----------------------
Yes, the
ReActAgent
does indeed trigger an event every time it uses one of its tools. This is done using the
callback_manager.event
method. The event type is
CBEventType.FUNCTION_CALL
, and the payload includes the function call and the tool metadata. This event is triggered within a context manager, and the tool is called within this context. If the tool call is successful, the output is stored. If an exception occurs during the tool call, an error message is stored instead. At the end of the context, the
event.on_end
method is called with the tool output.
Here is the relevant code snippet from the
ReActAgent documentation ():
with self.callback_manager.event(
CBEventType.FUNCTION_CALL,
payload={
EventPayload.FUNCTION_CALL: reasoning_step.action_input,
EventPayload.TOOL: tool.metadata,
},
) as event:
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,
is_error=True,
)
event.on_end(
payload={EventPayload.FUNCTION_OUTPUT: str(tool_output)}
)
This event handling allows for tracking and handling of tool calls within the
ReActAgent
.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------