xFlow
  • Overview
    • Introduction
    • Core Features
    • Architecture
      • High Level Architecture
      • Tech Stack
      • Deployment Flexibility
      • Performance and Scalability
      • Security Compliance
  • Getting Started
    • Installation
    • Quick Start
    • Configuration
  • Core Concepts
    • Serverless Workflow Specification
    • Workflow data handling
    • Workflow Expressions
    • Error handling
    • Input and Output schema definition
    • User Task
    • User Forms
      • Lowcode Form
      • Advanced User Form
    • AI Agents in Enterprise Business Processes
    • Comparisons
      • BPMN2
  • Developer Guide
    • Architecture
    • API Reference
    • Workflow States Reference
      • Event State
      • Operation State
      • Switch State
      • Parallel State
      • Inject State
      • ForEach State
      • Callback State
      • UserTask State
      • AIAgent State
      • AIAgentProxy State
      • UserProxyAgent State
      • AI Outbound Agent State
    • Workflow Functions
      • REST
      • GraphQL
      • Custom
        • Built-in Functions
        • Lowcoder Query Function
      • Function Auth
    • Workflow Secrets
    • Integrations
    • Workflow Modeler
    • Frontend Development
      • Forms
        • Lowcode Form
        • Advanced User Form
    • Serverless Workflow Development
      • Operation State
      • Switch State
      • Parallel State
      • ForEach State
      • Callback State
      • User Task State
    • AI Agent Development
      • AI Agent
        • Predefined LLM
        • LLM Configuration
        • Multi LLM Configuration
        • Chat Memory
        • Tools
        • Data Output
        • Agent Outcomes
      • AI Agent Proxy
        • AI Agents Integration
      • User Proxy Agent
      • xChatBot Integration
  • Examples
    • Basic Examples
    • Advanced Examples
      • Loan Approval Workflow
      • QMS AP Workflow
  • Administration
    • Monitoring and Logging
    • Security
    • Performance Tuning
  • Extensions and Customizations
    • Plugins and Add-ons
  • Troubleshooting
    • Common Issues
    • FAQs
  • Release Notes
    • Version History
    • Upcoming Features
  • Support
    • Contact Information
    • Community
Powered by GitBook
On this page
  • Introduction
  • Key Concepts
  • Detailed Explanation of AI Agent State Configuration
  • Conclusion
  1. Developer Guide
  2. AI Agent Development

AI Agent

Introduction

The AI Agent State in xFlow is a powerful component designed to integrate AI-driven decision-making and automation within business workflows. Leveraging large language models (LLMs), this state enables the creation of intelligent agents that can understand, process, and respond to complex queries, thereby enhancing the efficiency and effectiveness of business processes.

This documentation explains the key concepts and configurations of the AI Agent State.

Key Concepts

System Message

The systemMessage is a crucial configuration that sets the context for the AI agent. It acts as a guideline for the AI, instructing it on how to behave and what role to assume during the interaction. This message is typically used to define the AI agent's identity, tone, and the type of assistance it is expected to provide.

  • Example: "You are a helpful assistant specialized in customer support queries. Provide concise and accurate answers based on the given data."

User Message

The userMessage represents the input from the user that the AI agent needs to process. It captures the user's query or command, which the AI will analyze to generate an appropriate response. This message is dynamically constructed based on the user's interaction with the system.

  • Example: '${ "User: " + .request.question }'

Max Tool Executions

The maxToolExecutions parameter defines the maximum number of tools the AI agent can invoke during its operation. This is important to limit the scope of actions an AI can take, preventing excessive resource usage and ensuring focused execution.

  • Example: 5 (limits the AI agent to execute up to 5 different tools during its task).

Memory

The memory concept allows the AI agent to retain information across different interactions. This is essential for maintaining context, making the AI's responses more coherent and relevant over multiple exchanges. Memory ensures that the agent can recall past interactions and use this information to enhance future responses.

  • Example:

    memory: 
      memoryId: "session123"
      memoryType: "message_window"
      maxMessages: 10

Output

The output configuration defines the structure of the data the AI agent will return after processing a user query. It ensures that the AI's responses are formatted correctly and contain all necessary information required by the subsequent workflow steps.

  • Example:

    {
        "type": "object",
        "properties": {
            "answer": {
                "type": "string",
                "description": "The answer to the user question"
            },
            "images": {
                "type": "array",
                "description": "List of related images",
                "items": {
                    "type": "string",
                    "format": "uri"
                }
            }
        },
        "required": ["answer"]
    }

Tools

Tools are external functions or services that the AI agent can invoke to perform specific tasks. These tools extend the capabilities of the AI, allowing it to fetch data, perform calculations, or interact with other systems to provide comprehensive responses.

  • Example:

    - name: FIND_RELEVANT_DOCUMENTS
      description: "This tool searches for documents related to the user's query."
      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"]
        }

Agent Outcomes

AgentOutcomes define the possible results of the AI agent's operations. These outcomes are based on conditions evaluated after the AI processes a user query. Depending on the outcome, the workflow can transition to different states, ensuring flexible and adaptive process flows.

  • Example:

    - condition: '${ $agentOutcome.returnValues.selectedAgent == "RAG_REACT" }'
      transition: RagAgentProxy
    - condition: '${ $agentOutcome.returnValues.selectedAgent == "TRANSACTION_PROCESSING" }'
      transition: ProductRetriver

LLM Config

The llmConfig parameter specifies the configuration settings for the large language model that powers the AI agent. This includes details like the model type, version, and any specific tuning parameters that optimize the model's performance for the given task.

  • Example:

    llmConfig: 
      provider: "openai"
      apiKey: "your-api-key"
      overrideParams: 
        modelType: "gpt-4"
        temperature: 0.7
        maxTokens: 1500

Detailed Explanation of AI Agent State Configuration

State Definition

The AI Agent State is defined within a workflow using specific properties. These properties configure how the AI agent behaves, what messages it processes, the tools it can use, and the outcomes it generates.

Example Definition

- name: AgentSelector
  type: aiagent
  agentName: AgentSelector
  aiModel: gpt-4
  systemMessage: "You are an assistant for selecting which tool is the most useful to use. 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"
      ]
    }
  maxToolExecutions: 5
  memory: 
    memoryId: "session123"
    memoryType: "message_window"
    maxMessages: 10
  tools:
    - name: FIND_RELEVANT_DOCUMENTS
      description: "This tool searches for documents related to the user's query."
      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"]
        }
  agentOutcomes:
    - condition: '${ $agentOutcome.returnValues.selectedAgent == "RAG_REACT" }'
      transition: RagAgentProxy
    - condition: '${ $agentOutcome.returnValues.selectedAgent == "TRANSACTION_PROCESSING" }'
      transition: ProductRetriver
  llmConfig: 
    provider: "OpenAI"
    apiKey: "your-api-key"
    overrideParams: 
      modelType: "gpt-4"
      temperature: 0.7
      maxTokens: 1500
    multiLLMsConfig: 
      strategy: "fallback"
      models: 
        - provider: "OpenAI"
          apiKey: "your-openai-api-key"
        - provider: "Anthropic"
          apiKey: "your-anthropic-api-key"

Workflow Integration

The AI Agent State is integrated into the overall workflow to handle specific tasks that require intelligent processing. The state interacts with other states, such as user tasks and operational states, to ensure a seamless flow of operations.

Example Workflow Integration

states:
  - name: Init
    type: operation
    actions:
      - name: StartWorkflow
        functionRef:
          refName: InitFunction
    transition: AgentSelector
  - name: AgentSelector
    type: aiagent
    ... # Configuration as shown in the previous section
  - name: RagAgentProxy
    type: aiagentproxy
    ... # Configuration for proxy state
  - name: ProductRetriver
    type: operation
    actions:
      - name: RetrieveProductInfo
        functionRef:
          refName: RetrieveProduct


    transition: CompleteRequest
  - name: CompleteRequest
    type: end

Conclusion

The AI Agent State in xFlow offers a robust framework for integrating AI capabilities into business workflows. By configuring system messages, user messages, memory, tools, and agent outcomes, developers can create intelligent agents that enhance process automation, decision-making, and user interaction. Understanding these key concepts allows for the effective deployment of AI-driven solutions, driving digital transformation and operational efficiency.

PreviousAI Agent DevelopmentNextPredefined LLM

Last updated 11 months ago

For more detailed information and advanced configurations, refer to the

AI Agent State spec