Skip to content
Snippets Groups Projects
Unverified Commit 24ea187a authored by Ming's avatar Ming Committed by GitHub
Browse files

[Agent using tools] Upon exception, say so, so that Agent can correct itself. (#12137)

parent 8098b728
No related branches found
No related tags found
No related merge requests found
...@@ -240,7 +240,15 @@ class ReActAgentWorker(BaseAgentWorker): ...@@ -240,7 +240,15 @@ class ReActAgentWorker(BaseAgentWorker):
EventPayload.TOOL: tool.metadata, EventPayload.TOOL: tool.metadata,
}, },
) as event: ) as event:
tool_output = tool.call(**reasoning_step.action_input) try:
tool_output = tool.call(**reasoning_step.action_input)
except Exception as e:
tool_output = ToolOutput(
content=f"Error: {e!s}",
tool_name=tool.metadata.name,
raw_input={"kwargs": reasoning_step.action_input},
raw_output=e,
)
event.on_end(payload={EventPayload.FUNCTION_OUTPUT: str(tool_output)}) event.on_end(payload={EventPayload.FUNCTION_OUTPUT: str(tool_output)})
task.extra_state["sources"].append(tool_output) task.extra_state["sources"].append(tool_output)
...@@ -276,7 +284,15 @@ class ReActAgentWorker(BaseAgentWorker): ...@@ -276,7 +284,15 @@ class ReActAgentWorker(BaseAgentWorker):
EventPayload.TOOL: tool.metadata, EventPayload.TOOL: tool.metadata,
}, },
) as event: ) as event:
tool_output = await tool.acall(**reasoning_step.action_input) try:
tool_output = await tool.acall(**reasoning_step.action_input)
except Exception as e:
tool_output = ToolOutput(
content=f"Error: {e!s}",
tool_name=tool.metadata.name,
raw_input={"kwargs": reasoning_step.action_input},
raw_output=e,
)
event.on_end(payload={EventPayload.FUNCTION_OUTPUT: str(tool_output)}) event.on_end(payload={EventPayload.FUNCTION_OUTPUT: str(tool_output)})
task.extra_state["sources"].append(tool_output) task.extra_state["sources"].append(tool_output)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment