output_typedecides howagent.run()formats the conversation it returns.- A function-calling schema in
tools_list_dictionarymakes the model answer with arguments that match your schema.
Output Types
Swarms supports multiple output formats through theoutput_type parameter. output_type controls how the conversation transcript (agent.short_memory) is formatted when agent.run() returns — it is not a schema parser. In particular:
"str-all-except-first"(default) — every message after the system prompt and the first input, contents joined into one string without role labels. In a plain run the first input is your task, so you get the agent’s answer"final"/"last"— just the content of the last message. This is a string for a text answer, and a list of tool-call dicts when the model answered with a function call"str"/"string"/"all"— the full conversation as one string, with a timestamp and role label on each message"list"— the conversation as a list of{"role", "content"}dicts"dict"/"dictionary"— the full conversation history as a Pythonlistof message dicts, including each message’stimestampandmessage_id(despite the name, this is a list, not a single dict)"json"— the full conversation history serialized as a JSON string (an array of message dicts, not a single schema-shaped object)"yaml"— the conversation history as a YAML string"dict-all-except-first"— every message after the system prompt and the first input, as a list of message dicts. This is the defaultoutput_typeof several multi-agent harnesses (HeavySwarm,HierarchicalSwarm,ConcurrentWorkflow,LLMCouncil,PlannerWorkerSwarm, and others)"list-final"— the content of the last message, wrapped in a single-item list"dict-final"— the content of the last message, as a(content, content)tuple
Function-Calling Schemas
The reliable way to get schema-shaped data is to give the agent a function schema intools_list_dictionary and no Python callable to run. The model answers with a function call whose arguments follow your schema, and the agent returns that call to you instead of executing anything.
With output_type="final", run() returns a list of tool-call dicts:
Basic JSON Schema
Define the shape with a Pydantic model and convert it withBaseTool().base_model_to_dict(), which returns an OpenAI tool schema:
The request is sent with
tool_choice="auto", so the model may still answer in plain text. Name the function in your task or system prompt, and check whether the result is a list before parsing it. Keep max_loops=1. No callable runs the function, so a later loop only sees a (no result recorded ...) placeholder for the call.Multiple Output Schemas
Give the agent several schemas and branch on the function the model chose:Hand-Written JSON Schemas
You can also pass an OpenAI tool schema as a plain dict:Tool Schema
Using tool_schema Parameter
tool_schema takes a single Pydantic model and writes its schema into the agent’s memory as guidance. It does not send a function to the model and does not parse the reply, so you get the model’s text back and parse it yourself:
Complex Output Structures
Nested Models
Nested models and enums become$defs references in the generated schema:
Lists and Arrays
Validation and Constraints
The schema tells the model what to produce, but nothing checks the reply for you. Validate the parsed arguments with your Pydantic model and handleValidationError.
Field Validation
Enums and Choices
Output Processing
JSON Output
Dictionary Output
Working with Responses
Function Calling Response
When you pass Python callables intools, the agent runs the tool calls itself and records their results, so the return value is the conversation formatted by output_type, not raw tool calls:
Best Practices
1. Use Descriptive Field Names
2. Add Field Descriptions
3. Use Appropriate Constraints
4. Provide Examples in Descriptions
5. Give Each Schema a Docstring
A Pydantic model’s docstring becomes the function description the LLM sees, and the class name becomes the function name. Say what the function records, and name the function in your task.Next Steps
Agent Tools
Add tools to extend agent capabilities
Creating Agents
Learn how to create agents
Reference
- Output type formatting:
swarms/utils/history_output_formatter.py; the accepted values are inswarms/utils/output_types.py - Pydantic to tool schema:
BaseTool.base_model_to_dictinswarms/tools/base_tool.py, built onswarms/tools/pydantic_to_json.py - Tool-call parsing:
ToolManager.parse_responseinswarms/agents/tool_manager.py tool_schemaandlist_base_modelshandling:ToolManager.handle_tool_schema_opsinswarms/agents/tool_manager.py