Documentation
¶
Overview ¶
Package adapter defines the contract every agent CLI backend implements, and the registry that turns a config block into a live adapter.
Adapters are pure translators: they build argv and parse CLI output into [ir.Event]s. Process lifecycle belongs to internal/runner, and no adapter holds state across requests.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsRegistered ¶
IsRegistered reports whether this build can serve the given adapter id.
func Register ¶
Register makes an adapter implementation available to the gateway. It is called from the implementation package's init, so linking the package in is what enables the backend.
func Registered ¶
func Registered() []string
Registered lists the adapter ids compiled into this build.
Types ¶
type Adapter ¶
type Adapter interface {
// ID is the adapter id used to namespace models, e.g. "claude-code".
ID() string
// Probe checks that the CLI is installed, runnable and authenticated.
Probe(ctx context.Context) (Health, error)
// Run executes one request. It always streams: non-streaming callers just
// collect events until the terminal one. The returned channel is closed
// after an [ir.EventDone] or [ir.EventError].
Run(ctx context.Context, req ir.Request) (<-chan ir.Event, error)
}
Adapter turns one agent CLI into an inference backend.
An adapter advertises no model list. A request carries the model name the caller asked for in ir.Request.Variant; the adapter passes it to the CLI, which is the only authority on which names it accepts. An empty variant means "whatever model the CLI would pick on its own".
type EffortSetter ¶ added in v0.1.5
EffortSetter is implemented by adapters whose CLI has a knob for how hard the model thinks.
It reports the levels rather than a yes/no because the CLIs do not agree on a scale: Claude Code takes low through max and has no `minimal`, OpenAI's vocabulary has no `max`. A frontend asks for the list so it can refuse a level this backend does not have by naming both — which beats rounding the caller's request to the nearest neighbour and not saying so.
A nil or empty result means the installed CLI offers no such knob.
type Health ¶
type Health struct {
// Binary is the resolved absolute path of the CLI, when it was found.
Binary string
// Version is whatever the CLI reports for --version.
Version string
// Account describes the authenticated identity, when the CLI exposes one.
Account string
// Notes carry non-fatal remarks, e.g. flags the installed version lacks.
Notes []string
}
Health is the outcome of probing a backend, as reported by `agent2api doctor`.
type Options ¶
type Options struct {
ID string
Config config.Adapter
// ScratchRoot is the parent directory for per-request workdirs; empty means
// the OS temp directory.
ScratchRoot string
// RequestTimeout caps a whole run; IdleTimeout caps silence within one.
RequestTimeout time.Duration
IdleTimeout time.Duration
// Logger is the gateway logger, already scoped to this adapter.
Logger *slog.Logger
}
Options carries everything an adapter needs from the global config, with inheritance already resolved.
type SchemaEnforcer ¶ added in v0.1.3
SchemaEnforcer is implemented by adapters whose CLI can hold an answer to a JSON Schema.
It is an optional interface rather than a method on Adapter because the answer is a property of the installed binary, not of the adapter: the same adapter reports false against a CLI too old for the flag. Frontends ask before accepting a caller's schema so the refusal can name the backend that cannot do it, instead of reading as a gateway-wide limitation.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package agentcli holds the plumbing every CLI-backed adapter needs: resolving the binary, learning which flags the installed version actually supports, and turning one subprocess run into a stream of IR events.
|
Package agentcli holds the plumbing every CLI-backed adapter needs: resolving the binary, learning which flags the installed version actually supports, and turning one subprocess run into a stream of IR events. |
|
Package claudecode adapts the Claude Code CLI (`claude`) into an inference backend.
|
Package claudecode adapts the Claude Code CLI (`claude`) into an inference backend. |
|
Package codex adapts the Codex CLI (`codex exec`) into an inference backend.
|
Package codex adapts the Codex CLI (`codex exec`) into an inference backend. |
|
Package cursor adapts the Cursor Agent CLI (`cursor-agent`) into an inference backend.
|
Package cursor adapts the Cursor Agent CLI (`cursor-agent`) into an inference backend. |
|
Package fake provides an in-memory adapter for tests: it exercises the gateway end to end without spawning a CLI.
|
Package fake provides an in-memory adapter for tests: it exercises the gateway end to end without spawning a CLI. |
|
Package mock is a scripted backend, compiled in only with the "conformance" build tag.
|
Package mock is a scripted backend, compiled in only with the "conformance" build tag. |
|
Package qwen adapts the Qwen Code CLI (`qwen`) into an inference backend.
|
Package qwen adapts the Qwen Code CLI (`qwen`) into an inference backend. |