Scott Cogan
commited on
Commit
·
348f005
1
Parent(s):
def383b
requirements update for llm compat
Browse files
app.py
CHANGED
|
@@ -462,9 +462,8 @@ class BasicAgent:
|
|
| 462 |
logger.info("\n=== Tool Execution ===")
|
| 463 |
if isinstance(last_message, AIMessage):
|
| 464 |
# Extract tool calls from the message
|
| 465 |
-
tool_calls
|
| 466 |
-
|
| 467 |
-
for tool_call in tool_calls:
|
| 468 |
try:
|
| 469 |
tool_name = tool_call.name
|
| 470 |
tool_args = tool_call.args
|
|
@@ -479,11 +478,25 @@ class BasicAgent:
|
|
| 479 |
logger.error(f"Error executing tool {tool_name}: {str(e)}")
|
| 480 |
messages.append(AIMessage(content=f"Tool error: {str(e)}"))
|
| 481 |
else:
|
| 482 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 483 |
|
| 484 |
return {"messages": messages, "next": "agent"}
|
| 485 |
except Exception as e:
|
| 486 |
logger.error(f"Error in call_tools: {str(e)}")
|
|
|
|
| 487 |
return {"messages": messages, "next": "agent"}
|
| 488 |
|
| 489 |
async def __call__(self, question: str, task_id: str) -> str:
|
|
|
|
| 462 |
logger.info("\n=== Tool Execution ===")
|
| 463 |
if isinstance(last_message, AIMessage):
|
| 464 |
# Extract tool calls from the message
|
| 465 |
+
if hasattr(last_message, 'tool_calls') and last_message.tool_calls:
|
| 466 |
+
for tool_call in last_message.tool_calls:
|
|
|
|
| 467 |
try:
|
| 468 |
tool_name = tool_call.name
|
| 469 |
tool_args = tool_call.args
|
|
|
|
| 478 |
logger.error(f"Error executing tool {tool_name}: {str(e)}")
|
| 479 |
messages.append(AIMessage(content=f"Tool error: {str(e)}"))
|
| 480 |
else:
|
| 481 |
+
# If no tool calls found, check if we need to prompt for a tool call
|
| 482 |
+
content = last_message.content.strip().lower()
|
| 483 |
+
if any(phrase in content for phrase in ["let me", "i'll", "i will", "sure", "okay", "alright"]):
|
| 484 |
+
logger.info("No tool calls found, prompting for search")
|
| 485 |
+
messages.append(AIMessage(content="Please use the google_search tool to find the information."))
|
| 486 |
+
messages.append(HumanMessage(content="Please search for the information using the google_search tool."))
|
| 487 |
+
else:
|
| 488 |
+
logger.info("No tool calls found in AI message")
|
| 489 |
+
# If the message looks like a final answer, return it
|
| 490 |
+
if content.isdigit() or (content.startswith('[') and content.endswith(']')):
|
| 491 |
+
return {"messages": [last_message], "next": END}
|
| 492 |
+
else:
|
| 493 |
+
# Otherwise, continue the conversation
|
| 494 |
+
return {"messages": messages, "next": "agent"}
|
| 495 |
|
| 496 |
return {"messages": messages, "next": "agent"}
|
| 497 |
except Exception as e:
|
| 498 |
logger.error(f"Error in call_tools: {str(e)}")
|
| 499 |
+
# If there's an error, try to continue the conversation
|
| 500 |
return {"messages": messages, "next": "agent"}
|
| 501 |
|
| 502 |
async def __call__(self, question: str, task_id: str) -> str:
|