agent

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package agent is the extension point for a client agent (an IDE, a CLI) that talks to a host in its own way. The shared request path asks the agent for the route's answer and does not branch on which agent it is. A new agent is one package that embeds Base, overrides only what differs, and registers its route paths.

This is a library package. A host (the proxy, the bifrost adapter) imports it; it never imports a host. imports_test.go enforces that.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(a Agent)

Register adds a to the default registry. It panics on a refusal: that is a wiring error in an init(), found at start-up (the components.Register pattern).

Types

type Agent

type Agent interface {
	// Name is the agent label on the dashboard. "" means the shared code picks the label.
	Name() string
	// Paths are the model routes this agent owns, as UPSTREAM paths: the path the host forwards to
	// (for example /inference/v1/chat/completions), not the path the client calls on the host
	// (which can carry a host prefix such as /openai). The registry finds the agent by them, by the
	// exact path: no method, no query string, the same trailing slash.
	Paths() []string
	// SessionID is a session id that only this agent's client sends in a header. The host tries
	// it LAST: after x-context-guru-session and the ids in the body. It is per agent because such
	// a header often has no vendor prefix, so any client can send it, and only the route that
	// owns it may read it. "" means none.
	SessionID(h http.Header) string
	// ReadUsage corrects the shared parser's reading of a reply's usage, for an agent whose
	// upstream reports fields the shared parser does not know. base is that reading. A reply it
	// cannot read must return base unchanged (fail open).
	ReadUsage(contentType string, reply []byte, base Usage) Usage
	// ModelTarget is where the host sends its own calls to this route's model (a summary, the
	// sweep's question). The agent never sees the key: the host builds the header from it.
	ModelTarget() ModelTarget
}

Agent is what the shared request path asks of the client agent on a route.

func All added in v0.7.4

func All() []Agent

All is every agent in the default registry. See (*Registry).All.

func ForPath

func ForPath(path string) Agent

ForPath looks path up in the default registry.

type Base

type Base struct{}

Base is the neutral agent: it changes nothing on the shared path. An agent embeds it and overrides only the methods where it differs, so a new method on Agent does not break it. That is why Agent holds only what a host wires today: a method is added when its first caller is.

func (Base) ModelTarget

func (Base) ModelTarget() ModelTarget

func (Base) Name

func (Base) Name() string

func (Base) Paths

func (Base) Paths() []string

func (Base) ReadUsage

func (Base) ReadUsage(_ string, _ []byte, base Usage) Usage

func (Base) SessionID

func (Base) SessionID(http.Header) string

type ControlCall added in v0.7.4

type ControlCall struct {
	Method string
	Path   string // without the query
	Hosted bool   // the host serves many tenants
}

ControlCall is the control-plane call the client made, as plain strings.

type ControlPlane added in v0.7.4

type ControlPlane interface {
	// WantsReply reports whether the agent reads the reply to c. True: the host asks the upstream
	// for an uncompressed reply, and calls Reply on a readable 200.
	WantsReply(c ControlCall) bool
	// Reply reads or changes the 200 reply body of c. body is at most the host's size limit, and
	// is the agent's own copy. A body the agent cannot read gives the zero value: the host sends
	// the body unchanged.
	Reply(c ControlCall, body []byte) ControlReply
}

ControlPlane is an optional capability, usually of the CatchAll Gateway: it reads or changes the reply to a control-plane call (a call that is not a model call). The host asks the agent of the route the call came in on. Like ModelTarget, it sees no header: the host keeps auth, the size limit and metering.

type ControlReply added in v0.7.4

type ControlReply struct {
	Body    []byte         // nil: send the upstream body unchanged
	Windows map[string]int // model id -> context window from the agent's catalog; nil: none
}

ControlReply is what the agent makes of a reply.

type Gateway added in v0.7.4

type Gateway interface {
	Agent
	Gateway() GatewaySpec
}

Gateway is an optional capability: the agent's client calls the host on the agent's own paths, at the host's root. From A2.5 PR 3, the host mounts each path in Paths() at the same path. A Gateway must have a Name, one per Gateway: the host keys its upstream by it. Register refuses an empty Name and a second Gateway with the same Name.

type GatewaySpec added in v0.7.4

type GatewaySpec struct {
	// Dialect is the wire dialect of the agent's model paths: "openai" today. From A2.5 PR 3, the
	// host refuses, at start-up, a dialect it does not serve.
	Dialect string
	// CatchAll forwards every request no other route matched to this agent's upstream. At most one
	// agent has it: Register refuses a second one.
	CatchAll bool
}

GatewaySpec is how the host mounts a Gateway.

type ModelTarget

type ModelTarget struct {
	Path       string // for example /inference/v1/chat/completions
	AuthScheme string // for example Apikey
}

ModelTarget is the chat path on the route's upstream, and the scheme of the Authorization header that carries the caller's key. "" in a field means the host default for it (/v1/chat/completions, Bearer). The host ignores a field it cannot use safely, and keeps its default for that field.

type Registry

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

Registry maps a route path to the agent that owns it. It is safe for concurrent use.

func NewRegistry

func NewRegistry() *Registry

func (*Registry) All added in v0.7.4

func (r *Registry) All() []Agent

All is every registered agent, each once, sorted by Name. The slice is the caller's own copy.

func (*Registry) ForPath

func (r *Registry) ForPath(path string) Agent

ForPath is the agent that owns path, or Base when no agent claims it.

func (*Registry) Register

func (r *Registry) Register(a Agent) error

Register adds a, with every path it claims. A path that is empty, repeated, or claimed by an agent already registered is refused, and then a claims no path at all. A Gateway with an empty Name, a second Gateway with the same Name, and a second CatchAll Gateway, are refused the same way.

type Usage

type Usage struct {
	FreshInput int64
	CacheRead  int64
	CacheWrite int64
	// CacheWrite1h is the part of CacheWrite billed at the one-hour write tier.
	CacheWrite1h int64
	Output       int64
	// Backend is a short label of which backend of the agent's upstream served the reply (for
	// example "A" or "B"), or "" for none. The agent sets it from marks it reads in the reply and
	// never returns the marks themselves. It is set whether or not the reply has usage.
	Backend string
}

Usage is the token counts ReadUsage reads and returns. It is a neutral copy of the counts in the host's own usage type: a library cannot import the host to use that type. The host maps its type to this one and back.

Directories

Path Synopsis
Package all blank-imports every built-in agent so their init() registrations run.
Package all blank-imports every built-in agent so their init() registrations run.
Package bob is the agent for IBM Bob: the Bob IDE and Bob Shell.
Package bob is the agent for IBM Bob: the Bob IDE and Bob Shell.

Jump to

Keyboard shortcuts

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