Find answers from the community

Updated 3 weeks ago

Getting tracebacks and detail logs on tool execution errors for an agent

Is there any way to get tracebacks/detail logs on tool execution errors for an agent?


Plain Text
async def acall_tool(tool: BaseTool, arguments: dict) -> ToolOutput:
    """Call a tool with arguments asynchronously."""
    async_tool = adapt_to_async_tool(tool)
    try:
        if (
            len(tool.metadata.get_parameters_dict()["properties"]) == 1
            and len(arguments) == 1
        ):
            try:
                single_arg = arguments[next(iter(arguments))]
                return await async_tool.acall(single_arg)
            except Exception:
                # some tools will REQUIRE kwargs, so try it
                return await async_tool.acall(**arguments)
        else:
            return await async_tool.acall(**arguments)
    except Exception as e:
        return ToolOutput(
            content="Encountered error: " + str(e),
            tool_name=tool.metadata.name,
            raw_input=arguments,
            raw_output=str(e),
            is_error=True,
        )


Not raising might be handy when the agent can recover using the Exceptions as a mechanism to inform the LLM, but when real bugs strike, in more complex tools, this is super hard to debug.
I always end up monkeypatching to raise.
Add a reply
Sign up and join the conversation on Discord