// 1. First call — model returns tool calls
const result = await tracia.prompts.run('assistant', { question: 'Weather in Tokyo?' });
if (result.finishReason === 'tool_calls' && result.toolCalls) {
// 2. Execute tools locally
const weatherData = await getWeather(result.toolCalls[0].arguments.location);
// 3. Continue with tool results
const result2 = await tracia.prompts.run('assistant', undefined, {
messages: [
...result.messages!,
{ role: 'tool', toolCallId: result.toolCalls[0].id, toolName: 'get_weather', content: JSON.stringify(weatherData) }
],
traceId: result.traceId,
parentSpanId: result.spanId,
});
console.log(result2.text);
// "The weather in Tokyo is 22°C and sunny."
}