mgbam commited on
Commit
d21b959
·
verified ·
1 Parent(s): 5158329

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +3 -7
agent.py CHANGED
@@ -357,7 +357,6 @@ def tool_node(state: AgentState) -> Dict[str, Any]:
357
  new_state = {"messages": []}
358
  return propagate_state(new_state, state)
359
  last = wrap_message(messages_list[-1])
360
- # Safely retrieve pending tool_calls from the message's __dict__
361
  tool_calls = last.__dict__.get("tool_calls")
362
  if not (isinstance(last, AIMessage) and tool_calls):
363
  logger.warning("tool_node invoked without pending tool_calls")
@@ -462,9 +461,9 @@ def should_continue(state: AgentState) -> str:
462
  if "consultation complete" in last.content.lower():
463
  state["done"] = True
464
  return "end_conversation_turn"
465
- state["done"] = False
466
- # Return "start" to loop back.
467
- return "start"
468
 
469
  def after_tools_router(state: AgentState) -> str:
470
  if state.get("interaction_warnings"):
@@ -480,17 +479,14 @@ class ClinicalAgent:
480
  wf.add_node("tools", tool_node)
481
  wf.add_node("reflection", reflection_node)
482
  wf.set_entry_point("start")
483
- # Note: Added a "start" branch in the conditional edges.
484
  wf.add_conditional_edges("start", should_continue, {
485
  "continue_tools": "tools",
486
- "start": "start",
487
  "end_conversation_turn": END
488
  })
489
  wf.add_conditional_edges("tools", after_tools_router, {
490
  "reflection": "reflection",
491
  "end_conversation_turn": END
492
  })
493
- # Removed edge from reflection back to start to break the cycle.
494
  self.graph_app = wf.compile()
495
  logger.info("ClinicalAgent ready")
496
 
 
357
  new_state = {"messages": []}
358
  return propagate_state(new_state, state)
359
  last = wrap_message(messages_list[-1])
 
360
  tool_calls = last.__dict__.get("tool_calls")
361
  if not (isinstance(last, AIMessage) and tool_calls):
362
  logger.warning("tool_node invoked without pending tool_calls")
 
461
  if "consultation complete" in last.content.lower():
462
  state["done"] = True
463
  return "end_conversation_turn"
464
+ # If no tool calls are present, terminate the conversation instead of looping.
465
+ state["done"] = True
466
+ return "end_conversation_turn"
467
 
468
  def after_tools_router(state: AgentState) -> str:
469
  if state.get("interaction_warnings"):
 
479
  wf.add_node("tools", tool_node)
480
  wf.add_node("reflection", reflection_node)
481
  wf.set_entry_point("start")
 
482
  wf.add_conditional_edges("start", should_continue, {
483
  "continue_tools": "tools",
 
484
  "end_conversation_turn": END
485
  })
486
  wf.add_conditional_edges("tools", after_tools_router, {
487
  "reflection": "reflection",
488
  "end_conversation_turn": END
489
  })
 
490
  self.graph_app = wf.compile()
491
  logger.info("ClinicalAgent ready")
492