Skip to documentation
Documentation navigation

Documentation navigation

Documentation / guides

Tool translation

Translate tool definitions, calls, arguments, and results without losing JSON shape.

developer

Tools are provider-neutral inference.Tool values with a name, description, and JSON object schema. Each dialect wraps that definition differently and normalizes a tool call back to content.ToolUseBlock.

Definitions

type Tool struct {
	Name        string
	Description string
	Schema      json.RawMessage
}

OpenAI uses one {type:"function", function:{...}} entry per tool. Responses uses a function item with parameters. Anthropic uses input_schema. Gemini groups functionDeclarations inside one tool. Bedrock nests each definition under toolSpec.inputSchema.json. Empty schemas become {"type":"object"} only in dialects whose encoder documents that fallback.

Calls and results

OpenAI Chat and Responses carry function arguments as a JSON-encoded string on the wire; their decoders expose raw JSON in ToolUseBlock.Input. Anthropic and Bedrock carry a JSON object. OpenAI and Responses flatten result blocks to text, so non-text results fail closed. Anthropic preserves IsError; Bedrock maps it to status: "error"; OpenAI and Responses have no corresponding wire field and intentionally omit the flag.

message := &content.AIMessage{Message: content.Message{Blocks: []content.Block{
	&content.ToolUseBlock{ID: "call-1", Name: "lookup", Input: json.RawMessage(`{"q":"go"}`)},
}}}
_ = message // replay this block in the next Request to preserve the call.

Source and proof

Run go test ./codec/openaiapi ./codec/openairesponses ./codec/anthropicapi ./codec/geminiapi ./codec/bedrockconverse.

← back to documentation