Skip to main content
When you disable streaming for an agent, it returns structured JSON responses instead of streamed text. You can optionally define a response schema so the JSON shape stays predictable and machine-readable every time, rather than open-ended prose.

What is Structured Output?

Structured Output means:
  • ✅ Agent returns complete response at once (not streamed)
  • ✅ Response is formatted as JSON (not raw text)
  • ✅ Can be used as a tool in other agents
  • ✅ Can be used in workflows
  • ✅ Can be called via API

Three Ways to Use Structured Output Agents

1. As a Tool in Other Agents

Use one agent as a tool that another agent can call: Scenario: Sales Agent needs help with lead scoring.
  1. Sales Agent receives lead info
  2. Calls “Lead Scorer” agent as a tool
  3. Gets structured score & analysis back
  4. Uses the score to prioritize the lead
Configuration:
  • Main Agent: Has “Lead Scorer” as a tool
  • Lead Scorer: Non-streaming agent returning score JSON
Example:

2. In Workflows

Use agent in workflows for multi-step automation: Scenario: Daily data processing workflow.
  1. Extract Data (API → Raw data)
  2. Validate Agent (Non-streaming) → { valid: true, ... }
  3. Transform Agent (Non-streaming) → { normalized: {...} }
  4. Load to Database (API call)
  5. Result: Clean data loaded
Use cases:
  • Data validation and cleaning
  • Content analysis and categorization
  • Document extraction
  • Quality assurance checks

3. Via API

Call agent directly through REST API:

Configuring Structured Output

In Agent Settings

  1. Go to agent configuration
  2. Find Streaming setting
  3. Disable streaming
  4. Optionally define response schema (JSON structure)

Response Schema (Optional)

Define the expected JSON structure:
Benefits:
  • ✅ Agent response always matches schema
  • ✅ Easier to parse in code
  • ✅ Better tool integration
  • ✅ API contracts clearly defined

Using as a Tool

Adding Agent as Tool to Another Agent

1

Go to Main Agent Settings

Open the agent that will call other agents
2

Open Tools Tab

Navigate to Tools configuration
3

Add New Tool

Select “Agent” as tool type
4

Select Agent

Choose which agent to use as tool
5

Configure Parameters

Define what input to pass and how to use output
6

Save

Agent now available as tool

Example: Agent Calling Agent

Scenario: Support Bot needs Lead Scoring Agent.
  • Support Bot Config:
    • Name: Support Bot
    • Tools:
      • Help Desk API (for creating tickets)
      • Email Tool (for sending emails)
      • Lead Scorer Agent (for evaluating customers)
    • Prompt: “If customer mentions a sales opportunity, use the Lead Scorer agent to evaluate whether they’re a good sales lead”
Flow example:
  1. User: “I’m interested in your enterprise plan”
  2. Support Bot thinks: “This is a sales opportunity”
  3. Support Bot calls Lead Scorer Agent
    • Input: “Customer details and interest”
    • Output: { lead_score: 9, category: "hot", rec: "route_to_sales" }
  4. Support Bot responds: “Great! I’m connecting you with our sales team”

Using in Workflows

Workflow Integration

Example workflow: Customer Feedback Analysis
  1. Receive Feedback
    • Input: Customer feedback text
    • Variable: customer_feedback
  2. Analyze with Agent
    • Agent: “Feedback Analyzer” (non-streaming)
    • Input: customer_feedback
    • Output: { sentiment, topics, action_needed }
  3. Route Based on Analysis
    • If action_needed == true — create ticket in Help Desk
    • If sentiment == "negative" — alert support team
    • Else — archive
  4. Notify Stakeholders
    • Send report with analysis
    • Done

Conditional Routing with Agent Output

Agent returns:
Workflow routes:
  • If priority == "high" AND needs_escalation — escalate to manager
  • Elif category == "billing" — route to billing team
  • Else — route to general support

API Usage

REST API Endpoint

Example: Node.js

Example: Python


Response Handling

Successful Response

Error Response


Best Practices

Define Clear Schema

Specify response format so consumers know what to expect

Handle Errors

Always check status and error fields in responses

Use Context

Pass user_id, session_id, or other context for better tracking

Monitor Usage

Track API calls and token usage in project monitoring

API Security

  • ✅ Use API keys with appropriate permissions
  • ✅ Rotate keys regularly
  • ✅ Don’t embed keys in frontend code
  • ✅ Use environment variables or secrets manager
  • ✅ Monitor for unusual API usage

Comparing with Chat Mode

🔗 Learn about Chat Mode: Conversational Chat

Troubleshooting

Check:
  • Input format correct
  • Agent has proper datasources/tools
  • Response schema doesn’t reject valid data
Solutions:
  • Review expected schema
  • Check agent prompt includes format instructions
  • Adjust schema to be less restrictive
Causes:
  • Agent processing complex request
  • Tool calls taking too long
  • External API delays
Solution: Increase timeout or optimize agent
Check:
  • Tool agent is non-streaming
  • Tool agent is in same project
  • Tool agent has required datasources
  • Input format matches tool expectations

Next Steps