Skip to content

Commit 020ce63

Browse files
committed
fix: updata multi-agent sample
1 parent 3d444cd commit 020ce63

File tree

6 files changed

+367
-2732
lines changed

6 files changed

+367
-2732
lines changed

samples/multi-agent-supervisor-researcher-coder/README.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,37 @@ graph TD;
1919
__start__([<p>__start__</p>]):::first
2020
input(input)
2121
supervisor(supervisor)
22+
__end__([<p>__end__</p>]):::last
2223
__start__ --> input;
24+
coder\3a__end__ -.-> supervisor;
2325
input --> supervisor;
24-
supervisor -.-> researcher___start__;
25-
supervisor -.-> coder___start__;
26-
researcher___end__ -.-> supervisor;
27-
coder___end__ -.-> supervisor;
26+
researcher\3a__end__ -.-> supervisor;
27+
supervisor -.-> coder\3a__start__;
28+
supervisor -.-> researcher\3a__start__;
29+
supervisor -.-> __end__;
2830
subgraph researcher
29-
researcher___start__(<p>__start__</p>)
30-
researcher_agent(agent)
31-
researcher_tools(tools)
32-
researcher___end__(<p>__end__</p>)
33-
researcher___start__ --> researcher_agent;
34-
researcher_tools --> researcher_agent;
35-
researcher_agent -.-> researcher_tools;
36-
researcher_agent -.-> researcher___end__;
31+
researcher\3a__start__(<p>__start__</p>)
32+
researcher\3aagent(agent)
33+
researcher\3atools(tools)
34+
researcher\3a__end__(<p>__end__</p>)
35+
researcher\3a__start__ --> researcher\3aagent;
36+
researcher\3aagent -.-> researcher\3a__end__;
37+
researcher\3aagent -.-> researcher\3atools;
38+
researcher\3atools --> researcher\3aagent;
3739
end
3840
subgraph coder
39-
coder___start__(<p>__start__</p>)
40-
coder_agent(agent)
41-
coder_tools(tools)
42-
coder___end__(<p>__end__</p>)
43-
coder___start__ --> coder_agent;
44-
coder_tools --> coder_agent;
45-
coder_agent -.-> coder_tools;
46-
coder_agent -.-> coder___end__;
41+
coder\3a__start__(<p>__start__</p>)
42+
coder\3aagent(agent)
43+
coder\3atools(tools)
44+
coder\3a__end__(<p>__end__</p>)
45+
coder\3a__start__ --> coder\3aagent;
46+
coder\3aagent -.-> coder\3a__end__;
47+
coder\3aagent -.-> coder\3atools;
48+
coder\3atools --> coder\3aagent;
4749
end
4850
classDef default fill:#f2f0ff,line-height:1.2
4951
classDef first fill-opacity:0
5052
classDef last fill:#bfb6fc
51-
5253
```
5354

5455
## How It Works
@@ -68,7 +69,7 @@ graph TD;
6869

6970
## Requirements
7071

71-
- Python 3.10+
72+
- Python 3.11+
7273
- LangGraph
7374
- Anthropic API key (for Claude)
7475
- Tavily API key (for web search)

samples/multi-agent-supervisor-researcher-coder/agent.mermaid

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,33 @@ graph TD;
77
__start__([<p>__start__</p>]):::first
88
input(input)
99
supervisor(supervisor)
10+
__end__([<p>__end__</p>]):::last
1011
__start__ --> input;
12+
coder\3a__end__ -.-> supervisor;
1113
input --> supervisor;
12-
supervisor -.-> researcher___start__;
13-
supervisor -.-> coder___start__;
14-
researcher___end__ -.-> supervisor;
15-
coder___end__ -.-> supervisor;
14+
researcher\3a__end__ -.-> supervisor;
15+
supervisor -.-> coder\3a__start__;
16+
supervisor -.-> researcher\3a__start__;
17+
supervisor -.-> __end__;
1618
subgraph researcher
17-
researcher___start__(<p>__start__</p>)
18-
researcher_agent(agent)
19-
researcher_tools(tools)
20-
researcher___end__(<p>__end__</p>)
21-
researcher___start__ --> researcher_agent;
22-
researcher_tools --> researcher_agent;
23-
researcher_agent -.-> researcher_tools;
24-
researcher_agent -.-> researcher___end__;
19+
researcher\3a__start__(<p>__start__</p>)
20+
researcher\3aagent(agent)
21+
researcher\3atools(tools)
22+
researcher\3a__end__(<p>__end__</p>)
23+
researcher\3a__start__ --> researcher\3aagent;
24+
researcher\3aagent -.-> researcher\3a__end__;
25+
researcher\3aagent -.-> researcher\3atools;
26+
researcher\3atools --> researcher\3aagent;
2527
end
2628
subgraph coder
27-
coder___start__(<p>__start__</p>)
28-
coder_agent(agent)
29-
coder_tools(tools)
30-
coder___end__(<p>__end__</p>)
31-
coder___start__ --> coder_agent;
32-
coder_tools --> coder_agent;
33-
coder_agent -.-> coder_tools;
34-
coder_agent -.-> coder___end__;
29+
coder\3a__start__(<p>__start__</p>)
30+
coder\3aagent(agent)
31+
coder\3atools(tools)
32+
coder\3a__end__(<p>__end__</p>)
33+
coder\3a__start__ --> coder\3aagent;
34+
coder\3aagent -.-> coder\3a__end__;
35+
coder\3aagent -.-> coder\3atools;
36+
coder\3atools --> coder\3aagent;
3537
end
3638
classDef default fill:#f2f0ff,line-height:1.2
3739
classDef first fill-opacity:0

samples/multi-agent-supervisor-researcher-coder/graph.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import Annotated, Literal
22

33
from langchain_anthropic import ChatAnthropic
4-
from langchain_community.tools.tavily_search import TavilySearchResults
5-
from langchain_core.messages import HumanMessage, SystemMessage
4+
from langchain_tavily import TavilySearch
5+
from langchain_core.messages import HumanMessage, SystemMessage, BaseMessage
66
from langchain_core.tools import tool
77
from langchain_experimental.utilities import PythonREPL
88
from langgraph.graph import END, START, MessagesState, StateGraph
@@ -11,7 +11,8 @@
1111
from pydantic import BaseModel
1212
from typing_extensions import TypedDict
1313

14-
tavily_tool = TavilySearchResults(max_results=5)
14+
15+
tavily_tool = TavilySearch(max_results=5)
1516

1617
# This executes code locally, which can be unsafe
1718
repl = PythonREPL()
@@ -28,7 +29,7 @@ def python_repl_tool(
2829
result = repl.run(code)
2930
except BaseException as e:
3031
return f"Failed to execute. Error: {repr(e)}"
31-
result_str = f"Successfully executed:\n\`\`\`python\n{code}\n\`\`\`\nStdout: {result}"
32+
result_str = f"Successfully executed:\n```python\n{code}\n```\nStdout: {result}"
3233
return result_str
3334

3435
members = ["researcher", "coder"]
@@ -62,6 +63,16 @@ class GraphOutput(BaseModel):
6263
class State(MessagesState):
6364
next: str
6465

66+
def get_message_text(msg: BaseMessage) -> str:
67+
"""LangChain-style safe message text extractor."""
68+
if isinstance(msg.content, str):
69+
return msg.content
70+
if isinstance(msg.content, list):
71+
return "".join(
72+
block.get("text", "") for block in msg.content if block.get("type") == "text"
73+
)
74+
return ""
75+
6576
def input(state: GraphInput):
6677
return {
6778
"messages": [
@@ -75,7 +86,7 @@ async def supervisor_node(state: State) -> Command[Literal[*members]] | GraphOut
7586
response = await llm.with_structured_output(Router).ainvoke(state["messages"])
7687
goto = response["next"]
7788
if goto == "FINISH":
78-
return GraphOutput(answer=state["messages"][-1].content)
89+
return GraphOutput(answer=get_message_text(state["messages"][-1]))
7990
else:
8091
return Command(goto=goto, update={"next": goto})
8192

samples/multi-agent-supervisor-researcher-coder/pyproject.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ description = "Multi-agent system where a supervisor coordinates between a resea
55
authors = [{ name = "John Doe", email = "john.doe@myemail.com" }]
66
requires-python = ">=3.10"
77
dependencies = [
8-
"langgraph>=0.2.55",
9-
"langchain-anthropic>=0.3.8",
8+
"langgraph>=0.6.11",
9+
"langchain-anthropic>=0.3.22",
1010
"langchain-experimental>=0.3.4",
11-
"tavily-python>=0.5.0",
12-
"uipath-langchain==0.0.124"
11+
"tavily-python>=0.7.12",
12+
"uipath-langchain==0.0.141",
13+
"langchain-tavily>=0.2.12",
1314
]
1415

1516
[project.optional-dependencies]

0 commit comments

Comments
 (0)