bstraehle commited on
Commit
1ec9f6e
·
verified ·
1 Parent(s): d0311ca

Update multi_agent.py

Browse files
Files changed (1) hide show
  1. multi_agent.py +14 -12
multi_agent.py CHANGED
@@ -26,8 +26,10 @@ def create_agent(llm: ChatOpenAI, tools: list, system_prompt: str):
26
  MessagesPlaceholder(variable_name="agent_scratchpad"),
27
  ]
28
  )
 
29
  agent = create_openai_tools_agent(llm, tools, prompt)
30
  executor = AgentExecutor(agent=agent, tools=tools)
 
31
  return executor
32
 
33
  def agent_node(state, agent, name):
@@ -45,17 +47,16 @@ def create_graph(model, topic):
45
  tavily_tool = TavilySearchResults(max_results=10)
46
 
47
  members = ["Researcher"]
48
-
 
49
  system_prompt = (
50
- "You are a Manager tasked with managing a conversation between the"
51
- " following agent(s): {members}. Given the following user request,"
52
- " respond with the agent to act next. Each agent will perform a"
53
- " task and respond with their results and status. When finished,"
54
- " respond with FINISH."
55
  )
56
 
57
- options = ["FINISH"] + members
58
-
59
  function_def = {
60
  "name": "route",
61
  "description": "Select the next role.",
@@ -80,8 +81,8 @@ def create_graph(model, topic):
80
  MessagesPlaceholder(variable_name="messages"),
81
  (
82
  "system",
83
- "Given the conversation above, who should act next?"
84
- " Or should we FINISH? Select one of: {options}",
85
  ),
86
  ]
87
  ).partial(options=str(options), members=", ".join(members))
@@ -102,16 +103,17 @@ def create_graph(model, topic):
102
  researcher_node = functools.partial(agent_node, agent=researcher_agent, name="Researcher")
103
 
104
  workflow = StateGraph(AgentState)
105
- workflow.add_node("Researcher", researcher_node)
106
  workflow.add_node("Manager", supervisor_chain)
 
107
 
108
  for member in members:
109
  workflow.add_edge(member, "Manager")
110
 
111
  conditional_map = {k: k for k in members}
112
  conditional_map["FINISH"] = END
113
-
114
  workflow.add_conditional_edges("Manager", lambda x: x["next"], conditional_map)
 
115
  workflow.set_entry_point("Manager")
116
 
117
  return workflow.compile()
 
26
  MessagesPlaceholder(variable_name="agent_scratchpad"),
27
  ]
28
  )
29
+
30
  agent = create_openai_tools_agent(llm, tools, prompt)
31
  executor = AgentExecutor(agent=agent, tools=tools)
32
+
33
  return executor
34
 
35
  def agent_node(state, agent, name):
 
47
  tavily_tool = TavilySearchResults(max_results=10)
48
 
49
  members = ["Researcher"]
50
+ options = ["FINISH"] + members
51
+
52
  system_prompt = (
53
+ "You are a Manager tasked with managing a conversation between the "
54
+ "following agent(s): {members}. Given the following user request, "
55
+ "respond with the agent to act next. Each agent will perform a "
56
+ "task and respond with their results and status. When finished, "
57
+ "respond with FINISH."
58
  )
59
 
 
 
60
  function_def = {
61
  "name": "route",
62
  "description": "Select the next role.",
 
81
  MessagesPlaceholder(variable_name="messages"),
82
  (
83
  "system",
84
+ "Given the conversation above, who should act next? "
85
+ "Or should we FINISH? Select one of: {options}.",
86
  ),
87
  ]
88
  ).partial(options=str(options), members=", ".join(members))
 
103
  researcher_node = functools.partial(agent_node, agent=researcher_agent, name="Researcher")
104
 
105
  workflow = StateGraph(AgentState)
106
+
107
  workflow.add_node("Manager", supervisor_chain)
108
+ workflow.add_node("Researcher", researcher_node)
109
 
110
  for member in members:
111
  workflow.add_edge(member, "Manager")
112
 
113
  conditional_map = {k: k for k in members}
114
  conditional_map["FINISH"] = END
 
115
  workflow.add_conditional_edges("Manager", lambda x: x["next"], conditional_map)
116
+
117
  workflow.set_entry_point("Manager")
118
 
119
  return workflow.compile()