Why Native Tool Use?
Architecture
ToolAwareClient Interface
TheToolAwareClient interface extends the base LLMClient with tool support:
Automatic Detection
Detection is done via type assertion, with no configuration required:Providers that do not implement
ToolAwareClient continue to work normally via SendPrompt.Provider Tool Use Support
Not all providers implement native tool use. Features like/coder mode and multi-agent orchestration work best with providers that support SendPromptWithTools:
Data Types
ToolDefinition
ToolDefinition
Defines a tool available to the model:
ToolCall and ToolResult
ToolCall and ToolResult
Represent a tool call by the model and its result:The
IsError field (aligned with Anthropic’s Messages API) is emitted natively as is_error: true in Claude’s tool_result block. For OpenAI-compatible providers (OpenAI, Moonshot, MiniMax, ZAI, OpenRouter), the models.Message also carries ErrorCode (ENOENT, Timeout, ExitCode:N, InvalidArgs, …) and the adapter prepends content with [ERROR:<code>] — the model gets the signal even without a native error field.LLMResponse
LLMResponse
Unified response that can contain text and/or tool calls:
Provider Implementations
- OpenAI
- Anthropic (Claude)
Uses the
tools field in the Chat Completions API:- Sends tools as a
toolsarray withtool_choice: "auto" - Processes
tool_callsinchoices[0].message toolmessages in the history link results to thetool_call_id
Tool result with is_error / ErrorCode (provider-agnostic)
Tool results carry two orthogonal signals that travel to the model:IsError bool— true when the tool executed but reported a business-level failure (non-zero exit, HTTP 4xx, file not found, invalid args schema). False = success.ErrorCode string— locale-independent classification:ENOENT,EACCES,EISDIR,EEXIST,Timeout,Canceled,ExitCode:N,NetworkError,DNSError,InvalidArgs, etc. Empty whenIsError=false.
The model pattern-matches on
[ERROR:<code>] to decide retry/recovery without parsing English — InvalidArgs means “fix the schema”, Timeout means “try again”, ENOENT means “wrong file”.
ContentBlock with Cache Control
For Anthropic, the system prompt is split into blocks with cache control:Fallback Integration
The fallback chain (llm/fallback) supports SendPromptWithTools automatically. Providers without native tool use support are skipped in the tool call chain but remain available for plain text requests.