What you’ll build
A supervisor agent that:- Wraps a Limerick Agent and a Haiku Agent as
agent_as_tooltools. - Sends the user’s prompt to both sub-agents.
- Presents both poems, clearly labeled.
- Picks a favorite and explains why.
Prerequisites
- A SeekrFlow API key, set as the
SEEKR_API_KEYenvironment variable - Python 3.8 or later
- The SeekrFlow SDK:
pip install seekrai
Build it
1
Set up the client
Create
agents_as_tools.py and start with the imports, configuration, and
client.This recipe uses
meta-llama/Llama-3.1-70B-Instruct. The supervisor has to call
both sub-agent tools and then reason over their output, so a capable instruct
model with reliable tool calling matters more here than in a single-tool agent.
Any instruct model that supports tool calling works, such as
meta-llama/Llama-3.3-70B-Instruct.2
Add helper functions
These helpers wait for asynchronous operations and make the script safe to run
more than once.
run_agent polls a run to completion, promote_and_wait polls
an agent until it is Active, and the get_or_create helpers reuse existing
resources instead of creating duplicates.3
Create the sub-agents
Create the two specialist agents. Each has narrow instructions that keep it
focused on a single job.
4
Promote the sub-agents
A sub-agent must be
Active before it can be wrapped as a tool, so promote both
now.5
Wrap each sub-agent as a tool
Create an
agent_as_tool tool for each sub-agent. The description is what the
supervisor sees when it decides which tool to call, and the config points at
the sub-agent by ID.6
Create the supervisor
Create the supervisor agent and attach both tools. Its instructions tell it to
call each tool and then compare the results.
7
Send a prompt
Send a prompt to the supervisor and print its reply. The supervisor calls both
sub-agents, then returns both poems with its verdict.
8
Run the script
Run the finished script:You should see a limerick and a haiku about the prompt, followed by the
supervisor’s pick.
Clean up resources (optional)
Promoted agents and their tools stay in your account until you remove them. When you are done, add this helper and call it to tear down everything the recipe created.Next steps
- Add more specialists. Wrap additional sub-agents (a sonnet writer, a translator) as tools and attach them to the supervisor.
- Route instead of fan out. Change the supervisor’s instructions so it picks the single best sub-agent for a prompt rather than calling all of them.
- Nest deeper. A sub-agent can have tools of its own, including other agents, so you can build multi-level workflows.