This is an interactive notebook. You can run it locally or use the following links:
strict: true, you can guarantee the response abides by a provided schema.
Structured outputs in a multi-agent system produce consistent, predictably processed data between agents. They also support explicit refusals and remove the need for retries or response validation.
Install the dependencies
First, install the libraries the tutorial depends on. This tutorial uses the following libraries:- OpenAI to create the multi-agent system.
- Weave to track the LLM workflow and evaluate prompting strategies.
WANDB_API_KEY in your environment so you can log in with wandb.login(). Provide this to Colab as a secret.
Set the W&B project to log into in name_of_wandb_project.
name_of_wandb_project may also be in the format of [YOUR-TEAM]/[YOUR-PROJECT] to specify a team to log the traces into.weave.init().
Because this tutorial uses the OpenAI API, you also need an OpenAI API key. Sign up on the OpenAI platform to get your own API key. Provide this to Colab as a secret too.
Set up the agents
With Weave initialized, define the agents that make up the system. The use case for this tutorial is a data analysis task. First, set up the four-agent system:- Triaging agent: Decides which agents to call.
- Data pre-processing agent: Prepares data for analysis, for example by cleaning it up.
- Data analysis agent: Performs analysis on the data.
- Data visualization agent: Visualizes the output of the analysis to extract insights.
Enable multi-agent tracking with Weave
With the agents and their tools defined, the next step is to wire them together and enable Weave tracing. 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.
clean_data, start_analysis, and use_line_chart.
Begin by defining the execution function responsible for running tool calls.
By decorating Python functions with @weave.op(), you can log and debug language model inputs, outputs, and traces.
A multi-agent system involves many functions, but it’s sufficient to add @weave.op() on top of each one.
Execute the multi-agent system and visualize in Weave
With every agent, tool, and handler in place, the system is ready to run. Finally, execute the primaryhandle_user_message function using the user’s input and observe the results.

analysis_agent appear in a structured output format. OpenAI’s structured outputs help agents collaborate, but as the system grows more complex, the format of these interactions becomes harder to follow. Weave lets you inspect these intermediate processes and their inputs and outputs in detail.
