> For the complete documentation index, see [llms.txt](https://docs.a4b.vn/xflow/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.a4b.vn/xflow/developer-guide/workflow-states-reference/aiagent-state.md).

# AIAgent State

The `AIAgentState` is used to define an AI Agent state within a serverless workflow. This state encapsulates the configuration for an AI agent, detailing its name, type, language model, messages, tools, outcomes, and other essential properties. This specification provides a comprehensive overview of the `AIAgentState` and its related objects.

### AIAgentState

The `AIAgentState` is a specialized state in a serverless workflow designed to integrate AI agents. The state defines the agent's configuration, including the AI model, system and user messages, tools for the agent to use, possible outcomes, and other properties.

<table data-header-hidden><thead><tr><th width="174"></th><th></th><th width="116"></th><th></th></tr></thead><tbody><tr><td><strong>Parameter</strong></td><td><strong>Description</strong></td><td><strong>Type</strong></td><td><strong>Required</strong></td></tr><tr><td>agentName</td><td>The name of the agent.</td><td>string</td><td>yes</td></tr><tr><td>aiModel</td><td>The name of AI Language Model. Default value is 'gpt-4o'.</td><td>string</td><td>no</td></tr><tr><td><a href="#llmconfig">llmConfig</a></td><td>The configuration for the language model.</td><td>object</td><td>no</td></tr><tr><td>systemMessage</td><td>The system message used for constructing LLM prompt. Defaults to "You are a helpful AI Assistant."</td><td>string</td><td>yes</td></tr><tr><td>userMessage</td><td>The user message.</td><td>string</td><td>yes</td></tr><tr><td>maxToolExecutions</td><td>The maximum number of tool executions. Default is 10.</td><td>integer</td><td>no</td></tr><tr><td><a href="#chatmemory">memory</a></td><td>The memory of the agent. If not specify, the workflow process instance scope is used.</td><td>object</td><td>no</td></tr><tr><td><a href="#agentdataoutput">output</a></td><td>JSON schema for agent data output. See AgentDataOutput.</td><td>object</td><td>yes</td></tr><tr><td><a href="#toolforai">tools</a></td><td>Define list of tools. Each tool is described by the ToolForAI schema.</td><td>array</td><td>no</td></tr><tr><td><a href="#onagentoutcome">agentOutcomes</a></td><td>Define list of agent outcomes. Each outcome is described by the <a href="#onagentoutcome">OnAgentOutcome</a> schema.</td><td>array</td><td>yes</td></tr><tr><td><a href="https://docs.a4b.vn/xflow/3.-core-concepts/workflow-data-handling#state-data-filters">dataFilter</a></td><td>Filter to apply to the state data.</td><td>string</td><td>no</td></tr><tr><td><a href="#multiagentcollaboration">multiAgentCollaboration</a></td><td>Multi-agent collaboration enables AI agent to delegate tasks to other collaborator agents. When enabled, the agent acts as a supervisor, coordinating responses from its collaborator agents.</td><td>object</td><td>no</td></tr></tbody></table>

### **LLMConfig**

The `LLMConfig` defines the configuration for the AI Language Model to be used by the AI Agent.

| Property                            | Type   | Description                                                    | Required |
| ----------------------------------- | ------ | -------------------------------------------------------------- | -------- |
| provider                            | string | The name of the provider.                                      | yes      |
| apiKey                              | string | The API key to access the AI Language Model.                   | yes      |
| [overrideParams](#llmparams)        | object | The parameters to override for the provider. (Optional)        | no       |
| [multiLLMsConfig](#multillmsconfig) | object | The strategy to use when multiple AI Language Models are used. | no       |

### **LLMParams**

The `LLMParams` defines the parameters for the LLM.

| Property           | Type    | Description                                                      | Required |
| ------------------ | ------- | ---------------------------------------------------------------- | -------- |
| model              | string  | The model to use for generating responses.                       | no       |
| temperature        | number  | The sampling temperature.                                        | no       |
| top\_p             | number  | The top-p sampling parameter.                                    | no       |
| n                  | integer | The number of completions to generate.                           | no       |
| logprobs           | integer | The number of log probabilities to return.                       | no       |
| echo               | boolean | Whether to echo back the prompt.                                 | no       |
| stop               | array   | Sequences where the model should stop generating further tokens. | no       |
| max\_tokens        | integer | The maximum number of tokens to generate.                        | no       |
| presence\_penalty  | number  | The presence penalty parameter.                                  | no       |
| frequency\_penalty | number  | The frequency penalty parameter.                                 | no       |
| logit\_bias        | object  | Logit bias configuration.                                        | no       |

### **MultiLLMsConfig**

The `MultiLLMsConfig` defines the configuration for multiple AI Language Models and the strategy to use when multiple AI Language Models are used.

| Property                      | Type   | Description                                                                        | Required |
| ----------------------------- | ------ | ---------------------------------------------------------------------------------- | -------- |
| [strategy](#multillmstrategy) | object | The strategy to use when multiple AI Language Models are used.                     | yes      |
| [targets](#llmproviderconfig) | array  | The list of AI Language Models to use. See [LLMProviderConfig](#llmproviderconfig) | yes      |

### **MultiLLMStrategy**

The `MultiLLMStrategy` defines the strategy to use when multiple AI Language Models are used.

| Property      | Type   | Description                                                                                | Required |
| ------------- | ------ | ------------------------------------------------------------------------------------------ | -------- |
| mode          | string | The mode for handling the request. It can be '`single`', '`fallback`', or '`loadbalance`'. | yes      |
| onStatusCodes | array  | The status codes to trigger the strategy.                                                  | yes      |

The mode for handling the request. It can be '`single`', '`fallback`', or '`loadbalance`'.

* `single`: This mode uses a single, specified Language Model API to handle requests.
* `fallback`: With numerous Language Model APIs available, each with unique strengths, seamlessly switching between them based on performance or availability is ideal. The fallback mode allows you to specify a prioritized list of providers/models. If the primary LLM fails, The AI Agent automatically switches to the next one, ensuring the execution robustness and reliability.
* `loadbalance`: Load Balance mode efficiently distributes network traffic across multiple LLMs. This ensures high availability and optimal performance of AI Agent, preventing any single LLM from becoming a performance bottleneck.

We can combine multiple handling strategies, such as fallback and load balance, to maximize both reliability and performance. This approach ensures efficient traffic distribution while providing fallback options in case of model failures.

#### Examples:

* `single`

```json
{
  "apiKey": "sk-123456",
  "overrideParams": {
    "model": "claude-1"
  }
}
```

* `fallback`

```json
{
  "strategy": {
      "mode": "fallback",
  },
  "targets": [
    {
      "apiKey": "sk-123456"
    },
    {
      "apiKey": "sk-789101",
      "overrideParams": {
          "model": "claude-1"
      }
    }
  ]
}
```

```json
{
  "strategy": {
    "mode": "fallback",
    "onStatusCodes": [ 429 ]
  },
  "targets": [
    {
      "apiKey": "sk-123456"
    },
    {
      "apiKey": "sk-789101"
    }
  ]
}
```

* `loadbalance`

```json
{
  "strategy": {
      "mode": "loadbalance",
  },
  "targets": [
    {
      "apiKey": "sk-123456",
      "weight": 0.75
    },
    {
      "apiKey": "sk-789101",
      "weight": 0.25
    }
  ]
}
```

* Combination:

```json
{
  "strategy": {
    "mode": "fallback",
    "onStatusCodes": [
      429
    ]
  },
  "targets": [
    {
      "apiKey": "sk-main-123456"
    },
    {
      "strategy": {
        "mode": "loadbalance"
      },
      "targets": [
        {
          "apiKey": "sk-sub-456789",
          "weight": 0.75
        },
        {
          "apiKey": "sk-sub-987654",
          "weight": 0.25
        }
      ]
    }
  ]
}
```

#### **LLMProviderConfig**

The `LLMProviderConfig` defines the configuration for an AI provider.

| Property                      | Type   | Description                                                                          | Required |
| ----------------------------- | ------ | ------------------------------------------------------------------------------------ | -------- |
| provider                      | string | The name of the LLM provider.                                                        | yes      |
| apiKey                        | string | The API key to use for the provider.                                                 | yes      |
| weight                        | number | The weight of the provider, used for load balancing. (Optional)                      | no       |
| [overrideParams](#llmparams)  | object | The parameters to override for the provider. See [LLMParams](#llmparams). (Optional) | no       |
| [strategy](#multillmstrategy) | object | The strategy to use for the target. (Optional)                                       | no       |
| [targets](#llmproviderconfig) | array  | The list of LLM provider configurations for the target. (Optional)                   | no       |

### ChatMemory

The `ChatMemory` object specifies the schema for the AI Agent chat memory configuration.

<table data-header-hidden><thead><tr><th></th><th width="246"></th><th width="152"></th><th></th></tr></thead><tbody><tr><td><strong>Field</strong></td><td><strong>Description</strong></td><td><strong>Type</strong></td><td><strong>Required</strong></td></tr><tr><td>memoryId</td><td>The memory id to store the agent history.</td><td>string</td><td>yes</td></tr><tr><td>memoryType</td><td>Type of memory (<code>message_window</code> or <code>token_window</code>). Default is <code>message_window.</code></td><td>string</td><td>no</td></tr><tr><td>maxMessages</td><td>The maximum number of messages to retain. If there isn't enough space for a new message, the oldest one is evicted. Used for <code>message_window</code> memory type.</td><td>integer</td><td>yes (if memoryType is <code>message_window</code>)</td></tr><tr><td>maxTokens</td><td>The maximum number of tokens to retain. Chat memory will retain as many of the most recent messages as can fit into maxTokens. Messages are indivisible. If an old message doesn't fit, it is evicted completely. Used for <code>token_window</code> memory type.</td><td>integer</td><td>yes (if memoryType is <code>token_window</code>)</td></tr></tbody></table>

### AgentDataOutput

The `AgentDataOutput` object specifies the schema for the data output produced by the AI agent.

<table data-header-hidden><thead><tr><th></th><th width="264"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Field</strong></td><td><strong>Description</strong></td><td><strong>Type</strong></td><td><strong>Required</strong></td></tr><tr><td>schema</td><td>URI of the JSON Schema used to describe the agent data output</td><td>string</td><td>yes</td></tr></tbody></table>

### OnAgentOutcome

The `OnAgentOutcome` object defines the actions to be performed based on the outcome of the AI agent. The actions are executed if the outcome matches the specified conditions.

<table data-header-hidden><thead><tr><th width="137"></th><th width="274"></th><th width="137"></th><th></th></tr></thead><tbody><tr><td><strong>Field</strong></td><td><strong>Description</strong></td><td><strong>Type</strong></td><td><strong>Required</strong></td></tr><tr><td>condition</td><td>Expression, if defined, must evaluate to true for this outcome to be matched. If false, the outcome is disregarded.</td><td>string</td><td>no</td></tr><tr><td>finish</td><td>If true, the agent will finish after this action is executed. If false, the agent will continue to process.</td><td>boolean</td><td>no</td></tr><tr><td><a href="https://docs.a4b.vn/xflow/3.-core-concepts/workflow-data-handling#event-data-filters">dataFilter</a></td><td>Event data filter described by the <a href="https://docs.a4b.vn/xflow/3.-core-concepts/workflow-data-handling#event-data-filters">EventDataFilter</a> schema.</td><td>object</td><td>no</td></tr><tr><td><a href="https://github.com/serverlessworkflow/specification/blob/0.9.x/specification.md#transition-definition">transition</a></td><td>The outgoing transition when the outcome is selected, if not defined the default transition will be used.</td><td>object</td><td>no</td></tr></tbody></table>

### ToolForAI

The `ToolForAI` object describes the tools available for use by the AI agent, including their parameters, output, and execution details.

<table data-header-hidden><thead><tr><th width="155"></th><th width="313"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Field</strong></td><td><strong>Description</strong></td><td><strong>Type</strong></td><td><strong>Required</strong></td></tr><tr><td>name</td><td>Tool name</td><td>string</td><td>yes</td></tr><tr><td>description</td><td>Tool description</td><td>string</td><td>yes</td></tr><tr><td>type</td><td>Tool type, either <code>standard</code> for a standard actions or <code>mcp</code> for a Model Context Protocol tools. Default is <code>standard</code>.</td><td>string</td><td>yes</td></tr><tr><td><a href="#toolparams">parameters</a></td><td>JSON schema for tool parameters described by <a href="#toolparams">ToolParams</a> schema. <strong>Required</strong> for <code>standard</code> tools, <strong>ignored</strong> for <code>mcp</code> tools.</td><td>object</td><td>no</td></tr><tr><td><a href="#tooloutput">output</a></td><td>JSON schema for tool output described by <a href="#tooloutput">ToolOutput</a> schema. <strong>Ignored</strong> for <code>mcp</code> tools.</td><td>object</td><td>no</td></tr><tr><td><a href="#toolexecution">execution</a></td><td>Tool execution definition described by ToolExecution schema. <strong>Ignored</strong> for <code>mcp</code> tools.</td><td>object</td><td>no</td></tr><tr><td>metadata</td><td>Metadata</td><td>object</td><td>no</td></tr><tr><td><a href="#mcpclient">mcpClient</a></td><td>MCP client configuration for Model Context Protocol tools. <strong>Required</strong> for <code>mcp</code> tools.</td><td>object</td><td>no</td></tr></tbody></table>

### ToolExecution

The `ToolExecution` object specifies how actions are to be performed by the tools used by the AI agent.

<table data-header-hidden><thead><tr><th width="149"></th><th width="298"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Field</strong></td><td><strong>Description</strong></td><td><strong>Type</strong></td><td><strong>Required</strong></td></tr><tr><td>actionMode</td><td>Specifies how actions are to be performed (in sequence or parallel). Default is sequential.</td><td>string</td><td>no</td></tr><tr><td>actions</td><td>Actions to be performed, each described by the Action schema.</td><td>array</td><td>yes</td></tr></tbody></table>

### ToolOutput

The `ToolOutput` object specifies the schema for the output produced by the tools used by the AI agent.

<table data-header-hidden><thead><tr><th></th><th width="284"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Field</strong></td><td><strong>Description</strong></td><td><strong>Type</strong></td><td><strong>Required</strong></td></tr><tr><td>schema</td><td>URI of the JSON Schema used to describe the tool output</td><td>string</td><td>yes</td></tr></tbody></table>

### ToolParams

The `ToolParams` object defines the parameters required by the tools used by the AI agent.

<table data-header-hidden><thead><tr><th></th><th width="285"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Field</strong></td><td><strong>Description</strong></td><td><strong>Type</strong></td><td><strong>Required</strong></td></tr><tr><td>schema</td><td>URI of the JSON Schema used to describe the parameters</td><td>string</td><td>yes</td></tr></tbody></table>

### McpClient

The `McpClient` object defines configuration for Model Context Protocol (MCP) tools.

<table data-header-hidden><thead><tr><th></th><th width="285"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Field</strong></td><td><strong>Description</strong></td><td><strong>Type</strong></td><td><strong>Required</strong></td></tr><tr><td>url</td><td>The URL of the MCP server</td><td>string</td><td>yes</td></tr><tr><td><a href="#mcpauth">auth</a></td><td>Authentication details for the MCP client. If not specified, no authentication is used.</td><td>object</td><td>no</td></tr><tr><td><a href="#mcptoolfilter">toolFilter</a></td><td>Filter for MCP tools that can be used to select specific tools based on their properties. If not specified, all tools are included.</td><td>object</td><td>no</td></tr></tbody></table>

### McpAuth

The `McpAuth` object defines authentication details for the MCP client. It can be either bearer token based or header based authentication.

<table data-header-hidden><thead><tr><th></th><th width="285"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Field</strong></td><td><strong>Description</strong></td><td><strong>Type</strong></td><td><strong>Required</strong></td></tr><tr><td>type</td><td>The type of authentication to use for the MCP client. <code>bearer</code> means to use a bearer token, <code>header</code> means to use custom headers for authentication. Default is <code>bearer</code>.</td><td>string</td><td>yes</td></tr><tr><td>bearerToken</td><td>The bearer token to use for authentication. This is <strong>required</strong> when the type is <code>bearer</code>.</td><td>string</td><td>no</td></tr><tr><td>headers</td><td>Key-value pairs of headers to include in the request for authentication. This is <strong>required</strong> when the type is <code>header</code>.</td><td>object</td><td>no</td></tr></tbody></table>

### McpToolFilter

The `McpToolFilter` object defines filter for MCP tools that can be used to select specific tools based on their properties.

<table data-header-hidden><thead><tr><th></th><th width="285"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Field</strong></td><td><strong>Description</strong></td><td><strong>Type</strong></td><td><strong>Required</strong></td></tr><tr><td>type</td><td>The type of filter to apply to the MCP tools. <code>all</code> means all tools are included, <code>include</code> means only specified tools are included, <code>exclude</code> means specified tools are excluded, and <code>expression</code> means a custom expression is used to filter tools. Default is <code>all</code>.</td><td>string</td><td>yes</td></tr><tr><td>includedTools</td><td>List of MCP tool names to include when the filter type is <code>include</code>.</td><td>array</td><td>no</td></tr><tr><td>excludedTools</td><td>List of MCP tool names to exclude when the filter type is <code>exclude</code>.</td><td>array</td><td>no</td></tr><tr><td>expression</td><td>A custom jq expression to filter MCP tools when the filter type is <code>expression</code>. The expression should evaluate to true for tools that should be included. The input to the expression is the tool object itself which have the following properties: <code>name</code>, <code>description</code></td><td>string</td><td>no</td></tr></tbody></table>

### MultiAgentCollaboration

The `MultiAgentCollaboration` object defines the configuration of agents collaboration, enables AI agent to delegate tasks to other collaborator agents. When enabled, the agent acts as a supervisor, coordinating responses from its collaborator agents.

<table data-header-hidden><thead><tr><th></th><th width="285"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Field</strong></td><td><strong>Description</strong></td><td><strong>Type</strong></td><td><strong>Required</strong></td></tr><tr><td>enabled</td><td>Turn on multi-agent collaboration to appoint this agent as a supervisor agent. A supervisor agent can designate one or more collaborator agents, delegate responses, and can also be used as an collaborator in another multi-agent collaboration.</td><td>boolean</td><td>no</td></tr><tr><td>collaborators</td><td>Define list of collaborator agents. See the <a href="#collaboratoragent">CollaboratorAgent</a>.</td><td>array</td><td>no</td></tr></tbody></table>

### CollaboratorAgent

The `CollaboratorAgent` object defines the configuration of a collaborator agent which is designated to assist the supervior agent in a multi-agent collaboration. It can be used to delegate tasks and provide specialized responses.

<table data-header-hidden><thead><tr><th width="202"></th><th width="285"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Field</strong></td><td><strong>Description</strong></td><td><strong>Type</strong></td><td><strong>Required</strong></td></tr><tr><td>name</td><td>The name of the collaborator agent.</td><td>string</td><td>yes</td></tr><tr><td>collaboratorInstruction</td><td>Describes the task that the collaborator agent performs within multi-agent collaboration. We recommend providing clear, specific scenarios. You can also define the style and tone. Refer to the agent using its collaborator name.</td><td>string</td><td>yes</td></tr><tr><td>agentRef</td><td>The reference to the agent state that this collaborator represents</td><td>string</td><td>yes</td></tr></tbody></table>

**Example:**

<table data-full-width="false"><thead><tr><th>YAML</th><th data-hidden>JSON</th></tr></thead><tbody><tr><td><pre class="language-yaml" data-line-numbers data-full-width="false"><code class="lang-yaml">states:
  - name: AgentSelector
    agentName: AgentSelector
    type: aiagent
    aiModel: llama3-70b-8192
    systemMessage: |-
      You are an assistant for selecting which tool is the most useful to use. \n
      Based on the tool's description, you have to return the name of the selected tool.
    userMessage: '${ "User: " + .request.question }'
    output: |-
      {
        "type": "object",
        "properties": {
            "selectedAgent": {
                "type": "string",
                "description": "The exact name of agent to be selected."
            }
        },
        "required": [
            "selectedAgent"
        ]
      }
    tools:
    - name: RAG_REACT
      description: |-
        RAG_REACT[input]: This tool is great for answering questions about searching products information, pricing, 
        description, give advise and others about querying data.
      parameters: |-
        {
          "type": "object",
          "properties": {
              "input": {
                  "type": "string",
                  "description": "The search query"
              }
          },
          "required": ["input"]
        }
      output: |-
        {
          "type": "object",
          "properties": {
              "answer": {
                  "type": "string",
                  "description": "The answer to the user question"
              },
              "images": {
                  "type": "array",
                  "description": "The list of images that related to the answer to be displayed to the user",
                  "items": {
                      "type": "string",
                      "format": "uri"
                  }
              }
          },
          "required": ["answer"]
        }
    - name: TRANSACTION_PROCESSING
      description: |-
        TRANSACTION_PROCESSING[request]: This tool is great for handle ordering, buying, booking products, payments, and others related to transactions request.
      parameters: |-
        {
          "type": "object",
          "properties": {
              "request": {
                  "type": "string",
                  "description": "The user request"
              }
          },
          "required": ["request"]
        }
      output: |-
        {
          "type": "object",
          "properties": {
              "answer": {
                  "type": "string",
                  "description": "The answer."
              }
          },
          "required": [
              "answer"
          ]
        }
    agentOutcomes:
    - condition: '${ $agentOutcome.returnValues.selectedAgent == "RAG_REACT" }'
      finish: true
      transition: RagAgent
    - condition: '${ $agentOutcome.returnValues.selectedAgent == "TRANSACTION_PROCESSING" }'
      finish: true
      transition: ProductRetriver
    - condition: '${ true }'
      finish: true
      transition: RagAgent
  - name: RagAgent
    agentName: RagAgent
    type: aiagent
    aiModel: gpt-4o
    systemMessage: |-
      You are an assistant for question-answering tasks. 
      Correct question to ensure the correctness of spelling and clarity of meaning in Vietnamese before answering. 
      Use the following pieces of retrieved context to answer the question. 
      If you don't know the answer, just say that you don't know. 

```
  Question: {question}
  Context: {context}
  Answer:
userMessage: '${ .request.question }'
output: |-
  {
      "type": "object",
      "properties": {
          "answer": {
              "type": "string",
              "description": "The answer to the user question"
          },
          "images": {
            "type": "array",
            "description": "The list of images that related to the answer to be displayed to the user",
            "items": {
              "type": "object",
              "properties": {
                "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "The URL of the image"
                }
              }
            }
          }
      },
      "required": ["answer"]
  }
tools:
- name: FIND_RELEVANT_DOCUMENTS
  description: |-
    FIND_RELEVANT_DOCUMENTS[question]: This tool is great for searching relevant documents, articles in the knowledge base related to the user question
  parameters: |-
    {
      "type": "object",
      "properties": {
          "input": {
              "type": "string",
              "description": "The search query"
          }
      },
      "required": ["input"]
    }
  output: |-
    {
        "type": "object",
        "properties": {
            "documents": {
                "type": "array",
                "items": {
                    "type": "string",
                    "format": "uri"
                }
            }
        },
        "required": ["documents"]
    }
  execution:
    actionMode: sequential
    actions:
    - name: FindRelevantDocuments
      functionRef:
        refName: FuncFindRelevantDocuments
        arguments:
          question: '${ .request.question }'
          actor: '${ .request.userContext }'
      actionDataFilter:
        results: '${ { "documents": .data } }'
        toStateData: ${ .request }
agentOutcomes:
- condition: '${ true }'
  finish: true
  transition: InformRagResult
```

</code></pre></td><td><pre class="language-json" data-line-numbers><code class="lang-json">{
"states": \[
{
"name": "AgentSelector",
"agentName": "AgentSelector",
"type": "aiagent",
"agentType": "agent",
"aiModel": "llama3-70b-8192",
"systemMessage": "You are an assistant for selecting which tool is the most useful to use. \n\nBased on the tool's description, you have to return the name of the selected tool.",
"userMessage": "${ "User: " + .request.question }",
"output": "{\n  "type": "object",\n  "properties": {\n      "selectedAgent": {\n          "type": "string",\n          "description": "The exact name of agent to be selected."\n      }\n  },\n  "required": \[\n      "selectedAgent"\n  ]\n}",
"tools": \[
{
"name": "RAG\_REACT",
"description": "RAG\_REACT\[input]: This tool is great for answering questions about searching products information, pricing, \ndescription, give advise and others about querying data.",
"parameters": "{\n  "type": "object",\n  "properties": {\n      "input": {\n          "type": "string",\n          "description": "The search query"\n      }\n  },\n  "required": \["input"]\n}",
"output": "{\n  "type": "object",\n  "properties": {\n      "answer": {\n          "type": "string",\n          "description": "The answer to the user question"\n      },\n      "images": {\n          "type": "array",\n          "description": "The list of images that related to the answer to be displayed to the user",\n          "items": {\n              "type": "string",\n              "format": "uri"\n          }\n      }\n  },\n  "required": \["answer"]\n}"
},
{
"name": "TRANSACTION\_PROCESSING",
"description": "TRANSACTION\_PROCESSING\[request]: This tool is great for handle ordering, buying, booking products, payments, and others related to transactions request.",
"parameters": "{\n  "type": "object",\n  "properties": {\n      "request": {\n          "type": "string",\n          "description": "The user request"\n      }\n  },\n  "required": \["request"]\n}",
"output": "{\n  "type": "object",\n  "properties": {\n      "answer": {\n          "type": "string",\n          "description": "The answer."\n      }\n  },\n  "required": \[\n      "answer"\n  ]\n}"
}
],
"agentOutcomes": \[
{
"condition": "${ $agentOutcome.returnValues.selectedAgent == "RAG\_REACT" }",
"finish": true,
"transition": "RagAgent"
},
{
"condition": "${ $agentOutcome.returnValues.selectedAgent == "TRANSACTION\_PROCESSING" }",
"finish": true,
"transition": "ProductRetriver"
},
{
"condition": "${ true }",
"finish": true,
"transition": "RagAgent"
}
]
},
{
"name": "RagAgent",
"agentName": "RagAgent",
"type": "aiagent",
"agentType": "agent",
"aiModel": "gpt-4o",
"systemMessage": "You are an assistant for question-answering tasks. \nCorrect question to ensure the correctness of spelling and clarity of meaning in Vietnamese before answering. \nUse the following pieces of retrieved context to answer the question. \nIf you don't know the answer, just say that you don't know. \n\nQuestion: {question}\nContext: {context}\nAnswer:",
"userMessage": "${ .request.question }",
"output": "{\n    "type": "object",\n    "properties": {\n        "answer": {\n            "type": "string",\n            "description": "The answer to the user question"\n        },\n        "images": {\n          "type": "array",\n          "description": "The list of images that related to the answer to be displayed to the user",\n          "items": {\n            "type": "object",\n            "properties": {\n              "url": {\n                  "type": "string",\n                  "format": "uri",\n                  "description": "The URL of the image"\n              }\n            }\n          }\n        }\n    },\n    "required": \["answer"]\n}",
"tools": \[
{
"name": "FIND\_RELEVANT\_DOCUMENTS",
"description": "FIND\_RELEVANT\_DOCUMENTS\[question]: This tool is great for searching relevant documents, articles in the knowledge base related to the user question",
"parameters": "{\n  "type": "object",\n  "properties": {\n      "input": {\n          "type": "string",\n          "description": "The search query"\n      }\n  },\n  "required": \["input"]\n}",
"output": "{\n    "type": "object",\n    "properties": {\n        "documents": {\n            "type": "array",\n            "items": {\n                "type": "string",\n                "format": "uri"\n            }\n        }\n    },\n    "required": \["documents"]\n}",
"execution": {
"actionMode": "sequential",
"actions": \[
{
"name": "FindRelevantDocuments",
"functionRef": {
"refName": "FuncFindRelevantDocuments",
"arguments": {
"question": "${ .request.question }",
"actor": "${ .request.userContext }"
}
},
"actionDataFilter": {
"results": "${ { "documents": .data } }",
"toStateData": "${ .request }"
}
}
]
}
}
],
"agentOutcomes": \[
{
"condition": "${ true }",
"finish": true,
"transition": "InformRagResult"
}
]
}
]
} </code></pre></td></tr></tbody></table>

***

This document provides a detailed view of the `AIAgentState` state and its related objects, including comprehensive schema definitions, required fields, and descriptions for each attribute within the `AIAgentState` and associated schemas. This specification ensures clarity and completeness for integrating AI agents within serverless workflows.
