Master the 7 Common AI Agent Design Patterns and Frameworks
This article surveys seven core multi‑agent design patterns—workflow, routing, parallel, loop, aggregation, network, and hierarchy—explains their mechanics, trade‑offs, and suitable scenarios, and reviews popular frameworks such as AutoGPT, Dify, AutoGen, CrewAI, and LangGraph, with concrete examples and code snippets.
Seven Multi‑Agent Design Patterns
1. Workflow (Prompt Chaining)
Each agent performs a step in a chain—e.g., one generates code, another reviews it, and a third deploys it. The output of each step becomes the input for the next, forming a dependency chain that guides the LLM toward the final solution. This pattern is suited for workflow automation, ETL, and multi‑step reasoning pipelines.
2. Routing
Routing introduces conditional logic, allowing an agent to dynamically select the next action from a set of possibilities based on context. A controller agent assigns tasks to specialized agents, as seen in MCP and A2A frameworks.
LLM routing (explicit vs. implicit): the LLM analyzes input and outputs an identifier or command; implicit routing wraps downstream agents as tool functions.
Embedding routing: uses vector similarity to route queries semantically.
Rule‑based routing: hard‑coded keywords, patterns, or structured data determine the route.
Small‑model routing: a fine‑tuned classifier decides the route, with the LLM optionally generating synthetic training data.
def __init__(self):
# Use a lightweight sentence‑encoding model
self.model = ChatModel(model_name="gpt-4", api_key="", stream=False)
# Define routing capabilities and handlers
self.routes = {
'code_help': {
'description': '编程,代码',
'handler': self.handle_code_question
},
'general_chat': {
'description': '聊天,日常对话',
'handler': self.handle_general_chat
}
}
# Pre‑compute embeddings for route descriptions
self.route_embeddings = {}
for route_name, route_info in self.routes.items():
embedding = self.model.encode([route_info['description']])
self.route_embeddings[route_name] = embedding
def route_query(self, user_question):
# 1. Encode the user question
question_embedding = self.model.encode([user_question])
# 2. Compute cosine similarity with each route embedding
similarities = {}
for route_name, route_embedding in self.route_embeddings.items():
similarity = cosine_similarity(question_embedding, route_embedding)[0][0]
similarities[route_name] = similarity
# 3. Choose the best route
best_route = max(similarities, key=similarities.get)
best_score = similarities[best_route]
# 4. Call the corresponding handler
handler = self.routes[best_route]['handler']
response = handler(user_question)
return {'route': best_route, 'confidence': best_score, 'response': response}3. Parallel
Agents handle different sub‑tasks (e.g., web crawling, retrieval, summarization) in parallel, and their outputs are merged into a single result. This reduces latency in high‑throughput pipelines such as document parsing or API orchestration.
4. Loop
Agents iteratively improve their output until a quality threshold is reached. This is ideal for proofreading, report generation, or creative iteration, where the system re‑thinks before finalizing the result. Reflection occurs within this pattern.
5. Aggregation
Multiple agents generate partial results; a master agent consolidates them into a final output. This pattern appears in RAG retrieval fusion, voting systems, and similar scenarios.
6. Network
Agents have no fixed hierarchy and can freely exchange context, suitable for simulations, multi‑agent games, and collective reasoning systems. The agentscope‑samples project demonstrates a nine‑agent “Werewolf” game.
7. Hierarchy
A top‑level planning agent distributes sub‑tasks to worker agents, tracks progress, and makes the final decision—mirroring a manager‑team structure. This pattern underlies intent‑recognition systems and many middleware architectures such as Redis, Elasticsearch, and Nocas.
Multi‑Agent Frameworks
AutoGPT – 180k ★ on GitHub
Dify – 118k ★ on GitHub
AutoGen – 51.4k ★ on GitHub
CrewAI – 40.1k ★ on GitHub
LangGraph – 20.6k ★ on GitHub
Why Use an Agent Framework?
When a problem cannot be exhaustively enumerated, requires cross‑system verification, and needs clarification, negotiation, and decision‑making within a dialogue, an agent framework outperforms a pure workflow.
Limitations of Pure Workflows
Workflows are not naturally friendly to the “clarify → decide → act” loop; each step must be drawn as a node, making the system complex and fragile.
Example: Customer Service Scenario
User query: “My package hasn’t arrived, what should I do?” The system would need multiple agents: intent recognition, logistics status, policy rules, user profile, anomaly detection, clarification, and solution generation. The combinatorial explosion of branches demonstrates the need for dynamic decision‑making frameworks.
Core Problems Solved by Agent Frameworks
Frameworks such as AutoGen and CrewAI treat “dynamic planning and tool calling within a conversation” as a first‑principle capability.
Typical workflow:
Identify intents and ask clarifying questions (Planner Agent splits intents, asks for order number, address).
Gather evidence across systems (OMS/logistics, billing, CRM, insurance database).
Apply policy reasoning (Policy Agent combines holiday delay, membership status, insurance terms to compute compensation and decide if human review is needed).
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
