wt002 commited on
Commit
93451f1
·
verified ·
1 Parent(s): 8a9ad42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -408,16 +408,8 @@ def reasoning_node(state: AgentState) -> AgentState:
408
 
409
 
410
  def tool_node(state: AgentState) -> AgentState:
411
- """
412
- Node for executing the chosen tool and returning its output.
413
- """
414
- print(f"DEBUG: Entering tool_node. Iteration: {state['iterations']}")
415
-
416
- # Ensure history exists
417
- if "history" not in state or not isinstance(state["history"], list):
418
- raise ValueError("Invalid or missing history in state")
419
 
420
- # Find the most recent action request in history
421
  tool_call_dict = None
422
  for msg in reversed(state["history"]):
423
  if isinstance(msg, dict) and msg.get("type") == "action_request":
@@ -425,16 +417,22 @@ def tool_node(state: AgentState) -> AgentState:
425
  break
426
 
427
  if not tool_call_dict:
428
- # This shouldn't happen if should_continue logic is correct, but for robustness
429
  print("WARNING: No action_request found in history, skipping tool execution.")
430
- return state
431
 
432
  tool_name = tool_call_dict.get("tool")
433
  tool_input = tool_call_dict.get("input")
434
 
435
- # Defensive check for missing tool or input
436
- if not tool_name or tool_input is None:
437
- raise ValueError(f"Tool name '{tool_name}' or input '{tool_input}' missing from action request: {tool_call_dict}")
 
 
 
 
 
 
 
438
 
439
  # Look up and invoke the tool from the state's tool list
440
  available_tools = state.get("tools", [])
 
408
 
409
 
410
  def tool_node(state: AgentState) -> AgentState:
411
+ # ... (previous code)
 
 
 
 
 
 
 
412
 
 
413
  tool_call_dict = None
414
  for msg in reversed(state["history"]):
415
  if isinstance(msg, dict) and msg.get("type") == "action_request":
 
417
  break
418
 
419
  if not tool_call_dict:
 
420
  print("WARNING: No action_request found in history, skipping tool execution.")
421
+ return state # Or raise a more specific error if this truly shouldn't happen
422
 
423
  tool_name = tool_call_dict.get("tool")
424
  tool_input = tool_call_dict.get("input")
425
 
426
+ # --- ADD THIS DEBUG PRINT ---
427
+ print(f"DEBUG: tool_node received action_request: tool='{tool_name}', input='{tool_input[:100]}...'")
428
+ # --- END DEBUG PRINT ---
429
+
430
+ if not tool_name or tool_input is None: # tool_input can be empty string for some tools, but not None
431
+ print(f"ERROR: Invalid tool call in action_request. Tool name: '{tool_name}', Input: '{tool_input}'")
432
+ # Instead of raising directly, you might want to send this back to reasoning
433
+ # Or provide a specific error message as tool output
434
+ state["history"].append(AIMessage(content=f"[Tool Error] Invalid tool call: Tool name '{tool_name}' or input was empty. LLM needs to provide valid action."))
435
+ return state
436
 
437
  # Look up and invoke the tool from the state's tool list
438
  available_tools = state.get("tools", [])