gateway

package
v0.1.0-beta.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package gateway is the LLM-side passthrough provider. It wraps a set of model-prefix → underlying provider routes and delegates each ChatRequest to the route that matches the request's Model.

The "gateway" name parallels the MCP gateway: just as Gateway.CallTool fronts heterogeneous downstream MCP servers behind one entry point, llm.gateway.Provider fronts heterogeneous LLM vendors behind one agent.ChatModel. The runtime holds a single provider; provider selection is a configuration concern, not an architectural one.

Routes are matched by Model prefix in the order they were registered; the first match wins. Providers are intentionally registered with short prefixes ("claude-", "gpt-", "gemini-") so a single instance can serve mixed-provider skills out of the box.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Provider)

Option configures a Provider during construction.

func WithFallback

func WithFallback(provider agent.ChatModel) Option

WithFallback sets a provider used when no prefix matches. Without a fallback, unmatched requests return an error.

func WithRoute

func WithRoute(prefix string, provider agent.ChatModel) Option

WithRoute registers a (prefix, provider) route. Order matters: the first matching prefix wins on each ChatRequest.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements agent.ChatModel by routing to one of N underlying providers based on ChatRequest.Model. Construct via New.

func New

func New(opts ...Option) (*Provider, error)

New constructs a routing Provider. At least one route or a fallback must be configured; an empty router returns an error so misconfigured callers fail at construction rather than on first request.

func (*Provider) Generate

func (p *Provider) Generate(ctx context.Context, req agent.ChatRequest) (agent.ChatResponse, error)

Generate dispatches the request to the matching underlying provider.

func (*Provider) Routes

func (p *Provider) Routes() []Route

Routes returns a copy of the registered routes. Useful for diagnostics; the slice is safe to mutate.

func (*Provider) Stream

Stream dispatches the request to the matching underlying provider.

type Route

type Route struct {
	Prefix   string
	Provider agent.ChatModel
}

Route binds a model-name prefix to an underlying provider. Prefix matching is intentional rather than exact-match — the runtime can register "claude-" once and serve every Claude model the user asks for, including new IDs not known at build time.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL