Documentation
¶
Overview ¶
Package oneagent provides a config-driven interface for running any AI agent CLI.
Backends are defined in a compact JSON config with run/resume command strings, output format (json/jsonl), and field paths for extracting results, sessions, and errors. Template variables ({prompt}, {model}, {cwd}, {session}) are substituted at runtime. This lets you add new agent backends without writing any code.
Index ¶
- func CompactThread(backends map[string]Backend, threadID, backend string) error
- func ConfigDir() string
- func DefaultConfigPath() string
- func ListThreads() ([]string, error)
- func LoadBackends(path string) (map[string]Backend, error)
- func LoadBackendsWithOptions(opts LoadOptions) (map[string]Backend, error)
- func PreflightCheckBackend(name string, b Backend) error
- func ResolveBackendProgram(b Backend) (string, bool)
- func ThreadDir() string
- type Backend
- type Client
- func (c Client) CompactThread(threadID, backend string) error
- func (c Client) ListThreads() ([]string, error)
- func (c Client) LoadThread(id string) (*Thread, error)
- func (c Client) PreflightCheck(backend string) error
- func (c Client) Run(opts RunOpts) Response
- func (c Client) RunContext(ctx context.Context, opts RunOpts) Response
- func (c Client) RunStream(opts RunOpts, emit func(StreamEvent)) Response
- func (c Client) RunStreamContext(ctx context.Context, opts RunOpts, emit func(StreamEvent)) Response
- func (c Client) RunWithThread(opts RunOpts) Response
- func (c Client) RunWithThreadStream(opts RunOpts, emit func(StreamEvent)) Response
- func (c Client) SaveThread(t *Thread) error
- type FilesystemStore
- type HookContext
- type LoadOptions
- type Response
- func Run(backends map[string]Backend, opts RunOpts) Response
- func RunContext(ctx context.Context, backends map[string]Backend, opts RunOpts) Response
- func RunStream(backends map[string]Backend, opts RunOpts, emit func(StreamEvent)) Response
- func RunStreamContext(ctx context.Context, backends map[string]Backend, opts RunOpts, ...) Response
- func RunWithThread(backends map[string]Backend, opts RunOpts) Response
- func RunWithThreadStream(backends map[string]Backend, opts RunOpts, emit func(StreamEvent)) Response
- type RunOpts
- type Store
- type StreamEvent
- type Thread
- type Turn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompactThread ¶
CompactThread summarizes old turns using a backend, keeping the last keepTurns.
func ConfigDir ¶
func ConfigDir() string
ConfigDir returns the default config directory (~/.config/oneagent).
func DefaultConfigPath ¶
func DefaultConfigPath() string
DefaultConfigPath returns the optional user override config path.
func ListThreads ¶
ListThreads returns the IDs of all saved threads.
func LoadBackends ¶
LoadBackends loads embedded defaults when path is empty and merges the optional user override file (~/.config/oneagent/backends.json) on top. When path is non-empty, only that file is loaded.
func LoadBackendsWithOptions ¶ added in v0.11.5
func LoadBackendsWithOptions(opts LoadOptions) (map[string]Backend, error)
LoadBackendsWithOptions loads backends using explicit options. This is useful for consumers that want the embedded defaults but need to own the override path instead of using ~/.config/oneagent/backends.json.
func PreflightCheckBackend ¶ added in v0.12.1
PreflightCheckBackend validates a single Backend without requiring a Client.
func ResolveBackendProgram ¶ added in v0.10.5
ResolveBackendProgram returns the resolved path for a backend's CLI binary, checking $PATH first, then the backend's configured paths. Returns the program name and whether it was found.
Types ¶
type Backend ¶
type Backend struct {
Cmd []string
ResumeCmd []string
SystemPrompt string
Format string // "json" or "jsonl"
Activity string
ActivityWhen string
Delta string
DeltaWhen string
Result string
ResultWhen string
ResultAppend bool
Session string
SessionWhen string
Error string
ErrorWhen string
DefaultModel string
Paths []string // additional directories to search for the CLI binary
PromptStdin bool // pass prompt via stdin instead of argv
PreRunCmd string // shell command to run before backend execution
PostRunCmd string // shell command to run after backend execution
Probe string // optional fast command to verify the backend is ready (e.g. "claude --version")
}
Backend defines how to invoke and parse output from an agent CLI. Populated by compiling a backendConfig from the JSON config file.
type Client ¶
Client is an embeddable oneagent runtime with configurable backends and thread store.
func (Client) CompactThread ¶
CompactThread summarizes old turns using a backend, keeping the last keepTurns.
func (Client) ListThreads ¶
ListThreads returns the IDs of all saved threads from the configured store.
func (Client) LoadThread ¶
LoadThread reads a thread from the configured store. A missing thread returns an empty thread.
func (Client) PreflightCheck ¶ added in v0.12.1
PreflightCheck validates that a backend is runnable before any job is queued. It verifies the CLI binary exists on disk and, when a Probe command is configured, executes it to catch missing API keys or auth issues early.
func (Client) Run ¶
Run executes a prompt against the configured backends and returns a normalized response.
func (Client) RunContext ¶ added in v0.11.7
RunContext executes a prompt against the configured backends and returns a normalized response.
func (Client) RunStream ¶
func (c Client) RunStream(opts RunOpts, emit func(StreamEvent)) Response
RunStream executes a prompt and emits normalized streaming events as they arrive.
func (Client) RunStreamContext ¶ added in v0.11.7
func (c Client) RunStreamContext(ctx context.Context, opts RunOpts, emit func(StreamEvent)) Response
RunStreamContext executes a prompt and emits normalized streaming events as they arrive.
func (Client) RunWithThread ¶
RunWithThread wraps Run with thread load/save and context injection. Threading is handled by invoke() when ThreadID is set.
func (Client) RunWithThreadStream ¶
func (c Client) RunWithThreadStream(opts RunOpts, emit func(StreamEvent)) Response
RunWithThreadStream wraps RunStream with thread load/save and context injection. Threading is handled by invoke() when ThreadID is set.
func (Client) SaveThread ¶
SaveThread writes the thread to the configured store.
type FilesystemStore ¶
type FilesystemStore struct {
Dir string
}
FilesystemStore stores thread JSON files in a directory on disk.
func (FilesystemStore) ListThreads ¶
func (s FilesystemStore) ListThreads() ([]string, error)
ListThreads returns the IDs of all saved threads from the filesystem store.
func (FilesystemStore) LoadThread ¶
func (s FilesystemStore) LoadThread(id string) (*Thread, error)
LoadThread reads a thread from the filesystem store. A missing file returns an empty thread.
func (FilesystemStore) SaveThread ¶
func (s FilesystemStore) SaveThread(t *Thread) error
SaveThread writes the thread to disk, creating the directory if needed.
type HookContext ¶ added in v0.11.0
HookContext is passed to the PostRun callback after a backend invocation completes.
type LoadOptions ¶ added in v0.11.5
type LoadOptions struct {
// IncludeEmbedded loads the embedded default backends first.
IncludeEmbedded bool
// OverridePath is merged on top when IncludeEmbedded is true,
// or loaded directly when IncludeEmbedded is false.
OverridePath string
}
LoadOptions controls how backend configs are loaded.
type Response ¶
type Response struct {
Result string `json:"result"`
Session string `json:"session"`
ThreadID string `json:"thread_id,omitempty"`
Backend string `json:"backend"`
Error string `json:"error,omitempty"`
Warnings string `json:"warnings,omitempty"`
ExitCode int `json:"exit_code,omitempty"`
Stderr string `json:"stderr,omitempty"`
}
Response is the normalized output from any backend.
func RunContext ¶ added in v0.11.7
RunContext executes a prompt against the specified backend with cancellation support.
func RunStream ¶
func RunStream(backends map[string]Backend, opts RunOpts, emit func(StreamEvent)) Response
RunStream executes a prompt and emits normalized streaming events as they arrive.
func RunStreamContext ¶ added in v0.11.7
func RunStreamContext(ctx context.Context, backends map[string]Backend, opts RunOpts, emit func(StreamEvent)) Response
RunStreamContext executes a prompt with cancellation support and emits normalized streaming events.
func RunWithThread ¶
RunWithThread wraps Run with thread load/save and context injection.
func RunWithThreadStream ¶
func RunWithThreadStream(backends map[string]Backend, opts RunOpts, emit func(StreamEvent)) Response
RunWithThreadStream wraps RunStream with thread load/save and context injection.
type RunOpts ¶
type RunOpts struct {
Backend string
Prompt string
Model string
Thinking string // thinking/reasoning effort level (e.g. "low", "medium", "high")
CWD string
SessionID string
ThreadID string
Source string
PreRun func(*RunOpts) error // library callback: called before backend executes, can modify opts, return error to abort
PostRun func(*HookContext) // library callback: called after response, for side effects
PreRunCmd string // CLI shell command to run before backend execution
PostRunCmd string // CLI shell command to run after backend execution
}
RunOpts configures a single agent invocation.
type Store ¶
type Store interface {
LoadThread(id string) (*Thread, error)
SaveThread(thread *Thread) error
ListThreads() ([]string, error)
}
Store persists portable thread state for a Client.
type StreamEvent ¶
type StreamEvent struct {
Type string `json:"type"`
RunID string `json:"run_id,omitempty"`
TS time.Time `json:"ts,omitempty"`
Backend string `json:"backend"`
ThreadID string `json:"thread_id,omitempty"`
Session string `json:"session,omitempty"`
Activity string `json:"activity,omitempty"`
Delta string `json:"delta,omitempty"`
Result string `json:"result,omitempty"`
Error string `json:"error,omitempty"`
}
StreamEvent is a normalized incremental event emitted during a streaming run.
type Thread ¶
type Thread struct {
ID string `json:"id"`
Summary string `json:"summary,omitempty"`
Turns []Turn `json:"turns"`
NativeSessions map[string]string `json:"native_sessions,omitempty"`
}
Thread is a portable conversation that can span multiple backends.
func LoadThread ¶
LoadThread reads a thread from disk. A missing file returns an empty thread.
func (*Thread) CompileContext ¶
CompileContext builds a context string from the thread's history within a byte budget.
func (*Thread) CompileRecentTurns ¶ added in v0.13.0
CompileRecentTurns builds a minimal context string from the most recent turns.