Documentation
¶
Overview ¶
Package einoproviders provides shared CloudWeGo Eino provider construction for agentic applications, including the opt-in OpenCode Go backend.
The root package defines the single-shot Provider contract, common Options, usage extraction, error classification, and a registry-backed NewProvider factory.
Backend packages register themselves from init. Import only the backends a program needs, usually for side effects:
import ( einoproviders "github.com/mattsp1290/eino-providers" _ "github.com/mattsp1290/eino-providers/claude" _ "github.com/mattsp1290/eino-providers/opencodego" )
The root package intentionally does not import backend subpackages. This keeps backend SDKs, Codex OAuth, and OpenCode Go authentication dependencies opt-in.
RegisterProvider is public so backend packages can self-register and tests can install local constructors. Direct third-party registration should be treated as experimental until the registry API is stabilized in a later minor release.
Index ¶
- Constants
- Variables
- func NewAgenticLimitedHTTPClient(source *http.Client, limits AgenticLimits) (*http.Client, error)
- func NewBoundedAgenticModel(delegate model.AgenticModel, limits AgenticLimits) (model.AgenticModel, error)
- func NewIdentifiedAgenticModel(delegate model.AgenticModel, identity AgenticResponseIdentity) model.AgenticModel
- func RegisterProvider(name string, ctor ProviderCtor)
- func RestoreAgenticContinuationForProvider(public *schema.AgenticMessage, state AgenticContinuationState, ...) (*schema.AgenticMessage, error)
- func ValidateAgenticContentBlocks(messages []*schema.AgenticMessage, limits AgenticLimits) error
- func WrapAuthError(err error) error
- func WrapInitError(err error) error
- type AgenticContinuationState
- type AgenticLimits
- type AgenticResponseIdentity
- type AgenticResponseMetadata
- type Capability
- type ErrorClass
- type Options
- type Provider
- type ProviderCtor
- type ResourceLimitError
- type UnsupportedCapabilityError
- type Usage
Constants ¶
const ( DefaultAgenticMaxRequestBytes int64 = 16 << 20 DefaultAgenticMaxEventBytes int64 = 2 << 20 DefaultAgenticMaxResponseBytes int64 = 32 << 20 DefaultAgenticMaxInlineMediaBytes int64 = 8 << 20 DefaultAgenticMaxContentBlocks = 1024 DefaultAgenticMaxErrorBodyBytes int64 = 1 << 20 DefaultAgenticMaxFixtureCaptureBytes int64 = 32 << 20 HardAgenticMaxRequestBytes int64 = 64 << 20 HardAgenticMaxEventBytes int64 = 8 << 20 HardAgenticMaxResponseBytes int64 = 128 << 20 HardAgenticMaxInlineMediaBytes int64 = 32 << 20 HardAgenticMaxContentBlocks = 4096 HardAgenticMaxErrorBodyBytes int64 = 4 << 20 HardAgenticMaxFixtureCaptureBytes int64 = 64 << 20 )
Variables ¶
var ( ErrProviderInit = errors.New("provider init error") ErrProviderTimeout = errors.New("provider timeout") ErrProviderAPI = errors.New("provider API error") ErrProviderAuth = errors.New("provider auth error") ErrUnknownProvider = errors.New("unknown provider") ErrBackendUnreachable = errors.New("backend unreachable") // ErrUnsupportedCapability reports an agentic input or option that the // selected native provider protocol cannot represent. It is always raised // before a request is dispatched. ErrUnsupportedCapability = errors.New("unsupported agentic capability") // ErrResourceLimit reports an agentic request or response that exceeded a // configured boundary. ErrResourceLimit = errors.New("agentic resource limit exceeded") )
Provider-error sentinels used for errors.Is classification.
Functions ¶
func NewAgenticLimitedHTTPClient ¶
NewAgenticLimitedHTTPClient returns a copy of source whose transport bounds native agentic request, successful response, and error response bodies. It never mutates the caller-owned client or transport. Protocol decoders remain responsible for enforcing framing-specific limits such as a single SSE event.
func NewBoundedAgenticModel ¶
func NewBoundedAgenticModel(delegate model.AgenticModel, limits AgenticLimits) (model.AgenticModel, error)
NewBoundedAgenticModel adds pre-dispatch and returned-message content-block validation to a native model. It complements the HTTP limiter, which owns byte boundaries at the transport layer.
func NewIdentifiedAgenticModel ¶
func NewIdentifiedAgenticModel(delegate model.AgenticModel, identity AgenticResponseIdentity) model.AgenticModel
NewIdentifiedAgenticModel preserves a delegate's native extension while attaching the stable identity contract required by this module.
func RegisterProvider ¶
func RegisterProvider(name string, ctor ProviderCtor)
RegisterProvider registers a provider constructor by name.
Backend packages should call RegisterProvider from init. Duplicate names are programming errors and panic, matching database/sql driver registration.
func RestoreAgenticContinuationForProvider ¶
func RestoreAgenticContinuationForProvider(public *schema.AgenticMessage, state AgenticContinuationState, provider, protocol string) (*schema.AgenticMessage, error)
RestoreAgenticContinuationForProvider recombines a public clone and opaque provider state without mutating either input.
func ValidateAgenticContentBlocks ¶
func ValidateAgenticContentBlocks(messages []*schema.AgenticMessage, limits AgenticLimits) error
ValidateAgenticContentBlocks rejects a message collection whose total block count exceeds the configured boundary without inspecting private block data.
func WrapAuthError ¶
WrapAuthError tags err as a provider authentication failure.
The returned error matches ErrProviderAuth with errors.Is and preserves err.Error() as its own Error string. Nil input returns nil.
func WrapInitError ¶
WrapInitError tags err as a provider initialization failure.
The returned error matches ErrProviderInit with errors.Is and preserves err.Error() as its own Error string. Nil input returns nil.
Types ¶
type AgenticContinuationState ¶
type AgenticContinuationState struct {
Provider string `json:"provider"`
Protocol string `json:"protocol"`
Version uint32 `json:"version"`
CorrelationID string `json:"correlation_id,omitempty"`
Opaque []byte `json:"opaque,omitempty"`
}
AgenticContinuationState is an opaque, versioned provider payload returned by a provider's SplitAgenticContinuation helper. Applications may persist it alongside the sanitized public message, but must not inspect or display it. The type intentionally has no String method to avoid accidental disclosure.
func SplitAgenticContinuationForProvider ¶
func SplitAgenticContinuationForProvider(msg *schema.AgenticMessage, provider, protocol string) (*schema.AgenticMessage, AgenticContinuationState, error)
SplitAgenticContinuationForProvider creates an immutable display-safe projection and a provider-tagged opaque continuation envelope. It removes extras and reasoning signatures from the public clone only; callers must retain the returned state to resume provider-native execution.
type AgenticLimits ¶
type AgenticLimits struct {
MaxRequestBytes int64
MaxEventBytes int64
MaxResponseBytes int64
MaxInlineMediaBytes int64
MaxContentBlocks int
MaxErrorBodyBytes int64
MaxFixtureCaptureBytes int64
}
AgenticLimits bounds request parsing and fixture capture. A zero field uses the documented default; negative values and values above hard caps are rejected by Validate.
func (AgenticLimits) Validate ¶
func (l AgenticLimits) Validate() (AgenticLimits, error)
Validate resolves defaults and rejects invalid or unsafe hard-limit values.
func (AgenticLimits) WithDefaults ¶
func (l AgenticLimits) WithDefaults() AgenticLimits
WithDefaults returns limits with every zero field replaced by its default.
type AgenticResponseIdentity ¶
type AgenticResponseIdentity struct {
Provider string `json:"provider"`
Protocol string `json:"protocol"`
RequestedModel string `json:"requested_model,omitempty"`
ReturnedModel string `json:"returned_model,omitempty"`
CorrelationID string `json:"correlation_id,omitempty"`
}
AgenticResponseIdentity records the provider identity observed for a native agentic response. RequestedModel and ReturnedModel are deliberately kept distinct because compatible endpoints may route to a different model.
type AgenticResponseMetadata ¶
type AgenticResponseMetadata struct {
Identity AgenticResponseIdentity `json:"identity"`
Native any `json:"native,omitempty"`
}
AgenticResponseMetadata preserves a provider adapter's native response extension while adding the stable identity fields exposed by this module. It is used where a protocol adapter already returned extension data that callers may rely on; replacing that data would lose correlation details.
type Capability ¶
type Capability string
Capability identifies a native protocol feature for capability errors. It intentionally contains no caller content, credentials, or opaque state.
type ErrorClass ¶
type ErrorClass int
ErrorClass is the switch-friendly classification returned by Classify.
const ( ErrorClassUnknown ErrorClass = iota ErrorClassProviderInit ErrorClassProviderTimeout ErrorClassProviderAPI ErrorClassProviderAuth ErrorClassUnknownProvider ErrorClassBackendUnreachable ErrorClassUnsupportedCapability ErrorClassResourceLimit )
func Classify ¶
func Classify(err error) ErrorClass
Classify returns the first matching provider error class for err.
type Options ¶
type Options struct {
// APIKey configures API-key authenticated backends such as Claude, OpenAI,
// Gemini, and OpenCode Go. It is ignored by Ollama and OpenAI-Codex.
APIKey string
// Protocol selects the OpenCode Go native inference protocol. It is ignored
// by every other backend. Use the typed constants from the opencodego
// package when setting this string field.
Protocol string
// UserAgent identifies the host coding agent to OpenCode Go. It is required
// by that backend and ignored by every other backend.
UserAgent string
// SessionID supplies the configured fallback OpenCode Go conversation
// identifier. Each request needs a valid configured or context session; a
// session attached to an operation context takes precedence. It is ignored by
// every other backend.
SessionID string
// BaseURL overrides the backend endpoint. Nil means use the backend
// default. OpenCode Go interprets it as the API root and appends the selected
// native inference route. OpenAI-Codex rejects non-nil BaseURL because its
// transport owns endpoint rewriting.
BaseURL *string
// MaxTokens requests an output-token cap where the backend supports one.
// OpenCode Go's direct Messages chat-model constructor requires a positive
// cap. Its registered Provider may leave this nil because Advise supplies
// the positive cap per invocation. Chat Completions and Responses allow nil.
// OpenAI-Codex ignores this because the Codex endpoint manages output
// length server-side.
MaxTokens *int
// KeepAlive configures Ollama model residency. Other backends ignore it.
KeepAlive *time.Duration
// HTTPClient supplies transport customization. OpenCode Go treats it as a
// trusted, unauthenticated base client that opencode-auth-go copies and decorates.
// OpenAI-Codex requires an authenticated client from codex-auth-go; other
// backends may ignore it.
HTTPClient *http.Client
// GenaiClient reuses an existing Gemini client and skips cold-start client
// construction when non-nil.
GenaiClient *genai.Client
}
Options configures provider construction.
Use field names in struct literals. Backends ignore fields that do not apply to them and validate fields that are forbidden for their endpoint semantics.
type Provider ¶
type Provider interface {
Advise(ctx context.Context, system, user string, maxTokens int) (text string, usage Usage, err error)
}
Provider is the contract every single-shot backend must satisfy.
Advise sends a single-turn request consisting of a system message and a user message, then returns the model's text reply. Implementations must honour ctx cancellation and deadlines, clamp maxTokens at the backend's Eino config layer, report unavailable usage as Usage{Available: false}, and wrap upstream errors with a short backend prefix.
func NewProvider ¶
NewProvider constructs a registered single-shot provider by name.
Backend packages register themselves from init. Consumers must import the backend packages they want, usually for side effects. If no backend registered name, NewProvider returns an error matching ErrUnknownProvider.
type ProviderCtor ¶
ProviderCtor constructs a single-shot Provider for a registered backend.
type ResourceLimitError ¶
ResourceLimitError identifies a bounded agentic resource without retaining the content that exceeded it.
func (*ResourceLimitError) Error ¶
func (e *ResourceLimitError) Error() string
func (*ResourceLimitError) Is ¶
func (e *ResourceLimitError) Is(target error) bool
type UnsupportedCapabilityError ¶
type UnsupportedCapabilityError struct {
Provider string
Protocol string
Capability Capability
}
UnsupportedCapabilityError is returned before transport dispatch when a concrete agentic provider cannot faithfully encode a requested feature.
func (*UnsupportedCapabilityError) Error ¶
func (e *UnsupportedCapabilityError) Error() string
func (*UnsupportedCapabilityError) Is ¶
func (e *UnsupportedCapabilityError) Is(target error) bool
type Usage ¶
Usage carries token accounting from a single provider call.
Available is false when the upstream provider did not return usage data. Consumers must not interpret InputTokens or OutputTokens unless Available is true.
func ExtractUsage ¶
ExtractUsage converts Eino message usage data into a Usage struct.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package claude provides Claude provider and native Messages AgenticModel constructors.
|
Package claude provides Claude provider and native Messages AgenticModel constructors. |
|
Package gemini provides Gemini provider and native generateContent AgenticModel constructors.
|
Package gemini provides Gemini provider and native generateContent AgenticModel constructors. |
|
Package ollama provides native Ollama chat and AgenticModel constructors.
|
Package ollama provides native Ollama chat and AgenticModel constructors. |
|
Package openai provides OpenAI provider and native Responses AgenticModel constructors.
|
Package openai provides OpenAI provider and native Responses AgenticModel constructors. |
|
Package openaicodex provides OAuth-authenticated native Codex Responses models.
|
Package openaicodex provides OAuth-authenticated native Codex Responses models. |
|
examples/toolcall
command
Command toolcall demonstrates a 2-turn tool-calling exchange against the OpenAI-Codex subscription backend using only the public eino-providers surface.
|
Command toolcall demonstrates a 2-turn tool-calling exchange against the OpenAI-Codex subscription backend using only the public eino-providers surface. |
|
Package opencodego integrates the OpenCode Go inference service with Eino.
|
Package opencodego integrates the OpenCode Go inference service with Eino. |
|
examples/toolcall
command
Command toolcall demonstrates a bounded, two-turn OpenCode Go function-tool exchange.
|
Command toolcall demonstrates a bounded, two-turn OpenCode Go function-tool exchange. |