DrishtiSharma commited on
Commit
141b6b8
·
verified ·
1 Parent(s): 0a642a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -1
app.py CHANGED
@@ -52,11 +52,14 @@ def invoke_tool(state):
52
  tool_calls = state['messages'][-1].additional_kwargs.get("tool_calls", [])
53
  for tool_call in tool_calls:
54
  if tool_call["function"]["name"] == "multiply":
 
55
  arguments = json.loads(tool_call["function"]["arguments"])
56
  result = multiply.invoke(arguments)
57
- return {"messages": [ToolMessage(content=str(result))]}
 
58
  return {"messages": [ToolMessage(content="No valid tool input provided.")]}
59
 
 
60
  graph.add_node("tool", invoke_tool)
61
 
62
  # Router Node: Manual Addition
 
52
  tool_calls = state['messages'][-1].additional_kwargs.get("tool_calls", [])
53
  for tool_call in tool_calls:
54
  if tool_call["function"]["name"] == "multiply":
55
+ # Extract and parse the arguments
56
  arguments = json.loads(tool_call["function"]["arguments"])
57
  result = multiply.invoke(arguments)
58
+ # Return the tool result while maintaining tool_call_id for future use
59
+ return {"messages": [ToolMessage(content=str(result), name="multiply", tool_call_id=tool_call["id"])]}
60
  return {"messages": [ToolMessage(content="No valid tool input provided.")]}
61
 
62
+
63
  graph.add_node("tool", invoke_tool)
64
 
65
  # Router Node: Manual Addition