DrishtiSharma commited on
Commit
df88f89
·
verified ·
1 Parent(s): 4056a7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -46,16 +46,29 @@ graph.add_node("tool", invoke_tool)
46
  graph.add_edge("tool", END)
47
  graph.set_entry_point("agent")
48
 
 
49
  def router(state):
50
  tool_calls = state['messages'][-1].additional_kwargs.get("tool_calls", [])
51
- if len(tool_calls): # Check if tool_calls exist
52
- return "multiply" # Route to the tool node
53
  else:
54
- return "end" # Route to the end node
55
-
56
-
57
- graph.add_conditional_edges("agent", router, {"multiply": "tool", "end": END})
58
- app_graph = graph.compile()
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  # Save graph visualization as an image
61
  with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmpfile:
 
46
  graph.add_edge("tool", END)
47
  graph.set_entry_point("agent")
48
 
49
+ # Define the router function
50
  def router(state):
51
  tool_calls = state['messages'][-1].additional_kwargs.get("tool_calls", [])
52
+ if len(tool_calls):
53
+ return "tools"
54
  else:
55
+ return "end"
56
+
57
+ # Add graph nodes and edges
58
+ app_graph = StateGraph(MessagesState)
59
+ app_graph.add_node("assistant", assistant)
60
+ app_graph.add_node("tools", ToolNode(tools))
61
+
62
+ # Add conditional routing logic
63
+ app_graph.add_edge(START, "assistant")
64
+ app_graph.add_conditional_edges("assistant", router, {
65
+ "tools": "tools",
66
+ "end": END
67
+ })
68
+ app_graph.add_edge("tools", "assistant")
69
+
70
+ # Compile the graph
71
+ react_graph = app_graph.compile()
72
 
73
  # Save graph visualization as an image
74
  with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmpfile: