Find answers from the community

Updated 3 months ago

Shouldnt the ReActAgent fire a AgentToolCallEvent every time it uses one of its tools?

Shouldnt the ReActAgent fire a AgentToolCallEvent every time it uses one of its tools?
k
a
6 comments
Please stand by @ashepherd as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
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 ():

Plain Text
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:
----------------------
But I can not use Instrumentation EventType AgentToolCallEvent with ReActAgent?
@kapa.ai But I can not use Instrumentation EventType AgentToolCallEvent with ReActAgent?
Let me check the knowledge base for you. One moment! :books:
----------------------
The AgentToolCallEvent is a specific type of event in the LlamaIndex instrumentation system. It is used to represent the event of an agent calling a tool. However, the ReActAgent does not directly use this event type in its implementation. Instead, it uses the more general CBEventType.FUNCTION_CALL event type when a tool is called, as shown in the ReActAgent documentation ().

Here is the relevant code snippet:

Plain Text
with self.callback_manager.event(
    CBEventType.FUNCTION_CALL,
    payload={{
        EventPayload.FUNCTION_CALL: reasoning_step.action_input,
        EventPayload.TOOL: tool.metadata,
    }},
) as event:
    ...


In this code, CBEventType.FUNCTION_CALL is the event type, and the payload includes the function call and the tool metadata.

If you want to use the AgentToolCallEvent with the ReActAgent, you would need to modify the agent's implementation to include this event type. However, this would require a good understanding of the LlamaIndex architecture and the specific role of the AgentToolCallEvent in the system.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord