runner

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildSystemPromptFromDB added in v0.8.0

func BuildSystemPromptFromDB(ctx context.Context, p DBPromptParams) string

BuildSystemPromptFromDB composes the full system prompt by populating a promptData struct and executing the system template.

Layers:

  1. System prompt — the agent's base system prompt from DB
  2. Tools — always-available tool descriptions (in the template)
  3. Agent soul — per-user identity/personality from memory ProfileStore
  4. User profile — per-user facts/context from memory ProfileStore
  5. Extension prompt sections — stable prompt content owned by plugins
  6. Project context — AGENTS.md files from cwd ancestors

func ChannelFromContext added in v0.9.0

func ChannelFromContext(ctx context.Context) (string, bool)

ChannelFromContext returns the current chat channel when present.

func DecodeEvent

func DecodeEvent(raw []byte) (ai.AssistantEvent, error)

DecodeEvent deserializes envelope to concrete event type.

func DefaultAgentSoul added in v0.9.0

func DefaultAgentSoul() string

DefaultAgentSoul returns the first soul tagged "default" from the builtin registry, used as the fallback persona when an agent has no override in memory.

func DefaultSystemPrompt added in v0.9.0

func DefaultSystemPrompt() string

DefaultSystemPrompt returns the default system prompt text.

func EncodeEvent

func EncodeEvent(event ai.AssistantEvent) ([]byte, error)

EncodeEvent serializes normalized assistant events.

func ExcludedToolsFromContext added in v0.12.0

func ExcludedToolsFromContext(ctx context.Context) []string

ExcludedToolsFromContext returns the per-run excluded tool names when present.

func MessageText

func MessageText(message MessageContent) string

MessageText extracts and joins all text from a message.

func SystemOverrideFromContext added in v0.9.0

func SystemOverrideFromContext(ctx context.Context) (string, bool)

SystemOverrideFromContext returns the per-run system prompt override when present.

func WithChannel added in v0.9.0

func WithChannel(ctx context.Context, channel string) context.Context

WithChannel returns a child context that carries the current chat channel.

func WithExcludedTools added in v0.12.0

func WithExcludedTools(ctx context.Context, names ...string) context.Context

WithExcludedTools returns a child context that hides the named tools for a single run.

func WithSystemOverride added in v0.9.0

func WithSystemOverride(ctx context.Context, system string) context.Context

WithSystemOverride returns a child context that carries a per-run system prompt override.

Types

type ActivityTracker

type ActivityTracker interface {
	LastActivity() time.Time
}

ActivityTracker is an optional interface for runners that track last activity.

type Aliver

type Aliver interface {
	Alive() bool
}

Aliver is an optional interface for runners that can report liveness.

type DBPromptParams added in v0.8.0

type DBPromptParams struct {
	SystemPrompt   string          // agent's base system prompt from DB
	AgentSoul      string          // agent's default soul from DB (fallback for all users)
	Memory         memory.Provider // active provider for profile loading (may be nil)
	UserID         int64           // auth user ID for profile lookup
	AgentID        string          // agent ID for profile lookup
	AnnaHome       string
	AgentRoot      string
	ProjectRoot    string // optional project root for local/project-attached runs
	UserRoot       string // per-user writable root
	PromptTools    []pkgplugins.PromptToolInfo
	PromptSections []pkgplugins.SystemPromptSection
	Host           sandbox.Host
}

DBPromptParams holds the parameters for building a system prompt from DB-backed config.

type Envelope

type Envelope struct {
	Type string          `json:"type"`
	Data json.RawMessage `json:"data"`
}

Envelope wraps stream events for transport.

type Event

type Event struct {
	Text    string
	Image   *ImageEvent
	ToolUse *ToolUseEvent
	Store   ai.Message // if non-nil, Pool appends to session history
	Err     error
}

Event is the consumer-facing stream event. Channels read these from the stream returned by Pool.Chat().

type GoRunner

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

GoRunner implements Runner by calling LLM providers directly via agent.Runner.

func NewGoRunner

func NewGoRunner(ctx context.Context, cfg GoRunnerConfig) (*GoRunner, error)

NewGoRunner creates a Go runner with built-in providers.

func (*GoRunner) Alive

func (r *GoRunner) Alive() bool

Alive reports whether the runner is healthy. Delegates to the session's lifecycle state.

func (*GoRunner) Chat

func (r *GoRunner) Chat(ctx context.Context, history []ai.Message, message MessageContent) <-chan Event

Chat runs the Engine agent loop with the provided history and forwards events.

func (*GoRunner) Close

func (r *GoRunner) Close() error

Close shuts down any subprocess-backed tools and the sandbox session. Guarantees cleanup of session resources regardless of state.

func (*GoRunner) LastActivity

func (r *GoRunner) LastActivity() time.Time

LastActivity returns the time of the last Chat call.

func (*GoRunner) SystemPrompt added in v0.9.0

func (r *GoRunner) SystemPrompt() string

SystemPrompt returns the runner's base system prompt before per-run overrides.

type GoRunnerConfig

type GoRunnerConfig struct {
	API              string // provider key: "anthropic", "openai"
	Model            string // e.g. "claude-sonnet-4-20250514"
	APIKey           string
	BaseURL          string // optional provider base URL override
	AgentRoot        string // agent root directory
	AnnaHome         string // anna home directory (e.g. ~/.anna)
	ProjectRoot      string // optional project root for project-aware tools and prompt/context loading
	System           string // optional system prompt override (bypasses default prompt building)
	PromptSections   []pkgplugins.SystemPromptSection
	ExtraTools       []tools.Tool // additional tools to register
	PluginTools      func(context.Context, plugintools.BuildContext) []tools.Tool
	ToolRuntime      pkgplugins.ToolRuntime
	UserRoot         string             // required per-user root used by prompts, skills, and sandbox execution
	HookPlugins      []hooks.HookPlugin // hook plugins for the engine loop
	ToolLifecycle    *coreagent.ToolLifecycle
	Providers        ProviderRegistryBuilder
	Sandbox          config.SandboxConfig
	SandboxBackendFn func(ctx context.Context) string // resolves active backend at session time; overrides Sandbox.Backend
}

GoRunnerConfig configures the Go runner.

type HandlerFunc

type HandlerFunc func(ctx context.Context, history []ai.Message, message MessageContent) <-chan Event

HandlerFunc is an adapter to allow the use of ordinary functions as Runners. If f is a function with the appropriate signature, HandlerFunc(f) is a Runner that calls f.

func (HandlerFunc) Chat

func (f HandlerFunc) Chat(ctx context.Context, history []ai.Message, message MessageContent) <-chan Event

Chat calls f(ctx, history, message).

type ImageEvent

type ImageEvent struct {
	Data     string // base64 encoded
	MimeType string // e.g. "image/jpeg"
}

ImageEvent carries a base64-encoded image to be sent to the channel.

type MessageContent

type MessageContent = any

MessageContent is the type for user messages passed through the runner pipeline. It is either string (text-only) or []ai.ContentBlock (multimodal, e.g. text + images).

type NewRunnerFunc

type NewRunnerFunc func(ctx context.Context, params RunnerParams) (Runner, error)

NewRunnerFunc creates a new Runner instance with the given params.

type ProviderRegistryBuilder added in v0.9.0

type ProviderRegistryBuilder func(api, apiKey, baseURL string) (*providers.Registry, error)

type Runner

type Runner interface {
	Chat(ctx context.Context, history []ai.Message, message MessageContent) <-chan Event
}

Runner runs prompts against an AI backend. It is stateless — it receives full history each call and must reconstruct context from it.

type RunnerParams added in v0.8.0

type RunnerParams struct {
	Model   string                    // model ID (empty = use default)
	Memory  any                       // memory.Provider — typed as any to avoid circular imports
	UserID  int64                     // auth user ID for user-scoped runner creation
	AgentID string                    // agent ID for profile loading
	HooksFn func() []hooks.HookPlugin // resolved at runner-creation time; nil = no hooks
}

RunnerParams holds parameters for creating a new Runner instance.

type Stateful

type Stateful interface {
	Stateful() bool
}

Stateful is an optional interface for runners that maintain their own context in-process (e.g., a long-running subprocess). When a runner is Stateful, Pool will not kill it after compaction — the runner keeps its live context and the compacted history is only persisted to disk for crash recovery.

type SystemPrompter added in v0.9.0

type SystemPrompter interface {
	SystemPrompt() string
}

SystemPrompter is an optional interface for runners that expose their base system prompt.

type ToolUseEvent

type ToolUseEvent struct {
	Tool   string // tool name, e.g. "bash", "read"
	Status string // "running", "done", "error"
	Input  string // short summary of the tool input
	Detail string // error detail or result summary (for "error" status)
}

ToolUseEvent describes a tool invocation in progress or completed.

Jump to

Keyboard shortcuts

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