Documentation
¶
Overview ¶
Package provider abstracts model backends behind Anthropic Messages semantics. A provider instance is constructed purely from configuration (protocol / model / base_url / api_key — CLAUDE.md principle 4): the anthropic protocol adapter works against ANY endpoint speaking Anthropic Messages — a gateway, a proxy, or a self-hosted model — never just api.anthropic.com. The registry resolves an agent's model string to a configured provider.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chunk ¶
type Chunk struct {
Kind ChunkKind
Index int64 // content block index (text/thinking deltas)
Text string // text/thinking fragment
ToolUse *ToolUse // KindToolUse only
StopReason string // KindDone only: end_turn | tool_use | max_tokens | …
Usage *domain.ModelUsage // KindDone only
}
Chunk is one streaming increment.
type ChunkKind ¶
type ChunkKind string
ChunkKind discriminates streaming increments of a turn.
const ( // KindTextDelta appends text to the content block at Index. KindTextDelta ChunkKind = "text_delta" // KindThinkingDelta appends thinking text to the block at Index. KindThinkingDelta ChunkKind = "thinking_delta" // KindToolUse is one complete tool invocation (input fully accumulated). KindToolUse ChunkKind = "tool_use" // KindDone closes the turn with stop reason and usage. KindDone ChunkKind = "done" )
type Config ¶
type Config struct {
Protocol string // "anthropic" | "openai"
Model string // model id sent to the upstream endpoint
BaseURL string // endpoint base URL; required (no implicit default host)
APIKey string // credential for the endpoint
Headers map[string]string // optional extra headers (gateway routing etc.)
}
Config constructs one provider instance.
type Message ¶
type Message struct {
Role string // "user" | "assistant"
Content json.RawMessage // Anthropic content: a string or an array of blocks
}
Message is one conversational turn.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry resolves agent model strings to constructed providers. Routing is exact-match with an optional "*" default, so an enterprise maps its model names onto endpoints purely in configuration. Constructed providers are cached per model string — one client per backend, not one per turn.
func NewRegistry ¶
type Request ¶
type Request struct {
System string
Messages []Message
Tools []json.RawMessage // Anthropic tool definitions, verbatim
MaxTokens int64
}
Request is one model turn in Anthropic Messages semantics. Content and tool definitions stay as raw Anthropic wire JSON so the anthropic-protocol adapter is near-zero-conversion; lossy mappings are confined to the non-Anthropic adapters (see provider/openai).
type Route ¶
Route binds an agent-facing model string to a provider config. Model "*" is the default route.
func LoadRoutes ¶
LoadRoutes reads a model_providers JSON file into registry routes. Structural validation happens here (unknown keys are config typos, not extensions); route-level validation stays in NewRegistry.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package anthropic adapts any endpoint speaking the Anthropic Messages protocol to the provider interface, via the official SDK with a configurable base URL — an enterprise gateway, a proxy, or a self-hosted model are all just configuration.
|
Package anthropic adapts any endpoint speaking the Anthropic Messages protocol to the provider interface, via the official SDK with a configurable base URL — an enterprise gateway, a proxy, or a self-hosted model are all just configuration. |
|
Package openai adapts an OpenAI Chat Completions endpoint (OpenAI itself, a vLLM server, or an internal OpenAI-compatible gateway) to the provider interface.
|
Package openai adapts an OpenAI Chat Completions endpoint (OpenAI itself, a vLLM server, or an internal OpenAI-compatible gateway) to the provider interface. |