> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inworld.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Intent Node Demo

This demo showcases how to use the `IntentNode`.

## Run the Template

1. Go to `Assets/InworldRuntime/Scenes/Nodes` and play the `IntentNode` scene.
   <img src="https://mintcdn.com/inworldai/09jBaDxLDhFWSIuG/img/unity/framework/Intent00.png?fit=max&auto=format&n=09jBaDxLDhFWSIuG&q=85&s=c71428e52b09aefe96f40505328f1dfe" alt="Intent00" width="747" height="663" data-path="img/unity/framework/Intent00.png" />
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).

<img src="https://mintcdn.com/inworldai/09jBaDxLDhFWSIuG/img/unity/framework/Intent.gif?s=53da8cc9abca2aa743ee03df6ea7b7a3" alt="Intent" width="1920" height="1080" data-path="img/unity/framework/Intent.gif" />

## 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`.

<img src="https://mintcdn.com/inworldai/09jBaDxLDhFWSIuG/img/unity/framework/IntentNode02.png?fit=max&auto=format&n=09jBaDxLDhFWSIuG&q=85&s=6124bf62a51a79140ae98339c7e6bf88" alt="IntentNode02" width="1017" height="792" data-path="img/unity/framework/IntentNode02.png" />

### IntentData

The `IntentData` is defined directly within the `IntentNodeAsset`.

<img src="https://mintcdn.com/inworldai/09jBaDxLDhFWSIuG/img/unity/framework/IntentNode04.png?fit=max&auto=format&n=09jBaDxLDhFWSIuG&q=85&s=9fa20cc585ed9e503d74427f0cd98a09" alt="IntentNode02" width="1008" height="723" data-path="img/unity/framework/IntentNode04.png" />

The data structure works as follows: each topic includes several `IntentSample` entries to help the AI module recognize those categories.

<img src="https://mintcdn.com/inworldai/09jBaDxLDhFWSIuG/img/unity/framework/IntentNode05.png?fit=max&auto=format&n=09jBaDxLDhFWSIuG&q=85&s=b99a7f7bd500c778a3d19d36e9ce65b6" alt="IntentNode02" width="1014" height="942" data-path="img/unity/framework/IntentNode05.png" />

### InworldController

`InworldController` includes only one primitive module: `TextEmbedder`.

<img src="https://mintcdn.com/inworldai/09jBaDxLDhFWSIuG/img/unity/framework/IntentNode03.png?fit=max&auto=format&n=09jBaDxLDhFWSIuG&q=85&s=ffce6cd8d2ba97cb370c4a90617d5b06" alt="IntentNode03" width="1365" height="560" data-path="img/unity/framework/IntentNode03.png" />

This is because `IntentNode` requires a `TextEmbedder` interface during `CreateRuntime()`.

```c# IntentNodeAsset.cs theme={"system"}
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.

```c# IntentNodeTemplate.cs theme={"system"}
protected override void OnGraphCompiled(InworldGraphAsset obj)
{
    foreach (InworldUIElement element in m_UIElements)
        element.Interactable = true;

}
```

5. After the UI is initialized, pressing `Enter` or the `SEND` button sends the input text to the graph.

6. Calling `ExecuteGraphAsync()` eventually produces a result and invokes `OnGraphResult()`, which `IntentNodeTemplate` subscribes to in order to receive the data.

```c# IntentNodeTemplate.cs theme={"system"}
protected override void OnGraphResult(InworldBaseData output)
{
    MatchedIntents matched = new MatchedIntents(output);
    if (matched.IsValid)
        DisplayMatchedIntents(matched);
    else
    {
        Debug.LogError(output);
    }
}
```
