Multi-Agent AI Systems with LangChain: Building an
Multi-agent AI systems with LangChain: what a multi-agent system is, when multiple agents beat a single LLM agent, and how to build and connect the roles.
This article is published in English.
Sources: Multi-Agent AI Systems with LangChain: Building an Orchestrator That Delegates Work
The following notes reconstruct a practical path around “Multi-Agent AI Systems with LangChain: Building an Orchestrator That Delegates Work”. Emphasis stays on contracts, checks, and drop-in code placeholders rather than motivational framing. When working through the Overview stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments.
1. What Is a Multi-Agent System?
The 1 What Is a stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
User
|
v
Single Agent
|
+-- Search
+-- Analyze
+-- Calculate
+-- Generate Report
User
|
v
+--------------+
| Main Agent |
| Orchestrator |
+------+-------+
|
+------------+------------+
| |
v v
+-------------+ +-------------+
| Math Agent | | Search Agent|
+-------------+ +-------------+
| |
square() search()
2. Why Use Multiple Agents?
The 2 Why Use Multiple stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
Database queries
Security analysis
Documentation search
Report generation
"I have a database question → call database agent."
"I have a security question → call security agent.""I need documentation → call documentation agent."
Single agent
The Single agent stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
LLM
|
+-------------+-------------+
| | |
Database Search Security
| | |
+-------------+-------------+
The Single agent stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments.
Multi-agent
For the Multi-agent stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
Main Agent
/ | \
/ | \
v v v
DB Agent Search Security
Agent Agent
3. Example: Two Specialized Agents
For the 3 Example Two Specialized stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
Calculate the square of a number
Calculate the square root of a number
@tool
def square_root(x: float) -> float:
"""Calculate the square root of a number"""
return x ** 0.5
@tool
def square(x: float) -> float:
"""Calculate the square of a number"""
return x ** 2
subagent_square_root = create_agent(
model=llm,
tools=[square_root]
)
subagent_square = create_agent(
model=llm,
tools=[square]
)
square_root()
square()
4. The Important Part: Turning Agents into Tools
For the 4 The Important Part stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Authenticate at the gateway and re-authorize at the data plane. A bearer token alone is not a tenancy boundary. For the 4 The Important Part stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments.
@tool
def call_subagent_square_root(x: float) -> float:
"""Call subagent 1 in order to calculate
the square root of a number"""
response = subagent_square_root.invoke(
{
"messages": [
HumanMessage(
content=f"Calculate the square root of {x}"
)
]
}
) return response["messages"][-1].content
@tool
def call_subagent_square(x: float) -> float:
"""Call subagent 2 in order to calculate
the square of a number"""
response = subagent_square.invoke(
{
"messages": [
HumanMessage(
content=f"Calculate the square of {x}"
)
]
}
) return response["messages"][-1].content
Main Agent
|
+-- call_subagent_square_root()
|
+-- call_subagent_square()
5. Creating the Orchestrator
When working through the 5 Creating the Orchestrator stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
main_agent = create_agent(
model=llm,
tools=[
call_subagent_square_root,
call_subagent_square
],
system_prompt=
"You are a helpful assistant who can call "
"subagents to calculate the square root or "
"square of a number."
)
User
|
|
v
+----------------+
| Main Agent |
| Orchestrator |
+-------+--------+
|
Tool selection
/ \
/ \
v v
+----------------+ +----------------+
| Square Root | | Square |
| Subagent | | Subagent |
+-------+--------+ +-------+--------+
| |
v v
square_root() square()
6. What Happens When the User Asks a Question?
When working through the 6 What Happens When stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
What is the square root of 456?
response = main_agent.invoke(
{
"messages": [
HumanMessage(
content="What is the square root of 456?"
)
]
}
)
call_subagent_square_root(x=456)
Calculate the square root of 456
square_root()
21.3541565
The square root of 456 is approximately 21.35.
User
|
| "What is the square root of 456?"
v
Main Agent
|
| selects call_subagent_square_root
v
Square Root Subagent
|
| invokes square_root(456)
v
21.3541565
|
v
Main Agent
|
v
"The square root of 456 is approximately 21.35."
7. Where Does the LLM Fit?
When working through the 7 Where Does the stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Cache stable system instructions and tool schemas. Re-sending identical preamble is a common source of burn. When working through the 7 Where Does the stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments.
llm = ChatOllama(
model="llama3.2:latest",
base_url="http://localhost:11434",
temperature=0,
)
Ollama / Llama
|
+----------+----------+
| |
v v
Main Agent Subagents
Orchestrator Specialized
Main Agent → powerful reasoning model
Security Agent → security-specialized modelCoding Agent → coding modelSimple Agent → smaller/cheaper model
8. Multi-Agent Does Not Mean Multiple LLMs
The 8 Multi-Agent Does Not stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Budget tokens per turn and per session. Agentic tools expand context aggressively; hard caps keep demos from becoming surprise invoices.
Model A
|
+-- Agent 1
+-- Agent 2
+-- Agent 3
Model A → Agent 1
Model B → Agent 2
Model C → Agent 3
Agent =
Model
+ Instructions
+ Tools
+ State/Context
+ Decision-making
9. Why Not Just Give All Tools to One Agent?
The 9 Why Not Just stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Expose tools with narrow schemas and explicit side-effect labels. Hosts need to know which calls mutate state before they auto-approve.
Orchestrator
|
+-------------------+-------------------+
| | |
v v v
Database Agent Security Agent Research Agent
| | |
PostgreSQL SIEM/Security Web/MCP
|
v
Report Generator
10. Multi-Agent vs. Sequential Workflow
The 10 Multi-Agent vs Sequential stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts. The 10 Multi-Agent vs Sequential stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments.
Sequential workflow
For the Sequential workflow stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
Step 1
↓
Step 2
↓
Step 3
↓
Step 4
Retrieve documents
↓
Analyze documents
↓
Generate report
↓
Send email
Orchestrated multi-agent system
For the Orchestrated multi-agent system stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
Orchestrator
/ | \
/ | \
Agent A Agent B Agent C
Workflow = predefined control flow
Multi-Agent =
LLM-driven delegation between specialized agents
11. Production Architecture
For the 11 Production Architecture stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline.
User
|
v
+-------------------+
| Orchestrator |
| Agent |
+---------+---------+
|
+----------------+----------------+
| | |
v v v
+-----------+ +-----------+ +-----------+
| Research | | Security | | Database |
| Agent | | Agent | | Agent |
+-----+-----+ +-----+-----+ +-----+-----+
| | |
v v v
Web/MCP SIEM/APIs PostgreSQL
| | |
+----------------+----------------+
|
v
+----------------+
| Final Response |
| / Report Agent |
+----------------+
Research Agent
→ web search
→ document retrieval
→ RAG
Security Agent
→ SIEM
→ vulnerability database
→ security APIsDatabase Agent
→ SQL
→ analyticsReport Agent
→ summarize
→ format
→ email
12. Key Takeaways
1. Specialize agents
Agent → one domain / capability
2. Wrap subagents as tools
Main Agent
|
+-- Subagent Tool
3. Let the orchestrator delegate
4. Keep the interfaces simple
Tool name
Description
Arguments
Result
5. Start simple
AI Orchestrator
|
+----------------+----------------+
| | |
Research Coding Security
Agent Agent Agent
| | |
MCP GitHub Security APIs
RAG Tools SIEM
Conclusion
User
↓
Main Agent
↓
Tool representing a subagent
↓
Specialized Subagent
↓
Domain-specific Tool
↓
Result
↓
Main Agent
↓
User