Skip to main content
The Swarms API supports two distinct capabilities for controlling agent output:
  • Structured Outputs — enforce a JSON schema on the LLM’s response using llm_args.response_format
  • Tools / Function Calling — provide tool definitions the LLM can invoke using tools_list_dictionary

Structured Outputs

Structured outputs guarantee that an agent’s response conforms to a JSON schema you define. This uses the model provider’s native response_format parameter (e.g., OpenAI’s structured outputs), passed through llm_args in the agent config.

How It Works

Add a response_format object inside llm_args in your agent configuration. The API passes this directly to the underlying LLM via LiteLLM.

Example: JSON Schema Mode

Extract structured data from unstructured text by defining the exact fields you want.

Expected Response

The agent’s outputs field contains the structured JSON in the content field:
The content field is a JSON string. Parse it in your application to get the structured object.

Structured Outputs in a Swarm

Use structured outputs with multiple agents in a ConcurrentWorkflow. Each agent can have its own response_format schema.

Expected Response

Each agent returns its own structured output in the output array:

Tools / Function Calling

Tools let the LLM invoke functions during execution. This is separate from structured outputs — tools define actions the model can take, while structured outputs control the format of the model’s response. Use tools_list_dictionary in the agent config to define available tools using the OpenAI function calling schema.

Defining Tools

Each tool follows the OpenAI function calling format:

Example: Agent with Tools

Expected Response

When the model calls a tool, the content field contains the tool call arguments:

Parsing Tool Call Responses

When an agent calls a tool, the content field is an array of tool call objects (not a plain string like structured outputs). Each object contains:
The arguments field is a JSON string, not a parsed object. You must parse it with json.loads() (Python) or JSON.parse() (JavaScript) before using the values.

Step-by-Step Parsing

Example Output

Detecting tool calls vs. text responses: When the agent uses tools, content is an array of objects. When the agent responds with plain text, content is a string. Check the type to handle both cases:

Multi-Agent Swarm with Tools

Combine multiple tool-enabled agents in a swarm. Each agent can have its own set of tools.

Expected Response

Parsing Swarm Tool Calls

Swarm responses differ from single-agent responses in two ways:
  1. The response key is output (not outputs)
  2. The content field is a string (serialized Python representation), not a native array
Use ast.literal_eval in Python to safely parse the content string:

FAQ

Structured outputs (llm_args.response_format) control the format of the model’s response — you define a JSON schema and the model’s output is guaranteed to match it.Tools (tools_list_dictionary) define actions the model can invoke — the model decides when to call a function and with what arguments.You can use both on the same agent if needed.
No, tools are optional for each agent. Simply omit the tools_list_dictionary field for agents that don’t require tools.
Structured outputs via response_format work with models that support OpenAI’s structured output format, including gpt-4.1, gpt-4.1-mini, and gpt-4o. The feature is passed through LiteLLM, so any LiteLLM-supported model with response_format support will work.
Yes. Set llm_args.response_format for the output format and tools_list_dictionary for available tools on the same agent.