how to track tool exicutions
# ask-ai
b
how to track tool exicutions
t
Thanks for reaching out, Mohammed. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You’re asking how to track tool executions — here are the practical ways to do that in LiveKit Agents and what to pick depending on your needs. Event listeners (real-time, in-app) • Use the
function_tools_executed
event on
AgentSession
. It gives
function_calls
and
function_call_outputs
, and
zipped()
pairs each call with its output. • Python example:
Copy code
@session.on("function_tools_executed")
def on_tool_executed(event: FunctionToolsExecutedEvent):
    for call, output in event.zipped():
        print(f"Tool called: {call.name}, Args: {call.arguments}")
        print(f"Output: {output.output}, Error: {output.is_error}")
• Node.js example:
Copy code
session.on(voice.AgentSessionEventTypes.FunctionToolsExecuted, (event) => {
  for (const [call, output] of event.zipped()) {
    console.log(`Tool called: ${call.name}, Args: ${JSON.stringify(call.arguments)}`);
    console.log(`Output: ${output.output}, Error: ${output.isError}`);
  }
});
Session traces / Observability (post-hoc, visual analysis) • Enable Agent Observability in LiveKit Cloud to capture traces. Each tool call appears as a trace/span with timestamps, duration, and full request/response metadata, synchronized with audio/transcripts for troubleshooting. In-tool logging (debugging, persistent logs) • Add logging inside your tool implementations to capture input, outputs, and errors:
Copy code
@function_tool()
async def lookup_weather(location: str):
    <http://logger.info|logger.info>(f"Executing lookup_weather for {location}")
    return {"weather": "sunny"}
External systems / audit logs • If your tool calls external services (MCP, APIs, DBs), enable audit/logging there as well to get end-to-end visibility. Would you like help implementing the event listener in your codebase (Python or Node), or enabling/troubleshooting Agent Observability for your project? If so, tell me which environment you’re using and any sample code or errors. Sources: Events and error handling | LiveKit docs | https://blog.livekit.io/streamline-troubleshooting-with-agent-observability/#/portal/signup| | Tool definition and use | LiveKit docs