yoon-gu commited on
Commit
4f3b1c9
·
verified ·
1 Parent(s): 9e93462

Create graph.py

Browse files
Files changed (1) hide show
  1. graph.py +54 -0
graph.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_openai import ChatOpenAI
2
+ from langgraph_supervisor import create_supervisor
3
+ from langgraph.prebuilt import create_react_agent
4
+
5
+ model = ChatOpenAI(model="gpt-4o")
6
+
7
+ # Create specialized agents
8
+
9
+ def add(a: float, b: float) -> float:
10
+ """Add two numbers."""
11
+ return a + b
12
+
13
+ def multiply(a: float, b: float) -> float:
14
+ """Multiply two numbers."""
15
+ return a * b
16
+
17
+ def web_search(query: str) -> str:
18
+ """Search the web for information."""
19
+ return (
20
+ "Here are the headcounts for each of the FAANG companies in 2024:\n"
21
+ "1. **Facebook (Meta)**: 67,317 employees.\n"
22
+ "2. **Apple**: 164,000 employees.\n"
23
+ "3. **Amazon**: 1,551,000 employees.\n"
24
+ "4. **Netflix**: 14,000 employees.\n"
25
+ "5. **Google (Alphabet)**: 181,269 employees."
26
+ )
27
+
28
+ math_agent = create_react_agent(
29
+ model=model,
30
+ tools=[add, multiply],
31
+ name="math_expert",
32
+ prompt="You are a math expert. Always use one tool at a time."
33
+ )
34
+
35
+ research_agent = create_react_agent(
36
+ model=model,
37
+ tools=[web_search],
38
+ name="research_expert",
39
+ prompt="You are a world class researcher with access to web search. Do not do any math."
40
+ )
41
+
42
+ # Create supervisor workflow
43
+ workflow = create_supervisor(
44
+ [research_agent, math_agent],
45
+ model=model,
46
+ prompt=(
47
+ "You are a team supervisor managing a research expert and a math expert. "
48
+ "For current events, use research_agent. "
49
+ "For math problems, use math_agent."
50
+ )
51
+ )
52
+
53
+ # Compile and run
54
+ app = workflow.compile()