Skip to main content
This demo showcases how to use the IntentNode.

Run the Template

  1. Go to Assets/InworldRuntime/Scenes/Nodes and play the IntentNode scene. Intent00
  2. Once the graph is compiled, enter text.
The system finds the closest intents from the intent list and provides a similarity score (0 = lowest, 1 = highest). Intent

Understanding the Graph

IntentNodeCanvas contains an InworldGraphExecutor whose graph asset includes only a single IntentNode. The graph is very simple. It contains a single node, IntentNode, with no edges. IntentNode is both the StartNode and the EndNode. IntentNode02

IntentData

The IntentData is defined directly within the IntentNodeAsset. IntentNode02 The data structure works as follows: each topic includes several IntentSample entries to help the AI module recognize those categories. IntentNode02

InworldController

InworldController includes only one primitive module: TextEmbedder. IntentNode03 This is because IntentNode requires a TextEmbedder interface during CreateRuntime().
IntentNodeAsset.cs
public override bool CreateRuntime(InworldGraphAsset graphAsset)
{
    m_Graph = graphAsset;
    ComponentStore componentStore = new ComponentStore();
    componentStore.AddTextEmbedderInterface(NodeName, InworldController.TextEmbedder.Interface as TextEmbedderInterface);
    InworldCreationContext creationContext = new InworldCreationContext(componentStore);
    IntentNodeCreationConfig creationCfg = GetNodeCreationConfig() as IntentNodeCreationConfig;
    IntentNodeExecutionConfig executionCfg = GetNodeExecutionConfig() as IntentNodeExecutionConfig;
    Runtime = new IntentNode(NodeName, creationContext, creationCfg, executionCfg);
    return Runtime?.IsValid ?? false;
}

Workflow

  1. When the game starts, InworldController initializes its only module, TextEmbedderModule, which creates the TextEmbedderInterface.
  2. Next, InworldGraphExecutor initializes its graph asset by calling each component’s CreateRuntime(). In this case, only IntentNode.CreateRuntime() is called, using the created TextEmbedderInterface as input.
  3. After initialization, the graph calls Compile() and returns the executor handle.
  4. After compilation, the OnGraphCompiled event is invoked. In this demo, IntentNodeTemplate subscribes to it and enables the UI components. Users can then interact with the graph system.
IntentNodeTemplate.cs
protected override void OnGraphCompiled(InworldGraphAsset obj)
{
    foreach (InworldUIElement element in m_UIElements)
        element.Interactable = true;

}
  1. After the UI is initialized, pressing Enter or the SEND button sends the input text to the graph.
  2. Calling ExecuteGraphAsync() eventually produces a result and invokes OnGraphResult(), which IntentNodeTemplate subscribes to in order to receive the data.
IntentNodeTemplate.cs
protected override void OnGraphResult(InworldBaseData output)
{
    MatchedIntents matched = new MatchedIntents(output);
    if (matched.IsValid)
        DisplayMatchedIntents(matched);
    else
    {
        Debug.LogError(output);
    }
}