Documentation
¶
Overview ¶
Package proxy is the context-guru HTTP proxy: it runs the component pipeline on inbound chat requests, then forwards them to the configured upstream provider. It is the eval-containers gateway (exposes /openai + /anthropic on one port) and the standalone LLM-proxy integration.
It reuses bifrost's ChatMessage type but not its transport: the transport can't inject an in-process Go plugin, so we drive the request path directly. Message rewriting is byte-lossless (headroom invariant I1) — only the `messages` array is re-serialized; every other field of the original body is preserved verbatim via sjson.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves the proxy + management routes.
func New ¶
func New(pipe *components.Pipeline, st store.Store, agg *metrics.Aggregator, opts Options) *Handler
New builds the proxy handler. agg may be nil (no /stats rollups).
type Options ¶
type Options struct {
OpenAIUpstream string // e.g. https://api.openai.com
AnthropicUpstream string
// BobUpstream, when set, enables the Bob (BobShell) gateway: Bob's
// OpenAI-dialect model calls (POST /inference/v1/chat/completions) are reduced
// and forwarded here, and every other path Bob calls (control-plane:
// /admin/v1/profile, /inference/v1/model/info, …) is proxied through verbatim
// so the CLI boots and authenticates. Point Bob's CUSTOM_BASE_URL at this proxy.
BobUpstream string // e.g. https://api.us-east.bob.ibm.com
OpenAIKey string // injected as Authorization: Bearer <key>
AnthropicKey string // injected as x-api-key: <key>
// ForceModel, when set, overwrites the request's "model" field. eval-containers
// uses this to pin every call to EVAL_MODEL regardless of what the agent asked for.
ForceModel string
Client *http.Client
// CheapModel is the static "config"-source LLM client for NeedsModel
// components (nil = none). The "incoming"-source client is built per request
// from the route's upstream + the gateway's real key.
CheapModel components.Model
// Windows resolves a model's context window (max input tokens) so fraction-based
// Trigger thresholds scale with the model. nil => window unknown (0), fractions
// ignored, absolutes apply. Built in main from internal/modelinfo.
Windows interface {
Window(ctx context.Context, model string) (int, bool)
}
// InjectExpand controls advertising the context_guru_expand tool on outgoing
// requests so Offload markers are actually recoverable (expand.InjectAuto |
// InjectAlways | InjectNever). Empty defaults to auto. auto injects only when the
// request already declares tools and the store persists — safe for any agent.
InjectExpand string
// CacheMode controls cache-aware compaction ("auto"|"on"|"off"; empty=auto).
// auto/on keep offloaders from mutating already-cached content on prompt-caching
// backends; off restores legacy compact-everything (for confirmed non-caching backends).
CacheMode string
// PipelineFor builds a pipeline for a per-request override on /compact
// (?preset=… or x-context-guru-pipeline: a,b,c). nil = overrides ignored, the
// handler always uses the configured pipeline. Supplied by main (which holds
// the config + emitter) so proxy stays decoupled from the config package.
PipelineFor func(preset string, names []string) (*components.Pipeline, error)
}
Options configures upstreams and credential injection. Each upstream is a base URL the matching route forwards to (the incoming path is appended). When a key is set it replaces the client's auth on forward — this is the eval-containers gateway model, where the agent holds only a placeholder key and the real provider key lives in the gateway env. Leave keys empty to pass the incoming auth through unchanged (local/dev use).