runner

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 24 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 default agent soul text.

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 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 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 CoreToolsBuilder added in v0.9.0

type CoreToolsBuilder func(plugintools.BuildContext) []tools.Tool

type DBPromptParams added in v0.8.0

type DBPromptParams struct {
	SystemPrompt   string          // agent's full system prompt from DB (the base layer)
	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
	Workspace      string
	Cwd            string // optional working directory
	UserDataDir    string // optional per-user data directory
	PromptTools    []pkgplugins.PromptToolInfo
	PromptSections []pkgplugins.SystemPromptSection
}

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(_ context.Context, cfg GoRunnerConfig) (*GoRunner, error)

NewGoRunner creates a Go runner with built-in providers.

func (*GoRunner) Alive

func (r *GoRunner) Alive() bool

Alive always returns true — the Go runner has no subprocess to die.

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 owned by the runner.

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
	WorkDir        string // working directory for tool execution
	Workspace      string // workspace dir for skills/memory (e.g. ~/.anna/workspace)
	AnnaHome       string // anna home directory (e.g. ~/.anna)
	System         string // optional system prompt override (bypasses default prompt building)
	PromptSections []pkgplugins.SystemPromptSection
	ExtraTools     []tools.Tool       // additional tools to register
	UserDataDir    string             // per-user data directory for sandbox enforcement (empty = no sandbox)
	HookPlugins    []hooks.HookPlugin // hook plugins for the engine loop
	ToolLifecycle  *coreagent.ToolLifecycle
	CoreTools      CoreToolsBuilder
	Providers      ProviderRegistryBuilder
}

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 (0 = no user isolation)
	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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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