AI / Core OpenAI Codex Application Fundamentals Interview Questions
How do you implement multi-agent systems using the OpenAI Agents SDK?
Multi-agent systems decompose complex tasks across multiple specialised agents that collaborate via handoffs. Each agent focuses on what it does best, improving overall quality and maintainability compared to a monolithic agent trying to do everything.
from agents import Agent, Runner, handoff import asyncio # Define specialised agents: code_agent = Agent( name="CodeWriter", instructions="Write clean, well-documented Python code. Focus on correctness.", model="gpt-5.5", ) review_agent = Agent( name="CodeReviewer", instructions="Review code for bugs, security issues, and performance problems.", model="gpt-5.5", ) doc_agent = Agent( name="DocWriter", instructions="Write clear docstrings and README documentation.", model="gpt-5.4-mini", # cheaper model for docs ) # Orchestrator agent with handoffs: orchestrator = Agent( name="Orchestrator", instructions="""Manage the coding workflow: 1. Use CodeWriter to implement features 2. Use CodeReviewer to review and fix issues 3. Use DocWriter to document the final code """, handoffs=[ handoff(code_agent), handoff(review_agent), handoff(doc_agent), ], model="gpt-5.5", ) async def run_pipeline(task: str): result = await Runner.run( orchestrator, task, max_turns=20, # prevent infinite loops ) return result.final_output # Run: output = asyncio.run(run_pipeline( "Implement a thread-safe LRU cache class with comprehensive tests" )) print(output)
Handoff patterns: an agent can hand off to a more specialised sub-agent mid-task (unidirectional), or the orchestrator can send tasks to parallel workers and aggregate results. The SDK handles the state transfer between agents so each agent receives the full context it needs.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
