Orchestration patterns are standardized approaches for organizing and coordinating AI agents to work together effectively on complex tasks. These patterns provide structured ways to design agent interactions, information flows, and responsibilities.The pattern implementations use AG2’s group chat orchestration, read more about it here.Each pattern includes:
Description of the structure and information flow
Visualization example of agent interactions
Code example showing how to implement the pattern with AG2’s swarm orchestration
A dynamic workflow where tasks are intelligently distributed to specialized agents based on content analysis rather than predetermined paths.Business Use Cases:
Customer support systems that route queries to appropriate department specialists
Multi-domain virtual assistants that connect users with specialized services
Knowledge management systems that direct questions to domain experts
Research platforms that route complex questions to knowledgeable AI agents
A resource-efficient approach where simpler, less resource-intensive agents handle tasks first, with more capable (but potentially more expensive) agents only engaged when necessary.Business Use Cases:
Tiered customer support (chatbot → human agent → specialist)
Computational tasks with varying complexity requirements
Content moderation (automated → human review)
Technical problem-solving with varying difficulty levels
A workflow where content progresses through repeated cycles of evaluation and improvement, enabling continuous refinement through deliberate iterations.Business Use Cases:
A tree-structured organization where “manager” agents at higher levels delegate tasks to “specialist” agents at lower levels, then aggregate and refine their outputs.Business Use Cases:
Complex research reports requiring both oversight and specialized deep dives
Product development workflows coordinating multiple specialized teams
Multi-faceted analysis that benefits from both generalists and specialists
Organizational decision-making with multiple levels of approval
Enterprise customer service with tiered support levels
A flexible pattern that relies on agent descriptions and conversation context to naturally determine the most appropriate specialist for each stage of a conversation, without requiring explicit routing rules.Business Use Cases:
Collaborative creative projects where expertise needs shift organically throughout the process
Educational assistants that adapt to changing student questions across different subjects
Consultative services where problem diagnosis may require different specialists at unpredictable points
Versatile virtual assistants that handle diverse user needs without rigid conversation flows
A pattern that organizes agents into a linear sequence where each agent performs their specific action before passing onto the next agent in the chain.Business Use Cases:
A pattern that employs multiple agents to attempt the same task using different approaches, with results compared to select the best outcome or combine strengths.Business Use Cases:
Critical systems where errors must be minimized
Creative tasks benefiting from multiple distinct perspectives
Complex problem solving with unclear optimal approaches
Medical diagnosis requiring multiple expert opinions
Security systems needing cross-validation of potential threats
A pattern that breaks down complex requests into categorized, sequential tasks processed by specialized agents in a dependency-respecting workflow.Business Use Cases:
Content creation pipelines requiring research before writing
Product development processes with sequential phase requirements
Complex customer service requests needing multi-stage resolution
Academic or scientific workflows involving data gathering and analysis before conclusions
Report generation requiring fact-finding before compilation and presentation
Multi-phase project planning with dependent deliverables
Technical support cases requiring diagnosis before solution implementation
It is possible, and even expected, that some agents may fail to complete their response successfully and that may disrupt the workflow. This could be due an exception being raised in a tool call or function.If you are able to catch those exceptions, you can transfer to an error agent in your group chat using either ReplyResult or setting a context variable (e.g. my_agent.set_context("errored", True)) and using an OnContextCondition to transfer to the error agent.
Copy
from autogen.agentchat.group import AgentTarget, ContextExpression, OnContextCondition, ReplyResult# Transfer to the error_agent if the context variable "errored" is set to Truemy_agent.handoffs.add_context_condition( OnContextCondition( target=AgentTarget(error_agent), condition=ExpressionContextCondition(expression=ContextExpression("${errored}")), ))# Transfer to the error_agent when a tool failsdef my_tool_function(my_parameter: str, context_variables: ContextVariables) -> ReplyResult: try: ... except Exception as e: # Option 1: set context variable that will be handled in a handoff associated # with this agent (see above) context_variables["errored"] = True return ReplyResult( message=f"An exception was raised: {e}", context_variables=context_variables ) # Option 2: include the target error_agent in the returned ReplyResult # to transfer directly without the need for a handoff return ReplyResult( target=AgentTarget(error_agent), message=f"An exception was raised: {e}", context_variables=context_variables )# Error agent can return to the user (or some other agent) automatically when it transitionserror_agent.handoffs.set_after_work(RevertToUserTarget())