The world of software program growth has already discovered this lesson: monolithic purposes do not scale. Whether or not you are constructing a large e-commerce platform or a posh AI utility, counting on a single, all-in-one entity creates bottlenecks, will increase debugging prices, and limits specialised efficiency.
The identical precept applies to an AI agent. A single agent tasked with too many obligations turns into a “Jack of all trades, grasp of none.” Because the complexity of directions will increase, adherence to particular guidelines degrades, and error charges compound, resulting in increasingly more “hallucinations.” In case your agent fails, you should not must tear down your complete immediate to seek out the bug.
Reliability comes from decentralization and specialization. Multi-Agent Programs (MAS) can help you construct the AI equal of a microservices structure. By assigning particular roles (a Parser, a Critic, a Dispatcher) to particular person brokers, you construct programs which might be inherently extra modular, testable, and dependable.
On this information we’ll be utilizing the Google Agent Growth Package (ADK) as an instance 8 important design patterns, from the Sequential Pipeline to the Human-in-the-loop design sample, offering you with the concrete patterns and pseudocode you have to construct production-grade agent groups.
1. Sequential Pipeline Sample (aka the meeting line)
Let’s begin with the bread and butter of agent workflows. Consider this sample as a traditional meeting line the place Agent A finishes a job and fingers the baton on to Agent B. It’s linear, deterministic, and refreshingly straightforward to debug since you at all times know precisely the place the info got here from.
That is your go-to structure for information processing pipelines. Within the instance under, we see a circulation for processing uncooked paperwork: a Parser Agent turns a uncooked PDF into textual content, an Extractor Agent pulls out structured information, and a Summarizer Agent generates the ultimate synopsis.
In ADK, the SequentialAgent primitive handles the orchestration for you. The key sauce right here is state administration: merely use the output_key to put in writing to the shared session.state so the following agent within the chain is aware of precisely the place to choose up the work.
# ADK Pseudocode
# Step 1: Parse the PDF
parser = LlmAgent(
identify="ParserAgent",
instruction="Parse uncooked PDF and extract textual content.",
instruments=[PDFParser],
output_key="raw_text"
)
# Step 2: Extract structured information
extractor = LlmAgent(
identify="ExtractorAgent",
instruction="Extract structured information from {raw_text}.",
instruments=[RegexExtractor],
output_key="structured_data"
)
# Step 3: Summarize
summarizer = LlmAgent(
identify="SummarizerAgent",
instruction="Generate abstract from {structured_data}.",
instruments=[SummaryEngine]
)
# Orchestrate the Meeting Line
pipeline = SequentialAgent(
identify="PDFProcessingPipeline",
sub_agents=[parser, extractor, summarizer]
)
Python
2. Coordinator/Dispatcher Sample (aka the concierge)
Generally you do not want a sequence; you want a choice maker. On this sample, a central, clever agent acts as a dispatcher. It analyzes the person’s intent and routes the request to a specialist agent finest suited to the job.
That is best for complicated customer support bots the place you may must ship a person to a “Billing” specialist for bill points versus a “Tech Assist” specialist for troubleshooting.
This depends on LLM-driven delegation. You merely outline a dad or mum CoordinatorAgent and supply an inventory of specialist sub_agents. The ADK’s AutoFlow mechanism takes care of the remaining, transferring execution primarily based on the descriptions you present for the youngsters.
# ADK Pseudocode
billing_specialist = LlmAgent(
identify="BillingSpecialist",
description="Handles billing inquiries and invoices.",
instruments=[BillingSystemDB]
)
tech_support = LlmAgent(
identify="TechSupportSpecialist",
description="Troubleshoots technical points.",
instruments=[DiagnosticTool]
)
# The Coordinator (Dispatcher)
coordinator = LlmAgent(
identify="CoordinatorAgent",
# The directions information the routing logic
instruction="Analyze person intent. Route billing points to BillingSpecialist and bugs to TechSupportSpecialist.",
sub_agents=[billing_specialist, tech_support]
)
Python
3. Parallel Fan-Out/Collect Sample (aka the octopus)
Pace issues. When you have duties that do not depend upon one another, why run them one after the other? On this sample, a number of brokers execute duties concurrently to cut back latency or acquire numerous views. Their outputs are then aggregated by a ultimate “synthesizer” agent .
That is best for one thing like Automated Code Assessment. As a substitute of working checks sequentially, you’ll be able to spawn a “Safety Auditor,” a “Fashion Enforcer,” and a “Efficiency Analyst” to evaluation a Pull Request concurrently. As soon as they end, a “Synthesizer” agent combines their suggestions right into a single, cohesive evaluation remark.
The ParallelAgent in ADK must be used to run sub-agents concurrently. Bear in mind that though these brokers function in separate execution threads, they share the session state. To stop race situations, ensure that every agent writes its information to a novel key.
# ADK Pseudocode
# Outline parallel staff
security_scanner = LlmAgent(
identify="SecurityAuditor",
instruction="Verify for vulnerabilities like injection assaults.",
output_key="security_report"
)
style_checker = LlmAgent(
identify="StyleEnforcer",
instruction="Verify for PEP8 compliance and formatting points.",
output_key="style_report"
)
complexity_analyzer = LlmAgent(
identify="PerformanceAnalyst",
instruction="Analyze time complexity and useful resource utilization.",
output_key="performance_report"
)
# Fan-out (The Swarm)
parallel_reviews = ParallelAgent(
identify="CodeReviewSwarm",
sub_agents=[security_scanner, style_checker, complexity_analyzer]
)
# Collect/Synthesize
pr_summarizer = LlmAgent(
identify="PRSummarizer",
instruction="Create a consolidated Pull Request evaluation utilizing {security_report}, {style_report}, and {performance_report}."
)
# Wrap in a sequence
workflow = SequentialAgent(sub_agents=[parallel_reviews, pr_summarizer])
Python
4. Hierarchical decomposition (aka the russian doll)
Generally a job is just too large for one agent context window. Excessive-level brokers can break down complicated objectives into sub-tasks and delegate them. In contrast to the routing sample, the dad or mum agent may delegate simply half of a job and await the consequence to proceed its personal reasoning.
On this diagram, we see a ReportWriter that does not do the analysis itself. It delegates to a ResearchAssistant, which in flip manages WebSearch and Summarizer instruments.
You’ll be able to deal with a sub-agent as a software right here. By wrapping an agent in AgentTool, the dad or mum agent can name it explicitly, successfully treating the sub-agent’s complete workflow as a single perform name.
# ADK Pseudocode
# Stage 3: Device Brokers
web_searcher = LlmAgent(identify="WebSearchAgent", description="Searches internet for info.")
summarizer = LlmAgent(identify="SummarizerAgent", description="Condenses textual content.")
# Stage 2: Coordinator Agent
research_assistant = LlmAgent(
identify="ResearchAssistant",
description="Finds and summarizes data.",
# Coordinator manages the software brokers
sub_agents=[web_searcher, summarizer]
)
# Stage 1: High-Stage Agent
report_writer = LlmAgent(
identify="ReportWriter",
instruction="Write a complete report on AI tendencies. Use the ResearchAssistant to collect data.",
# Wrap the sub-agent hierarchy as a software for the dad or mum
instruments=[AgentTool(research_assistant)]
)
Python
5. Generator and critic (aka the editor’s desk)
Producing high-quality, dependable output usually requires a second pair of eyes. On this sample, you separate the creation of content material from the validation of content material. One agent acts because the Generator, producing a draft, whereas a second agent acts because the Critic, reviewing it towards particular, hard-coded standards or logical checks.
This structure is distinct due to its conditional looping. If the evaluation passes, the loop breaks, and the content material is finalized. If it fails, particular suggestions is routed again to the Generator to provide a compliant draft. That is extremely helpful for code era that wants syntax checking or content material creation requiring compliance evaluation.
To implement this in ADK, you separate issues into two particular primitives: a SequentialAgent that manages the draft-and-review interplay, and a dad or mum LoopAgent that enforces the standard gate and exit situation.
# ADK Pseudocode
# The Generator
generator = LlmAgent(
identify="Generator",
instruction="Generate a SQL question. In case you obtain {suggestions}, repair the errors and generate once more.",
output_key="draft"
)
# The Critic
critic = LlmAgent(
identify="Critic",
instruction="Verify if {draft} is legitimate SQL. If right, output 'PASS'. If not, output error particulars.",
output_key="suggestions"
)
# The Loop
loop = LoopAgent(
identify="ValidationLoop",
sub_agents=[generator, critic],
condition_key="suggestions",
exit_condition="PASS"
)
Python
6. Iterative refinement (aka the sculptor)
Nice work not often occurs in a single draft. Identical to a human author must revise, polish, and edit, typically your brokers want a couple of makes an attempt to get a solution precisely proper. On this sample, brokers enter a cycle of producing, critiquing, and refining till the output meets a selected high quality threshold.
In contrast to the Generator and Critic sample, which focuses on correctness (Go/Fail), this sample focuses on qualitative enchancment. A Generator creates a tough draft, a Critique Agent offers optimization notes, and a Refinement Agent polishes the output primarily based on these notes
This sample is applied utilizing the LoopAgent. A essential element right here is the exit mechanism. When you can set a tough restrict utilizing max_iterations, ADK additionally permits brokers to sign early completion. An agent can set off an exit by signaling escalate=True inside its EventActions if the standard threshold is met earlier than the utmost iterations are reached.
# ADK Pseudocode
# Generator
generator = LlmAgent(
identify="Generator",
instruction="Generate an preliminary tough draft.",
output_key="current_draft"
)
# Critique Agent
critic = LlmAgent(
identify="Critic",
instruction="Assessment {current_draft}. Listing methods to optimize it for efficiency.",
output_key="critique_notes"
)
# Refiner Agent
refiner = LlmAgent(
identify="Refiner",
instruction="Learn {current_draft} and {critique_notes}. Rewrite the draft to be extra environment friendly.",
output_key="current_draft" # Overwrites the draft with higher model
)
# The Loop (Critique -> Refine)
loop = LoopAgent(
identify="RefinementLoop",
max_iterations=3,
sub_agents=[critic, refiner]
)
# Full Workflow
workflow = SequentialAgent(sub_agents=[generator, loop])
Python
7. Human-in-the-loop (the human security web)
AI Brokers are highly effective, however typically you want a human within the driver’s seat for essential decision-making. On this mannequin, brokers deal with the groundwork, however a human should authorize high-stakes actions – particularly these which might be irreversible or carry important penalties. This consists of executing monetary transactions, deploying code to manufacturing, or taking motion primarily based on delicate information (versus merely processing it), making certain security and accountability.
The diagram reveals a Transaction Agent processing routine work. When a high-stakes examine is required, it calls an ApprovalTool Agent, which pauses execution and waits for a Human Reviewer to say “Sure” or “No.”
ADK permits you to implement this by way of customized instruments. An agent can name an approval_tool which pauses execution or triggers an exterior system to request human intervention.
# ADK Pseudocode
transaction_agent = LlmAgent(
identify="TransactionAgent",
instruction="Deal with routine processing. If excessive stakes, name ApprovalTool.",
instruments=[ApprovalTool]
)
approval_agent = LlmAgent(
identify="ApprovalToolAgent",
instruction="Pause execution and request human enter."
)
workflow = SequentialAgent(sub_agents=[transaction_agent, approval_agent])
Python
8. Composite patterns (the mix-and-match)
Actual-world enterprise purposes not often match right into a single field. You’ll possible mix these patterns to construct production-grade purposes.
For instance, a sturdy Buyer Assist system may use a Coordinator to route requests. If the person has a technical difficulty, that department may set off a Parallel search of documentation and person historical past. The ultimate reply may then undergo a Generator and Critic loop to make sure tone consistency earlier than being despatched to the person.
A couple of pro-tips earlier than you begin:
- State administration is significant: In ADK, session.state is your whiteboard. Use descriptive keys when utilizing output_key so downstream brokers know precisely what they’re studying.
- Clear descriptions: When utilizing routing, the outline discipline of your sub-agents is successfully your API documentation for the LLM. Be exact.
- Begin easy: Don’t construct a nested loop system on day one. Begin with a sequential chain, debug it, after which add complexity.
Get Began Now
Able to construct your crew of brokers? Try the ADK Documentation to get began. We are able to’t wait to see what you construct.







