Creating and Logging 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"] }
});

try {
    const result = callExternalService(toolCall.function.name, toolCall.function.arguments);
    traceToolCall.result(result);
} catch (error) {
    traceToolCall.error(error);
}

Replace ‘trace.toolCall’ with ‘span.toolCall’ when you are creating tool calls within an existing span