Maxim Logo
How toLog your application

Track tool calls

Track external system calls triggered by LLM responses in your agentic workflows. Tool calls represent interactions with external services, allowing you to monitor execution time and responses.

How to log tool calls

const toolCall = completion.choices[0].message.tool_calls[0];
const traceToolCall = trace.toolCall({
    id: toolCall.id,
    name: toolCall.function.name,
    description: "Get current temperature for a given location.",
    args: toolCall.function.arguments,
    tags: { location: toolCall.function.arguments["location"] }
});
// Note: Replace 'trace.toolCall' with 'span.toolCall' when you are creating tool calls within an existing span
 
try {
    const result = callExternalService(toolCall.function.name, toolCall.function.arguments);
    traceToolCall.result(result);
} catch (error) {
    traceToolCall.error(error);
}

On this page