Tool Calls
Last updated
How to declare tools and return tool results across every provider.
Declaring tools
Tool definitions use the OpenAI shape, with Parameters as json.RawMessage so a JSON Schema goes in verbatim:
tools := []llmrouter.Tool{{
Type: "function",
Function: llmrouter.ToolFunction{
Name: "get_weather",
Description: "Get the current weather for a city",
Parameters: json.RawMessage(`{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}`),
},
}}
Returning results
Results come back as Role: "tool" plus ToolCallID. Gemini additionally attaches ToolCall.ThoughtSignature, which must be echoed back verbatim or the next turn is rejected.
Related
- Message Types:
Tool,ToolCall,ToolCallFunctionfields - Streaming: tool calls arriving as
tool_callevents