Skip to content

Commit 4c2b858

Browse files
authored
Merge pull request #46 from langchain-ai/rlm/researcher
Add researcher
2 parents ee20820 + d8add20 commit 4c2b858

File tree

13 files changed

+3226
-17
lines changed

13 files changed

+3226
-17
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Customer Support Example
2+
3+
A simple example of building a customer support system using LangGraph Swarm. This example demonstrates how to create a system where agents can hand off conversations to other specialized agents.
4+
5+
## Overview
6+
7+
The system consists of two specialized agents:
8+
- **Flight Assistant**: Handles flight search and booking
9+
- **Hotel Assistant**: Handles hotel search and booking
10+
11+
These agents can transfer control to each other using handoff tools, allowing for a seamless customer experience.
12+
13+
## Quickstart
14+
15+
```bash
16+
uvx --refresh --from "langgraph-cli[inmem]" --with-editable . --python 3.11 langgraph dev
17+
```
18+
19+
## Features
20+
21+
- Agent handoff between specialized services
22+
- Mock data for flights and hotels
23+
- Reservation tracking by user ID
24+
- Built with LangGraph Swarm for agent orchestration
25+
26+
## How It Works
27+
28+
1. The system starts with the Flight Assistant as the default agent
29+
2. Agents can pass control using handoff tools (`transfer_to_hotel_assistant` and `transfer_to_flight_assistant`)
30+
3. User context and reservation information is maintained throughout handoffs
31+
4. Agents have access to specific tools related to their domain
32+
33+
34+
35+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": ["."],
3+
"graphs": {
4+
"agent": "./src/agent/customer_support.py:app"
5+
}
6+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[project]
2+
name = "swarm-customer-support"
3+
version = "0.0.1"
4+
description = "Simple customer support example using LangGraph Swarm."
5+
authors = [
6+
{ name = "Lance Martin" }
7+
]
8+
readme = "README.md"
9+
license = { text = "MIT" }
10+
requires-python = ">=3.9"
11+
dependencies = [
12+
"langchain-openai>=0.3.11",
13+
"langgraph>=0.3.21",
14+
"langgraph-swarm>=0.0.7",
15+
"langchain>=0.3.21",
16+
]
17+
18+
[project.optional-dependencies]
19+
dev = ["mypy>=1.11.1", "ruff>=0.6.1"]
20+
21+
[build-system]
22+
requires = ["setuptools>=73.0.0", "wheel"]
23+
build-backend = "setuptools.build_meta"
24+
25+
[tool.setuptools]
26+
packages = ["customer_support"]
27+
28+
[tool.setuptools.package-dir]
29+
"customer_support" = "src/agent"
30+
31+
[tool.setuptools.package-data]
32+
"*" = ["py.typed"]
33+
34+
[tool.ruff]
35+
lint.select = [
36+
"E", # pycodestyle
37+
"F", # pyflakes
38+
"I", # isort
39+
"D", # pydocstyle
40+
"D401", # First line should be in imperative mood
41+
"T201",
42+
"UP",
43+
]
44+
lint.ignore = [
45+
"UP006",
46+
"UP007",
47+
"UP035",
48+
"D417",
49+
"E501",
50+
]
51+
52+
[tool.ruff.lint.per-file-ignores]
53+
"tests/*" = ["D", "UP"]
54+
55+
[tool.ruff.lint.pydocstyle]
56+
convention = "google"

examples/customer_support/src/agent/customer_support.ipynb

Lines changed: 699 additions & 0 deletions
Large diffs are not rendered by default.

examples/customer_support.py renamed to examples/customer_support/src/agent/customer_support.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
from langchain_core.runnables import RunnableConfig
66
from langchain_openai import ChatOpenAI
7-
from langgraph.checkpoint.memory import InMemorySaver
87
from langgraph.prebuilt import create_react_agent
9-
108
from langgraph_swarm import create_handoff_tool, create_swarm
119

1210
model = ChatOpenAI(model="gpt-4o")
@@ -126,18 +124,7 @@ def prompt(state: dict, config: RunnableConfig) -> list:
126124
)
127125

128126
# Compile and run!
129-
checkpointer = InMemorySaver()
130-
builder = create_swarm([flight_assistant, hotel_assistant], default_active_agent="flight_assistant")
131-
132-
# Important: compile the swarm with a checkpointer to remember
133-
# previous interactions and last active agent
134-
app = builder.compile(checkpointer=checkpointer)
135-
# config = {"configurable": {"thread_id": "1", "user_id": "1"}}
136-
# result = app.invoke({
137-
# "messages": [
138-
# {
139-
# "role": "user",
140-
# "content": "i am looking for a flight from boston to ny tomorrow"
141-
# }
142-
# ],
143-
# }, config)
127+
builder = create_swarm(
128+
[flight_assistant, hotel_assistant], default_active_agent="flight_assistant"
129+
)
130+
app = builder.compile()

examples/research/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Swarm Researcher Example
2+
3+
A two-phase multi-agent system that demonstrates an effective collaborative approach to planning and research tasks. This example showcases a pattern used in many deep research systems:
4+
5+
1. **Planning Phase**: A dedicated planner agent clarifies requirements, reads documentation, and develops a structured approach
6+
2. **Research Phase**: A researcher agent implements the solution based on the planner's guidance
7+
8+
## Quickstart
9+
10+
```bash
11+
uvx --refresh --from "langgraph-cli[inmem]" --with-editable . --python 3.11 langgraph dev
12+
```
13+
14+
## How It Works
15+
16+
- The system starts with the **planner agent** that:
17+
- Analyzes the user's request
18+
- Reads relevant documentation
19+
- Asks clarifying questions to refine scope
20+
- Creates a structured plan with clear objectives
21+
- Identifies the most relevant resources for implementation
22+
- Hands off to the researcher agent
23+
24+
- The **researcher agent** then:
25+
- Follows the structured plan from the planner
26+
- Reads the recommended documentation sources
27+
- Implements the solution to satisfy all requirements
28+
- Can request additional planning if needed
29+
30+
This pattern demonstrates how breaking complex tasks into planning and execution phases can lead to more thorough, well-researched outcomes.
31+

examples/research/langgraph.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": ["."],
3+
"graphs": {
4+
"agent": "./src/agent/agent.py:app"
5+
}
6+
}

examples/research/pyproject.toml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[project]
2+
name = "swarm-researcher"
3+
version = "0.0.1"
4+
description = "Simple multi-agent example for planning and research."
5+
authors = [
6+
{ name = "Lance Martin" }
7+
]
8+
readme = "README.md"
9+
license = { text = "MIT" }
10+
requires-python = ">=3.9"
11+
dependencies = [
12+
"httpx>=0.28.1",
13+
"markdownify>=1.1.0",
14+
"langchain-anthropic>=0.3.10",
15+
"langchain-openai>=0.3.11",
16+
"langchain-mcp-adapters>=0.0.5",
17+
"langgraph>=0.3.21",
18+
"langgraph-swarm>=0.0.7",
19+
"langchain>=0.3.21",
20+
]
21+
22+
[project.optional-dependencies]
23+
dev = ["mypy>=1.11.1", "ruff>=0.6.1"]
24+
25+
[build-system]
26+
requires = ["setuptools>=73.0.0", "wheel"]
27+
build-backend = "setuptools.build_meta"
28+
29+
[tool.setuptools]
30+
packages = ["swarm_researcher"]
31+
32+
[tool.setuptools.package-dir]
33+
"swarm_researcher" = "src/agent"
34+
35+
[tool.setuptools.package-data]
36+
"*" = ["py.typed"]
37+
38+
[tool.ruff]
39+
lint.select = [
40+
"E", # pycodestyle
41+
"F", # pyflakes
42+
"I", # isort
43+
"D", # pydocstyle
44+
"D401", # First line should be in imperative mood
45+
"T201",
46+
"UP",
47+
]
48+
lint.ignore = [
49+
"UP006",
50+
"UP007",
51+
"UP035",
52+
"D417",
53+
"E501",
54+
]
55+
56+
[tool.ruff.lint.per-file-ignores]
57+
"tests/*" = ["D", "UP"]
58+
59+
[tool.ruff.lint.pydocstyle]
60+
convention = "google"

0 commit comments

Comments
 (0)