Back to catalog

Structured Outputs for Multi-Agent Systems

In this cookbook, we will explore how to use Structured Outputs to build multi-agent systems.

Structured Outputs for Multi-Agent Systems

In this cookbook, we will explore how to use Structured Outputs to build multi-agent systems.

Structured Outputs is a new capability that builds upon JSON mode and function calling to enforce a strict schema in a model output.

By using the new parameter strict: true, we are able to guarantee the response abides by a provided schema.

To demonstrate the power of this feature, we will use it to build a multi-agent system.

Why build a Multi-Agent System?

When using function calling, if the number of functions (or tools) increases, the performance may suffer.

To mitigate this, we can logically group the tools together and have specialized "agents" that are able to solve specific tasks or sub-tasks, which will increase the overall system performance.

Environment set up

Agents set up

The use case we will tackle is a data analysis task.

Let's first set up our 4-agents system:

  1. Triaging agent: Decides which agent(s) to call
  2. Data pre-processing Agent: Prepares data for analysis - for example by cleaning it up
  3. Data Analysis Agent: Performs analysis on the data
  4. Data Visualization Agent: Visualizes the output of the analysis to extract insights

We will start by defining the system prompts for each of these agents.

We will then define the tools for each agent.

Apart from the triaging agent, each agent will be equipped with tools specific to their role:

Data pre-processing agent

  1. Clean data
  2. Transform data
  3. Aggregate data

Data analysis agent

  1. Statistical analysis
  2. Correlation analysis
  3. Regression Analysis

Data visualization agent

  1. Create bar chart
  2. Create line chart
  3. Create pie chart

Tool execution

We need to write the code logic to:

  • handle passing the user query to the multi-agent system
  • handle the internal workings of the multi-agent system
  • execute the tool calls

For the sake of brevity, we will only define the logic for tools that are relevant to the user query.

From the user query, we can infer that the tools we would need to call are clean_data, start_analysis and use_line_chart.

We will first define the execution function which runs tool calls.

This maps a tool call to the corresponding function. It then appends the output of the function to the conversation history.

Next, we will create the tool handlers for each of the sub-agents.

These have a unique prompt and tool set passed to the model.

The output is then passed to an execution function which runs the tool calls.

We will also append the messages to the conversation history.

Finally, we create the overarching tool to handle processing the user query.

This function takes the user query, gets a response from the model and handles passing it to the other agents to execute. In addition to this, we will keep the state of the ongoing conversation.

Multi-agent system execution

Finally, we run the overarching handle_user_message function on the user query and view the output.

Conclusion

In this cookbook, we've explored how to leverage Structured Outputs to build more robust multi-agent systems.

Using this new feature allows to make sure that tool calls follow the specified schema and avoids having to handle edge cases or validate arguments on your side.

This can be applied to many more use cases, and we hope you can take inspiration from this to build your own use case!

Comments (0)

Sign In Sign in to leave a comment.

Spark Drops

Weekly picks: best new AI tools, agents & prompts

Venture Crew
Terms of Service

© 2026, Venture Crew