summaryrefslogtreecommitdiff
path: root/internal/config/config.go
diff options
context:
space:
mode:
authorClaude Sonnet 5 <noreply@anthropic.com>2026-07-03 09:03:01 +0000
committerClaude Sonnet 5 <noreply@anthropic.com>2026-07-03 09:03:13 +0000
commite38f673edc7428c0c836c39f40707cb681defb14 (patch)
tree97a704b2d83b9d572ae67d057315a6781ddf1470 /internal/config/config.go
parentbbd58e8d77f7c996add29b69f600e835a922542e (diff)
feat(provider): add native Anthropic Messages API adapter (Phase 2)
Adds internal/provider/anthropic, the first genuinely new provider.Provider implementation on top of Phase 1's provider-neutral tool-use loop, alongside (not replacing) the existing Docker/CLI-subprocess ContainerRunner path for the "claude" agent type: - internal/provider/anthropic: translates the neutral ChatRequest/ChatResponse shape to/from Anthropic's Messages API content-block format (system as a top-level field, tool_use/tool_result blocks, no "tool" role -- tool results become user-role messages), with a per-model-prefix pricing table for CostUSD - internal/retry: IsRateLimitError additively extended to recognize Anthropic's rate_limit_error/overloaded_error/529 shapes - internal/config: RunnersConfig.Anthropic/AnthropicEnabled() gate - internal/cli/serve.go, run.go: register runners["anthropic"] as a NativeRunner when [providers.anthropic].api_key is set and enabled -- tracked as a distinct executions.agent="anthropic" budget bucket, separate from the CLI-subprocess "claude" runner even though both bill the same Anthropic account go build/vet/test -race all pass. No live Anthropic API key is available in this environment, so verification is via fake-httptest-server adapter tests (12 cases, incl. multi-turn tool_result round-trip and rate-limit error matching) plus a Pool/NativeRunner routing test proving agent.type: "anthropic" actually reaches the new provider. Live end-to-end verification against the real API is a follow-up once a key is configured. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V1moSNCJRcP6kykA4tyUSs
Diffstat (limited to 'internal/config/config.go')
-rw-r--r--internal/config/config.go33
1 files changed, 22 insertions, 11 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index 640e933..de087d6 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -25,12 +25,12 @@ type Project struct {
// uses this client. It defaults to true when Endpoint is set; users with a
// slow or low-quality local model can disable it.
type LocalModel struct {
- Endpoint string `toml:"endpoint"` // e.g. "http://localhost:11434/v1"
- Model string `toml:"model"` // e.g. "llama3.1:8b"
- TimeoutSeconds int `toml:"timeout_seconds"` // default 60
- DefaultTemperature float64 `toml:"default_temperature"` // default 0.2
- APIKey string `toml:"api_key"` // optional bearer token
- PreferForElaborate *bool `toml:"prefer_for_elaborate"` // pointer so default-true survives parse
+ Endpoint string `toml:"endpoint"` // e.g. "http://localhost:11434/v1"
+ Model string `toml:"model"` // e.g. "llama3.1:8b"
+ TimeoutSeconds int `toml:"timeout_seconds"` // default 60
+ DefaultTemperature float64 `toml:"default_temperature"` // default 0.2
+ APIKey string `toml:"api_key"` // optional bearer token
+ PreferForElaborate *bool `toml:"prefer_for_elaborate"` // pointer so default-true survives parse
}
// UseForElaborate returns true when elaboration should try this local model
@@ -56,20 +56,31 @@ type RunnersConfig struct {
Gemini *bool `toml:"gemini"`
Local *bool `toml:"local"`
Container *bool `toml:"container"`
+ // Anthropic gates the native provider.Provider-backed NativeRunner
+ // registered under agent type "anthropic" (internal/provider/anthropic).
+ // It is distinct from Claude, which gates the Docker/CLI-subprocess
+ // ContainerRunner for agent type "claude" — the two are separate
+ // execution paths (and separate budget buckets) even though both bill
+ // the same Anthropic account. Also requires [providers.anthropic].api_key
+ // to be set; Anthropic = true with no configured key has no effect.
+ Anthropic *bool `toml:"anthropic"`
}
func (r RunnersConfig) ClaudeEnabled() bool { return r.Claude == nil || *r.Claude }
func (r RunnersConfig) GeminiEnabled() bool { return r.Gemini == nil || *r.Gemini }
func (r RunnersConfig) LocalEnabled() bool { return r.Local == nil || *r.Local }
func (r RunnersConfig) ContainerEnabled() bool { return r.Container == nil || *r.Container }
+func (r RunnersConfig) AnthropicEnabled() bool { return r.Anthropic == nil || *r.Anthropic }
// ProviderConfig configures a native (or OpenAI-compatible) LLM provider
// backend for the multi-provider harness — see docs/api-keys-setup.md. Phase
-// 1 only adds this type so config has somewhere for it to land; it is not yet
-// read by runner construction (no native provider adapters exist yet besides
-// the openaicompat one LocalModel already configures). Keyed by provider name
-// in the [providers.<name>] TOML table, e.g. [providers.groq],
-// [providers.anthropic].
+// 1 added this type so config had somewhere for it to land, without being
+// read by runner construction. Phase 2 is the first consumer:
+// [providers.anthropic] (APIKey + optional Endpoint/DefaultModel/
+// TimeoutSeconds) wires internal/provider/anthropic.New into a NativeRunner
+// registered under agent type "anthropic" — see internal/cli/serve.go and
+// internal/cli/run.go. Keyed by provider name in the [providers.<name>] TOML
+// table, e.g. [providers.groq], [providers.anthropic].
type ProviderConfig struct {
Endpoint string `toml:"endpoint"`
APIKey string `toml:"api_key"`