feat(ciayn_agent.py): add fallback_fixed_msg to inform users about fallback tool handling

fix(ciayn_agent.py): ensure error message is logged in chat history when fallback response is empty
This commit is contained in:
Ariel Frischer 2025-02-14 13:54:06 -08:00
parent f3a5ce6d8e
commit 27400d6225
1 changed files with 5 additions and 1 deletions

View File

@ -112,6 +112,9 @@ class CiaynAgent:
"Execute efficiently yet completely as a fully autonomous agent." "Execute efficiently yet completely as a fully autonomous agent."
) )
self.error_message_template = "Your tool call caused an error: {e}\n\nPlease correct your tool call and try again." self.error_message_template = "Your tool call caused an error: {e}\n\nPlease correct your tool call and try again."
self.fallback_fixed_msg = HumanMessage(
"Fallback tool handler has fixed the tool call see: <fallback tool call result> for the output."
)
def _build_prompt(self, last_result: Optional[str] = None) -> str: def _build_prompt(self, last_result: Optional[str] = None) -> str:
"""Build the prompt for the agent including available tools and context.""" """Build the prompt for the agent including available tools and context."""
@ -166,11 +169,12 @@ class CiaynAgent:
self, fallback_response: list[Any], e: ToolExecutionError self, fallback_response: list[Any], e: ToolExecutionError
) -> str: ) -> str:
err_msg = HumanMessage(content=self.error_message_template.format(e=e)) err_msg = HumanMessage(content=self.error_message_template.format(e=e))
self.chat_history.append(err_msg)
if not fallback_response: if not fallback_response:
self.chat_history.append(err_msg)
return "" return ""
self.chat_history.append(self.fallback_fixed_msg)
msg = f"Fallback tool handler has triggered after consecutive failed tool calls reached {DEFAULT_MAX_TOOL_FAILURES} failures.\n" msg = f"Fallback tool handler has triggered after consecutive failed tool calls reached {DEFAULT_MAX_TOOL_FAILURES} failures.\n"
# Passing the fallback raw invocation may confuse our llm, as invocation methods may differ. # Passing the fallback raw invocation may confuse our llm, as invocation methods may differ.
# msg += f"<fallback llm raw invocation>{fallback_response[0]}</fallback llm raw invocation>\n" # msg += f"<fallback llm raw invocation>{fallback_response[0]}</fallback llm raw invocation>\n"