Documentation
¶
Overview ¶
Package models is the adapter layer between core-agent's configuration and concrete LLM backends. The Provider interface keeps the rest of the codebase free of provider-specific imports so additional backends plug in behind the same contract.
Built-in providers:
- "gemini" / "vertex" — google.golang.org/adk/model/gemini
- "anthropic" — Claude via github.com/anthropics/anthropic-sdk-go
Each backend's package init() calls Register so importing the subpackage is enough to make the provider available.
Index ¶
- func AutoDetectProvider() string
- func Register(name string, c Constructor)
- func ResolveMCPSmallModel(p Provider, mcpSpecific, agenticGeneral string) string
- func ResolveSmallModel(p Provider, override string) string
- type AnthropicAPI
- type AnthropicVertex
- type Constructor
- type GeminiAPI
- type GeminiVertex
- type Provider
- type ProviderOptions
- type SmallModelDefaulter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutoDetectProvider ¶
func AutoDetectProvider() string
AutoDetectProvider walks the env to pick a default backend. Exported alias of autoDetectProvider for callers that need the provider name BEFORE constructing a Provider (e.g. cmd/core-agent's --task flag resolution needs the provider name to pick a model for a given tier without paying for full provider construction).
Returns "" when no env-based default is detectable. Returns the same canonical name strings as Resolve would route to.
func Register ¶
func Register(name string, c Constructor)
Register installs a Constructor under its provider name. Idiomatically called from package init() in each backend implementation.
func ResolveMCPSmallModel ¶
ResolveMCPSmallModel is ResolveSmallModel's MCP-wrap sibling — layers a per-surface override (mcp.json's agentic_wrap_model or --mcp-agentic-wrap-model) in front of the general chain so operators can pick a different tier for MCP responses than for built-in-tool wrappers. Rationale: MCP responses can be shaped differently enough (structured GKE tables vs. arbitrary fetch_url bodies) that one tier works well for one surface but not the other.
Precedence: mcpSpecific → agenticGeneral → provider default → "".
func ResolveSmallModel ¶
ResolveSmallModel picks the model ID that agentic subtasks should run on. Operator override (a non-empty explicit --agentic-small-model value) always wins. Otherwise: if p implements SmallModelDefaulter, return whatever it reports; if not, return "" — agentic wrappers treat empty as "inherit the parent's model."
Types ¶
type AnthropicAPI ¶
type AnthropicAPI struct {
// APIKey overrides ANTHROPIC_API_KEY. Empty falls back to the
// environment, same as the config path.
APIKey string
}
AnthropicAPI selects the Anthropic API backend (api-key auth).
type AnthropicVertex ¶
type AnthropicVertex struct {
// Project and Region identify the Model Garden deployment. Empty
// values fall back to the same env chain as the config path:
// ANTHROPIC_VERTEX_PROJECT_ID then GOOGLE_CLOUD_PROJECT for the
// project; CLOUD_ML_REGION then GOOGLE_CLOUD_LOCATION then the
// "us-east5" default for the region.
Project string
Region string
}
AnthropicVertex selects Anthropic models served through Vertex AI Model Garden (ADC auth).
type Constructor ¶
Constructor builds a Provider from validated config. Tests register alternates via Register so resolution stays decoupled from the imports of any single backend.
type GeminiAPI ¶
type GeminiAPI struct {
// APIKey overrides GOOGLE_API_KEY / GEMINI_API_KEY. Empty falls
// back to the environment, same as the config path.
APIKey string
}
GeminiAPI selects the Gemini API backend (api-key auth). The model ID is NOT part of routing — pass it to Provider.Model(ctx, name) afterwards, exactly as with Resolve.
type GeminiVertex ¶
type GeminiVertex struct {
// Project and Location identify the Vertex deployment. Empty
// values fall back to GOOGLE_CLOUD_PROJECT / GOOGLE_CLOUD_LOCATION,
// same as the config path.
Project string
Location string
}
GeminiVertex selects Gemini via Vertex AI (ADC auth).
type Provider ¶
type Provider interface {
// Name reports the provider identity ("gemini", "vertex", "anthropic").
// Used for telemetry and diagnostic messages.
Name() string
// Model returns a usable model.LLM for the given model ID. The same
// Provider may be asked for several models over its lifetime.
Model(ctx context.Context, modelID string) (model.LLM, error)
}
Provider constructs concrete model.LLM instances on demand. A Provider is bound to one credential source (API key, Vertex project, etc.) at construction time; callers ask for specific models by ID through Model.
func New ¶
func New(opts ProviderOptions) (Provider, error)
New constructs a Provider from per-provider options, routing through the same registry as Resolve — remember to blank-import the backend package (e.g. pkg/models/gemini) exactly as with Resolve. For auto-detection from the environment, use Resolve with a default config (or AutoDetectProvider for the name alone); New is deliberately explicit about the backend.
type ProviderOptions ¶
type ProviderOptions interface {
// contains filtered or unexported methods
}
ProviderOptions is the programmatic counterpart of the config file's `model` block (#492): before it, the only way through the provider registry — Resolve — was to fabricate the on-disk *config.Config struct, which coupled every programmatic embedder to the file schema. Each per-provider struct below carries exactly the fields its backend routes on; New translates it through the same registry Resolve uses, so both paths construct identical providers. The MODEL ID is deliberately not routing state: pass it to Provider.Model(ctx, name) on the returned provider, exactly as with Resolve.
Sealed (the toModelConfig method is unexported) so the set of option shapes evolves with the registry rather than by third-party implementation. Backends with richer knobs (thinking budgets, server-side tools, cache flags) keep exposing them on their own constructors and functional options — gemini.NewAPIKey / gemini.NewVertex / anthropic.New / anthropic.NewVertex remain the full-control path; these structs cover the routing layer's job: pick a backend and point it at credentials. Pass structs by value (a nil *GeminiAPI etc. would panic in the value-receiver call).
Resolve remains the config-file adapter, unchanged.
type SmallModelDefaulter ¶
type SmallModelDefaulter interface {
DefaultSmallModel() string
}
SmallModelDefaulter is an optional Provider extension. A Provider that implements this declares its preferred cheap-tier model — used by core-agent as the default for --agentic-small-model when the operator hasn't pinned one explicitly. Providers without a cheap-tier concept (echo, scripted) simply don't implement this; ResolveSmallModel returns "" for them and callers fall back to inheriting the parent's model.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package anthropic implements models.Provider for Anthropic / Claude.
|
Package anthropic implements models.Provider for Anthropic / Claude. |
|
Package gemini implements models.Provider for the Gemini family, covering both the public Gemini API (API-key auth) and Vertex AI (Application Default Credentials + GCP project).
|
Package gemini implements models.Provider for the Gemini family, covering both the public Gemini API (API-key auth) and Vertex AI (Application Default Credentials + GCP project). |
|
Package mock ships two credential-free LLM providers and a recording wrapper that pair for offline testing of agent flows:
|
Package mock ships two credential-free LLM providers and a recording wrapper that pair for offline testing of agent flows: |