# Data Output

A crucial aspect of this integration is the Agent Data Output, which defines how the data generated by the AI agent is structured and utilized within the workflow. This documentation explains the purpose and details of the data output schema for the AI agent.

### Agent Data Output Properties

The Agent Data Output schema is essential for defining the structure of the data that the AI agent produces. This schema ensures that the output is well-structured, consistent, and can be easily consumed by other parts of the workflow or external systems. Below are the key properties of the Agent Data Output schema, along with examples for each.

#### Schema

* **Name**: `schema`
* **Type**: `string`
* **Description**: This property specifies the URI or the definition of the JSON Schema used to describe the agent data output. The JSON Schema provides a blueprint for the structure and format of the data, ensuring that the output adheres to a predefined format.
* **Example**:

  ```yaml
  schema: 
    type: "object"
    properties: 
      response: 
        type: "string"
        description: "The AI's response to the user question"
    required: ["response"]
  ```

### Purpose of Data Output Schema

The data output schema serves several important purposes in the context of AI agents within xFlow:

1. **Standardization**: By defining a clear schema, the output data from the AI agent is standardized. This ensures that all data produced follows a consistent format, making it easier to process and interpret.
2. **Validation**: The schema provides a means to validate the output data. By adhering to the schema, the workflow engine can ensure that the data produced by the AI agent is correct and complete, reducing the likelihood of errors.
3. **Interoperability**: A well-defined schema facilitates interoperability between different components of the workflow. Other parts of the system, such as subsequent workflow states or external applications, can easily consume the output data if they know its structure in advance.
4. **Documentation**: The schema acts as documentation for the output data. Developers and system integrators can refer to the schema to understand what data is produced by the AI agent and how it can be used.

### Usage Example

Here is an example of how to configure the Agent Data Output in an AI Agent State within a xFlow workflow:

```yaml
- name: ExampleAIState
  type: aiagent
  agentName: ExampleAgent
  aiModel: gpt-4o
  systemMessage: "You are an assistant designed to provide accurate answers."
  userMessage: '${ "User: " + .request.question }'
  output: 
    schema: 
      type: "object"
      properties: 
        response: 
          type: "string"
          description: "The AI's response to the user question"
      required: ["response"]
  maxToolExecutions: 5
  memory: 
    memoryId: "session123"
    memoryType: "message_window"
    maxMessages: 10
  tools:
    - name: SEARCH_DOCUMENTS
      description: "Search for relevant documents based on the user's query."
      parameters: 
        schema: 
          type: "object"
          properties: 
            query: 
              type: "string"
              description: "The search query"
          required: ["query"]
      output: 
        schema: 
          type: "object"
          properties: 
            documents: 
              type: "array"
              items: 
                type: "string"
                format: "uri"
          required: ["documents"]
      execution:
        actionMode: "sequential"
        actions:
          - name: "FetchDocuments"
            functionRef:
              refName: "FetchDocumentsFunction"
              arguments:
                query: "${ .request.query }"
  agentOutcomes:
    - condition: '${ $agentOutcome.returnValues.response != null }'
      transition: SuccessState
    - condition: '${ $agentOutcome.returnValues.response == null }'
      transition: ErrorState
```

For more detailed information and advanced configurations, refer to the [AI Agent State spec](/xflow/developer-guide/workflow-states-reference/aiagent-state.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.a4b.vn/xflow/developer-guide/ai-agent-development/ai-agent/data-output.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
