multi-agent-architect – skill Agent & Tự động hóa cho agent AI
Thiết kế và tối ưu hệ thống multi-agent cấp production với LangGraph, LangChain và DeepAgents cho các workflow AI phức tạp.
Cài skill multi-agent-architect bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/multi-agent-architect-3d317.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /multi-agent-architect – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/multi-agent-architect-3d317.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $multi-agent-architect – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/multi-agent-architect-3d317.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /multi-agent-architect – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/multi-agent-architect-3d317.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /multi-agent-architect – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Multi-Agent Architect & Updater Skill
Overview
This skill turns Claude into a Senior AI Multi-Agent Architect specialized in LangGraph, LangChain, and DeepAgents. It provides structured workflows for creating and updating production-grade multi-agent systems — including supervisor agents, planners, researchers, coders, and memory-backed autonomous pipelines. Use it whenever you need to design, build, debug, or scale any multi-agent AI system.
If this skill adapts material from an external GitHub repository, declare both:
source_repo: owner/reposource_type: officialorsource_type: community
When to Use This Skill
- Use when you need to create a new agent or multi-agent workflow from scratch
- Use when working with LangGraph state graphs, nodes, edges, or conditional routing
- Use when the user asks about agent communication, memory systems, or tool-calling pipelines
- Use when debugging or optimizing an existing LangChain/LangGraph agent system
- Use when architecting supervisor, planner, research, coding, or validation agent roles
- Use when integrating DeepAgents with hierarchical planning and delegation
Inline code is a partial architecture sketch, not a production-ready or currently verified API integration. bind_tools only produces tool-call requests: a connected messages state, ToolNode route and return edge are required to execute them. The shown ToolNode is disconnected and must not be claimed to have researched or written anything. Redis history is not wired to the graph; use an authenticated tenant/session namespace and actual checkpoint/history integration. Protect the optional FastAPI endpoint with authentication, authorization, input/rate/time/token budgets and isolation. Increment and enforce a step budget before model calls; textual critique containing “bug” is not a test or reliable routing criterion.
How It Works
Step 1: Understand the Goal
Before writing any code, clarify:
- What is the business objective this agent system must achieve?
- What agent roles are needed (supervisor, planner, researcher, coder, validator)?
- What tools does each agent require?
- What memory strategy is needed (Redis, Vector DB, LangChain Memory)?
- What communication protocol connects agents (shared state, message passing)?
Step 2: Define the State Schema
All agents share a typed state object passed through the graph:
from typing import TypedDict
class AgentState(TypedDict):
user_goal: str
tasks: list[str]
completed_tasks: list[str]
next_agent: str
context: dict
step_count: int # guards against infinite loops
error: str | NoneStep 3: Define Agent Nodes
Each agent is an async function that reads from state and returns an updated state:
import logging
from langchain_openai import ChatOpenAI
logger = logging.getLogger(__name__)
async def research_node(state: AgentState) -> AgentState:
logger.info("research_node: starting")
llm = ChatOpenAI(model="gpt-4o")
result = await llm.bind_tools(research_tools).ainvoke(state["user_goal"])
state["context"]["research"] = result.content
state["next_agent"] = "coder"
return stateStep 4: Build the LangGraph
Wire nodes together with edges and conditional routing:
from langgraph.graph import StateGraph, END
from langgraph.prebuilt import ToolNode
def build_graph() -> StateGraph:
graph = StateGraph(AgentState)
graph.add_node("supervisor", supervisor_node)
graph.add_node("research", research_node)
graph.add_node("coder", coding_node)
graph.add_node("validator", validation_node)
graph.add_node("tools", ToolNode(all_tools))
graph.set_entry_point("supervisor")
graph.add_conditional_edges(
"supervisor",
route_next,
{"research": "research", "coder": "coder", "validator": "validator", "end": END}
)
graph.add_edge("research", "supervisor")
graph.add_edge("coder", "validator")
graph.add_edge("validator", "supervisor")
return graph.compile()
def route_next(state: AgentState) -> str:
if state["step_count"] > 20:
return "end"
return state["next_agent"]Step 5: Add Memory
from langchain_community.chat_message_histories import RedisChatMessageHistory
def get_memory(session_id: str):
return RedisChatMessageHistory(
session_id=session_id,
url=os.getenv("REDIS_URL"),
ttl=3600
)Step 6: Run the Graph
async def run(user_goal: str, session_id: str):
graph = build_graph()
initial_state = AgentState(
user_goal=user_goal,
tasks=[],
completed_tasks=[],
next_agent="supervisor",
context={},
step_count=0,
error=None,
)
return await graph.ainvoke(initial_state, config={"recursion_limit": 100})Step 7: Expose via FastAPI (optional)
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class RunRequest(BaseModel):
goal: str
session_id: str
@app.post("/run")
async def run_agent(req: RunRequest):
result = await run(req.goal, req.session_id)
return {"result": result}---
Updating an Existing Agent
When the user wants to update or debug an existing agent, structure the response as:
## Existing Issue
[Describe the current problem]
## Root Cause
[Identify why it's happening in the architecture]
## Proposed Update
[Outline the changes at architecture level]
## Updated Code
[Generate only the changed modules]
## Migration Notes
[What breaks, what's backward-compatible]
## Performance Impact
[Latency / token / memory delta]---
Standard Folder Structure
Always generate code in this layout:
multi_agent_system/
├── agents/ # One file per agent role
├── tools/ # Tool definitions and wrappers
├── memory/ # Redis, VectorDB, LangChain memory helpers
├── prompts/ # Prompt templates (one per agent)
├── workflows/ # High-level orchestration logic
├── graphs/ # LangGraph state + compiled graph definitions
├── api/ # FastAPI routes (optional)
├── configs/ # Config loader — no secrets in code
├── tests/ # Unit + integration tests per agent
└── main.py---
Examples
Example 1: Research + Coding Multi-Agent Workflow
# agents/research_agent.py
async def research_node(state: AgentState) -> AgentState:
llm = ChatOpenAI(model="gpt-4o").bind_tools([web_search, rag_search])
response = await llm.ainvoke(
f"Research the following and return structured findings:\n{state['user_goal']}"
)
state["context"]["research"] = response.content
state["next_agent"] = "coder"
return state
# agents/coding_agent.py
async def coding_node(state: AgentState) -> AgentState:
llm = ChatOpenAI(model="gpt-4o").bind_tools([python_repl, github_tool])
response = await llm.ainvoke(
f"Given this research:\n{state['context']['research']}\n\nWrite production Python code."
)
state["context"]["code"] = response.content
state["next_agent"] = "validator"
return stateExample 2: Supervisor with Dynamic Delegation
# agents/supervisor_agent.py
DELEGATION_PROMPT = """
You are a supervisor. Given the current state, decide the next agent.
Available agents: research, coder, validator, end.
Respond with ONLY the agent name.
Goal: {goal}
Completed: {completed}
Context keys available: {context}
"""
async def supervisor_node(state: AgentState) -> AgentState:
state["step_count"] += 1
llm = ChatOpenAI(model="gpt-4o")
decision = await llm.ainvoke(
DELEGATION_PROMPT.format(
goal=state["user_goal"],
completed=state["completed_tasks"],
context=list(state["context"].keys()),
)
)
next_agent = decision.content.strip().lower()
# Validate against allowlist before setting
allowed = {"research", "coder", "validator", "end"}
state["next_agent"] = next_agent if next_agent in allowed else "end"
return stateExample 3: DeepAgents Reflection Loop
async def reflection_node(state: AgentState) -> AgentState:
llm = ChatOpenAI(model="gpt-4o")
critique = await llm.ainvoke(
f"Evaluate this output critically:\n{state['context'].get('code', '')}\n"
"List any bugs, gaps, or improvements. Be concise."
)
state["context"]["critique"] = critique.content
state["next_agent"] = "coder" if "bug" in critique.content.lower() else "end"
return state---
Best Practices
- ✅ One agent = one responsibility — never combine planning + coding + testing in one node
- ✅ Use
TypedDictfor all state schemas — enables type checking and graph validation - ✅ Bind only the tools each agent needs — reduces hallucinated tool calls
- ✅ Always add a
step_countguard to prevent infinite
… (nội dung đầy đủ có trong gói tải về)
Skill liên quan
- multi-agent-brainstorming – Mô phỏng quy trình peer review có cấu trúc với nhiều agent chuyên biệt để kiểm tra thiết…
- multi-agent-patterns – Dùng skill này khi người dùng yêu cầu "design multi-agent system", "implement supervisor…
- multi-agent-task-orchestrator – Định tuyến tác vụ đến các agent AI chuyên biệt, với cơ chế chống trùng lặp, cổng kiểm…
- n8n-agents – Thiết kế agent AI, chain, classifier, extractor, tool calling, memory, RAG, structured…
- n8n-mcp-tools-expert – Hướng dẫn chuyên sâu cách dùng hiệu quả các công cụ MCP của n8n-mcp. Dùng khi tìm node…
- n8n-subworkflows – Xây dựng sub-workflow n8n có thể tái sử dụng, với input có kiểu, chế độ thực thi…
- n8n-workflow-patterns – Các mẫu kiến trúc đã được kiểm chứng để xây dựng workflow n8n.
- neverapply – Tìm việc phù hợp, tùy chỉnh CV, chuẩn bị phỏng vấn và ứng tuyển với sự đồng ý của người…