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
  • Overview
  • How Business Process Management Solutions Address Digital Transformation
  • The Rise of LLMs and AI Agents
  • Combining AI Agents with Business Workflows
  • xFlow's Strategy for Integrating AI Agents into Workflows
  • Conclusion
  1. Core Concepts

AI Agents in Enterprise Business Processes

Overview

In the rapidly evolving landscape of enterprise operations, digital transformation has become a pivotal focus for organizations aiming to stay competitive. Business Process Management (BPM) solutions play a critical role in this transformation, streamlining workflows, enhancing efficiency, and ensuring seamless integration of various business functions. However, the advent of large language models (LLMs) and AI Agents presents new opportunities to revolutionize how businesses approach process management. In this blog post, we will explore how AI Agents can be integrated into enterprise business processes to address digital transformation requirements.

How Business Process Management Solutions Address Digital Transformation

Business Process Management (BPM) solutions provide a structured approach to improving organizational workflows. They facilitate the automation of repetitive tasks, ensuring that processes are consistent and efficient. By digitizing and automating workflows, BPM solutions help organizations reduce errors, cut costs, and improve overall productivity. However, traditional BPM systems often struggle with tasks that require adaptability and human-like understanding—areas where AI can significantly contribute.

The Rise of LLMs and AI Agents

Large Language Models (LLMs) and AI Agents have emerged as powerful tools capable of understanding and generating human-like text, making them ideal for tasks that involve natural language processing. AI Agents, powered by these models, can interact with users, interpret their requests, and provide intelligent responses or actions. This capability opens up new possibilities for integrating AI into business workflows, enhancing both automation and user interaction.

Combining AI Agents with Business Workflows

The integration of AI Agents into business workflows allows for a mix of automated and human tasks, creating a more dynamic and responsive process. AI Agents can handle routine queries, provide decision support, and even execute complex tasks within workflows. When combined with user tasks, this hybrid approach ensures that both automated processes and human interventions work in harmony.

xFlow's Strategy for Integrating AI Agents into Workflows

xFlow, a robust business process management solution, leverages the Serverless Workflow specification to provide a flexible and scalable execution runtime for business processes. xFlow’s strategy involves integrating AI Agents and user tasks seamlessly into workflows, ensuring that both automated and manual tasks are effectively managed. Here’s how xFlow achieves this:

Workflow Engine with Serverless Workflow Specification

xFlow’s workflow engine adopts the Serverless Workflow specification, providing a standardized approach to defining and executing business processes. This specification ensures that workflows are scalable, resilient, and easy to maintain, making it ideal for integrating advanced features like AI Agents.

UserTask State

The UserTask State in xFlow is designed to integrate human interactions seamlessly into automated workflows. This state facilitates tasks that require manual intervention, such as approvals, reviews, and decision-making. It bridges automated processes with human input, ensuring that workflows remain flexible and responsive.

AI Agent Support with Serverless Workflow States

xFlow supports AI Agents through three specific serverless workflow states:

Example of a Serverless Workflow Combining AI Agent States and User Task State

This workflow is a sophisticated serverless process that efficiently manages user inquiries and product transactions through intelligent automation and strategic human interaction. By leveraging cutting-edge AI agents, this workflow ensures that users receive precise answers to their questions and seamless support for their transactions.

Below is a detailed explanation of its main points:

Workflow Structure

  1. Workflow Initialization:

    • Init State: This initial state performs no actions and transitions directly to the AgentSelector state.

  2. AI Agent Selection:

    • AgentSelector State: This state utilizes an AI model (GPT-4) to determine which tool (either RAG_PROCESSING for answering questions or TRANSACTION_PROCESSING for handling transactions) is most appropriate based on the user's question. The AI agent's decision dictates the workflow's path.

  3. Question Answering Path:

    • RagAgent State: If RAG_PROCESSING is selected, the workflow enters the RagAgent state where another AI model provides a detailed answer to the user's question. It may also search for relevant documents if needed.

    • InformRagResult State: The AI agent's response is relayed back to the user through the InformRagResult state.

  4. Transaction Processing Path:

    • ProductRetriver State: If TRANSACTION_PROCESSING is selected, the workflow proceeds to retrieve product details.

    • BuyProductTransactionUserProxy State: A user interaction state collects necessary information from the user to complete the transaction, such as product SKU, number of items, customer details, etc.

    • ConsolidateOrderInfo State: This state consolidates the collected order information.

    • InformOrderStatus State: The user is informed that their order is being processed.

    • CheckAndConfirmOrderUserTask State: A user task where a human user confirms the order.

    • CallBuyProductAPI: The final state where the actual product purchase transaction is executed.

  5. Fallback and Informative States:

    • InformWelcomeMessage State: A fallback state that thanks the user if the process cannot continue.

    • Finish State: The final state that signifies the end of the workflow.

Workflow Components

  • AI Agents: The workflow employs multiple AI agents (AgentSelector, RagAgent) to process user questions, select appropriate tools, and provide answers.

  • User Proxy Agents: States like InformRagResult, BuyProductTransactionUserProxy, InformOrderStatus act as intermediaries between the AI system and the user, ensuring that human interactions are effectively integrated.

  • Human Interaction: The CheckAndConfirmOrderUserTask state involves human users to verify and confirm the orders, ensuring critical decisions have human oversight.

id: DAIRYLAND_AGENT
name: DAIRYLAND_AGENT Workflow
version: '1.0'
dataInputSchema:
  schema: |-
    {
      "$schema": "http://json-schema.org/draft-04/schema#",
      "type": "object",
      "properties": {
        "request": {
          "type": "object",
          "properties": {
            "question": {
              "type": "string"
            }
          }
        }
      },
      "required": ["request"]
    }
  failOnValidationErrors: true
metadata: {}
timeouts:
  workflowExecTimeout:
    duration: P5D
  actionExecTimeout: PT15M
retries:
  - name: WorkflowRetries
    delay: PT3S
    maxAttempts: 10
start:
  stateName: Init
states:
  - name: Init
    type: operation
    actions: []
    transition: AgentSelector
  - name: AgentSelector
    agentName: AgentSelector
    type: aiagent
    aiModel: gpt-4o
    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_PROCESSING
      description: |-
        RAG_PROCESSING[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_PROCESSING" }'
      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: '${ ._ai_agent_state._contexts.authContext }'
          actionDataFilter:
            results: '${ { "documents": .data } }'
            toStateData: ${ .request }
    agentOutcomes:
    - condition: '${ true }'
      finish: true
      transition: InformRagResult

  - name: InformRagResult
    agentName: InformRagResult
    type: userproxyagent
    agentRole: relay
    userMessage: '${ .request.question }'
    relayMessage:
      text: ${ ._ai_agent_state.RagAgent.agentOutcome.finish.output.returnValues.answer }
      mediaExp: ${ ._ai_agent_state.RagAgent.agentOutcome.finish.output.returnValues.images }
    output: |-
      {
          "type": "object",
          "properties": {
              "answer": {
                  "type": "string"
              }
          },
          "required": ["answer"]
      }
    agentOutcomes:
    - condition: '${ true }'
      finish: true
      transition: Finish
  - name: ProductRetriver
    type: operation
    actions:
    - name: ProductRetriver
      functionRef:
        refName: FuncQueryProducts
      actionDataFilter:
        results: '${ { "products": .data } }'
        toStateData: ${ .request }
    transition: BuyProductTransactionUserProxy
  - name: BuyProductTransactionUserProxy
    agentName: BuyProductTransactionUserProxy
    type: userproxyagent
    agentRole: facilitator
    userMessage: '${ .request.question }'
    collectDataSchema: |-
      {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "properties": {
          "sku": {
            "type": "string",
            "description": "Unique sku code of the product, always be ask first if not available. This field can be identified by try to match the product name with the available products; if no match is found, filter the list to only include relevant products based on the user's request, and present these in a user-friendly format categorized by the product's category field, with each line containing the product name, category, price, and a short description; if no relevant products are found, present the entire list. Always use the name of the product when asking for the sku code."
          },
          "productName": {
            "type": "string",
            "description": "The name of selected product. This field always not be ask but will be filled automatically based on the selected product."
          },
          "numOfItems": {
            "type": "integer",
            "description": "Number of product items to buy",
            "default": 1
          },
          "fullName": {
            "type": "string",
            "description": "Customer full name"
          },
          "phoneNumber": {
            "type": "string",
            "description": "Customer phone number"
          },
          "address": {
            "type": "string",
            "description": "Customer address to deliver the product"
          }
        },
        "required": ["sku", "numOfItems", "fullName", "phoneNumber", "address"]
      }
    knownData: |-
      ${
        { 
          "fullName": .request.customer.fullName,
          "phoneNumber": .request.customer.phoneNumber,
          "userRequest": .request.question,
          "availableProducts": .request.products
        }
      }
    output: |-
      {
        "type": "object",
        "properties": {
          "sku": {
            "type": "string",
            "description": "Unique sku code of the product"
          },
          "productName": {
            "type": "string",
            "description": "Product name user want to buy"
          },
          "numOfItems": {
            "type": "integer",
            "description": "Number of product items to buy",
            "default": 1
          },
          "fullName": {
            "type": "string",
            "description": "Customer full name"
          },
          "phoneNumber": {
            "type": "string",
            "description": "Customer phone number"
          },
          "address": {
            "type": "string",
            "description": "Customer address to deliver the product"
          }
        },
        "required": ["sku", "numOfItems", "fullName", "phoneNumber", "address"]
      }
    agentOutcomes:
      - condition: '${ $agentOutcome.stopReason == "COMPLETE" }'
        finish: true
        transition: ConsolidateOrderInfo
      - condition: '${ $agentOutcome.stopReason == "FAIL" }'
        finish: true
        transition: InformWelcomeMessage
      - condition: '${ true }'
        finish: true
        transition: InformWelcomeMessage
    transition: Finish
  - name: ConsolidateOrderInfo
    type: operation
    actions:
    - name: ConsolidateOrderInfo
      functionRef:
        refName: ConsolidateOrderInfo
        arguments:
          order: '${ ._ai_agent_state.BuyProductTransactionUserProxy.collectedData }'
      actionDataFilter:
        results: '${ { "order": .jqResult } }'
        toStateData: ${ .request }
    transition: InformOrderStatus
  - name: InformOrderStatus
    agentName: InformOrderStatusAgent
    type: userproxyagent
    agentRole: relay
    userMessage: '${ .request.question }'
    relayMessage:
      text: |-
        Thông tin mua hàng đã được chuyển tới bộ phận xử lý đơn hàng của Dairy Land. Chúng tôi sẽ liên hệ bạn trong thời gian sớm nhất.
    output: |-
      {
          "type": "object",
          "properties": {
              "answer": {
                  "type": "string"
              }
          },
          "required": ["answer"]
      }
    agentOutcomes:
    - condition: '${ true }'
      finish: true
      transition: CheckAndConfirmOrderUserTask
  - name: CheckAndConfirmOrderUserTask
    taskKey: taskCheckAndConfirmOrder
    type: usertask
    formKey: 'LCD#6661422c2edc626d083512d4'
    assignee: mrbean@dairyland.vn
    taskOutcomes:
      - code: Complete
        name: Confirm Order
        outcomeDecision: COMPLETED
        transition: CallBuyProductAPI
    taskListeners:
      - taskEvent: completed
        actionMode: sequential
        actions:
          - functionRef:
              refName: MergeOrderData
              arguments:
                order: '${ $userTask.data.editedRequest.order }'
            actionDataFilter:
              results: '${ .jqResult }'
              toStateData: '${ .request.order }'
    transition: CallBuyProductAPI
  - name: "CallBuyProductAPI"
    type: "operation"
    actions:
      - functionRef:
          refName: "buyProduct"
          arguments:
            sku: "${ .request.order.sku }"
            numOfItems: "${ .request.order.numOfItems }"
            fullName: "${ .request.order.fullName }"
            phoneNumber: "${ .request.order.phoneNumber }"
            address: "${ .request.order.address }"
        actionDataFilter:
          useResults: false
    end: true
  - name: InformWelcomeMessage
    agentName: InformWelcomeMessagesAgent
    type: userproxyagent
    agentRole: relay
    userMessage: '${ .request.question }'
    relayMessage:
      text: |-
        Chân thành cảm ơn vì sự quan tâm của bạn đến dịch vụ của chúng tôi. Hy vọng sẽ được phục vụ bạn trong tương lai.
    output: |-
      {
          "type": "object",
          "properties": {
              "answer": {
                  "type": "string"
              }
          },
          "required": ["answer"]
      }
    agentOutcomes:
    - condition: '${ true }'
      finish: true
      transition: Finish
  - name: Finish
    type: operation
    actions: []
    end: true
functions:
  - name: ConsolidateOrderInfo
    type: custom
    operation: JqQueryExecute
    metadata:
      jq: '${ .order }'
  - name: MergeOrderData
    type: custom
    operation: JqQueryExecute
    metadata:
      jq: '${ .editedRequest.order }'
  - name: FuncQueryProducts
    type: custom
    operation: ExecuteQueryAction
    metadata:
      libraryQueryName: query.dairy_land.products
      libraryQueryRecordId: latest
      params: '[]'
  - name: FuncFindRelevantDocuments
    type: custom
    operation: ExecuteQueryAction
    metadata:
      libraryQueryName: query.dairy_land.find_relevant_documents
      libraryQueryRecordId: latest
      params: '["question", "actor"]'
  - name: "buyProduct"
    type: "rest"
    operation: >
      restDefinition#
      {
        "servers": [
          {
            "url": "https://665876fb5c361705264890f5.mockapi.io/api/v1"
          }
        ],
        "paths": {
          "/dairy_land/buy": {
            "post": {
              "description": "Buy an Dairy Land product",
              "requestBody": {
                "required": true,
                "content": {
                  "application/json": {
                    "schema": {
                      "type": "object",
                      "properties": {
                          "sku": {
                              "type": "string",
                              "description": "The SKU of the product"
                          },
                          "numOfItems": {
                              "type": "integer",
                              "description": "The number of items to buy"
                          },
                          "fullName": {
                              "type": "string",
                              "description": "The full name of the buyer"
                          },
                          "phoneNumber": {
                              "type": "string",
                              "description": "The phone number of the buyer"
                          },
                          "address": {
                              "type": "string",
                              "description": "The address of the buyer"
                          }
                      },
                      "required": [
                          "sku",
                          "numOfItems",
                          "fullName",
                          "phoneNumber",
                          "address"
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
events:
  - name: NewApplicationEvent
    type: com.a4b.xflow.engine.StateData
    source: xflowengine
  - name: UserTaskCreated
    type: com.a4b.xptask.event.post.user_task.UserTaskCreatedEvent
  - name: UserTaskCompleted
    type: com.a4b.xptask.event.post.user_task.UserTaskCompletedEvent

Conclusion

Integrating AI Agents into enterprise business processes offers a powerful solution for digital transformation. By combining AI capabilities with traditional BPM systems, organizations can achieve greater efficiency, flexibility, and responsiveness. xFlow’s strategy of incorporating AI Agent States and User Task States within the Serverless Workflow framework exemplifies how advanced technologies can be harmonized to meet the evolving needs of modern enterprises. Embracing such innovations will be key to staying competitive in the digital age.

PreviousAdvanced User FormNextComparisons

Last updated 11 months ago

: The AI Agent State 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.

: The AI Agent Proxy State is designed to facilitate the integration of AI agents developed using any framework or programming language into xFlow workflows. This state acts as an intermediary, allowing for seamless communication and execution of AI agents regardless of their underlying technology stack.

: The User Proxy Agent State is designed to facilitate interactions between the workflow and users. This state acts as a mediator, ensuring that user inputs are correctly captured and integrated into the workflow, and that responses from the workflow are appropriately relayed to the user.

AIAgent State
AIAgentProxy State
UserProxyAgent State
DAIRYLAND_AGENT Workflow