python
from agents import Agent, Runner, function_tool
@function_tool
def search_docs(query: str) -> str:
"""Search internal documentation."""
# Replace with a real retrieval call.
return "Found relevant documentation..."
research_agent = Agent(
name="ResearchAgent",
instructions="Find relevant information using available tools.",
tools=[search_docs],
)
analysis_agent = Agent(
name="AnalysisAgent",
instructions="Analyze findings and provide structured insights.",
)
supervisor = Agent(
name="Supervisor",
instructions="Coordinate the workflow between agents.",
handoffs=[research_agent, analysis_agent],
)
result = Runner.run_sync(supervisor, "What are the best practices for RAG?")
print(result.final_output)Go further
Run it
From a clone of stackunseen/examples:
bash
git clone https://github.com/stackunseen/examples
cd examples
cd multi-agent-orchestration-python
pip install openai-agents
export OPENAI_API_KEY=...
python supervisor.pyHow it works
The supervisor never calls tools itself. It hands off to a research agent that can search, then to an analysis agent that turns raw findings into structured insight. Each agent has exactly one responsibility.
Running it
Install the agents SDK, set your model provider key in the environment and run the file. The example uses an in-memory tool so it works without any backend.
Taking it to production
Replace the stub tool with a real retrieval call, add tracing around each hand-off and wrap any write action in an approval step. The multi-agent design story covers each of these.