Documentation
¶
Overview ¶
Package provider defines the model-neutral message types and the streaming interface every model backend implements. The agent loop only ever sees these types; the Anthropic and OpenAI wire dialects stay inside their own files and translate at the edge.
Index ¶
Constants ¶
const ( StopEndTurn = "end_turn" StopToolUse = "tool_use" StopMaxTokens = "max_tokens" )
Stop reasons, normalized across dialects.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Anthropic ¶
type Anthropic struct {
APIKey string
BaseURL string // default https://api.anthropic.com
Client *http.Client
}
Anthropic speaks the Messages API with SSE streaming.
type Block ¶
type Block struct {
Type BlockType `json:"type"`
// BlockText.
Text string `json:"text,omitempty"`
// BlockImage: base64 payload plus its MIME type.
MediaType string `json:"media_type,omitempty"`
Data string `json:"data,omitempty"`
// BlockToolUse.
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Input json.RawMessage `json:"input,omitempty"`
// BlockToolResult.
ToolID string `json:"tool_id,omitempty"`
Content string `json:"content,omitempty"`
IsError bool `json:"is_error,omitempty"`
}
Block is one piece of message content, a tagged union: Type says which fields mean anything. A plain struct beats an interface here because blocks round-trip through JSON for the session ledger.
type BlockType ¶
type BlockType string
BlockType enumerates the kinds of content a message can carry.
type OpenAI ¶
type OpenAI struct {
APIKey string
BaseURL string // e.g. https://api.openai.com/v1 or http://gamingpc:8000/v1
Client *http.Client
}
OpenAI speaks the chat completions dialect, which is the lingua franca of local and hosted inference alike: llama.cpp, ollama, vllm, and most gateways all serve it. BaseURL points at the /v1 root.
type Provider ¶
type Provider interface {
Stream(ctx context.Context, req Request, emit func(Event)) (*Response, error)
}
Provider streams one model response. emit may be nil when the caller does not care about deltas; Stream always returns the complete response.
type Role ¶
type Role string
Role is who a message is from. Tool results ride on user messages, the way both wire dialects expect.
type Tool ¶
type Tool struct {
Name string
Description string
Schema json.RawMessage
}
Tool describes a callable tool the way the model sees it. Schema is a JSON schema for the input object.
type Usage ¶
type Usage struct {
InputTokens int `json:"input_tokens"`
CachedInputTokens int `json:"cached_input_tokens,omitempty"`
CacheWriteInputTokens int `json:"cache_write_input_tokens,omitempty"`
OutputTokens int `json:"output_tokens"`
ReasoningTokens int `json:"reasoning_tokens,omitempty"`
TotalTokens int `json:"total_tokens"`
}
Usage preserves the provider's complete token accounting for one call. InputTokens is the whole prompt, including cache reads and writes. The cache fields are subsets of InputTokens. ReasoningTokens is a subset of OutputTokens. TotalTokens is the provider-reported total when available and otherwise InputTokens plus OutputTokens.