-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.py
More file actions
64 lines (52 loc) · 1.94 KB
/
graph.py
File metadata and controls
64 lines (52 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""LangGraph workflow definition"""
from langgraph.graph import StateGraph, END
from state import AgentState
from agents.manager import manager_agent
from agents.planner import planner_agent
from agents.analyzer import analyzer_agent
from agents.delegator import delegator_agent
from agents.executor import executor_agent
from agents.reviewer import reviewer_agent
from agents.reporter import reporter_agent
def create_workflow():
"""Build the multi-agent workflow graph"""
# Initialize graph
workflow = StateGraph(AgentState)
# Add all agent nodes
workflow.add_node("manager", manager_agent)
workflow.add_node("planner", planner_agent)
workflow.add_node("analyzer", analyzer_agent)
workflow.add_node("delegator", delegator_agent)
workflow.add_node("executor", executor_agent)
workflow.add_node("reviewer", reviewer_agent)
workflow.add_node("reporter", reporter_agent)
# Define routing function
def route_from_manager(state: AgentState) -> str:
"""Route based on manager's decision"""
next_agent = state.get("current_agent", "end")
if next_agent == "end":
return END
return next_agent
# Set entry point
workflow.set_entry_point("manager")
# Manager routes to all agents conditionally
workflow.add_conditional_edges(
"manager",
route_from_manager,
{
"planner": "planner",
"analyzer": "analyzer",
"delegator": "delegator",
"executor": "executor",
"reviewer": "reviewer",
"reporter": "reporter",
END: END
}
)
# All agents return to manager for next routing decision
for agent in ["planner", "analyzer", "delegator", "executor", "reviewer", "reporter"]:
workflow.add_edge(agent, "manager")
# Compile the graph
return workflow.compile()
# Create the app
app = create_workflow()