runner

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 20 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(p DBPromptParams) string

BuildSystemPromptFromDB composes the full system prompt in three layers:

  1. Basic system prompt — embedded default, overridden by SYSTEM.md in workspace
  2. Agent soul prompt — DB agents.system_prompt, overridden by SOUL.md in workspace
  3. User memory — always present from DB, updated via the memory tool (user_memory_update action)

Skills and project context are appended after these layers.

func DecodeEvent

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

DecodeEvent deserializes envelope to concrete event type.

func EncodeEvent

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

EncodeEvent serializes normalized assistant events.

func FormatSkillsForPrompt

func FormatSkillsForPrompt(skills []Skill) string

FormatSkillsForPrompt renders the available skills as XML for the system prompt. Skills with DisableModelInvocation=true are excluded.

func MessageText

func MessageText(message MessageContent) string

MessageText extracts and joins all text from a message.

func ValidateSkillName

func ValidateSkillName(name, parentDirName string) []string

ValidateSkillName checks a skill name against the Agent Skills spec. Returns validation errors (empty slice if valid).

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 soul from agents.system_prompt
	UserMemory   string // from user_agent_memory.content (always injected)
	AnnaHome     string
	Workspace    string
	Cwd          string // optional working directory
}

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 Engine.

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 is a no-op for the Go runner.

func (*GoRunner) LastActivity

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

LastActivity returns the time of the last Chat call.

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)
	ExtraTools  []tool.Tool             // additional tools to register
	PluginHooks engine.PluginHookRunner // optional plugin lifecycle hooks
}

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 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)
	UserMemory string // per-user memory to inject into system prompt
}

RunnerParams holds parameters for creating a new Runner instance.

type Skill

type Skill struct {
	Name                   string
	Description            string
	FilePath               string // absolute path to the SKILL.md or .md file
	BaseDir                string // directory containing the skill file
	Source                 string // "user", "project", or "path"
	DisableModelInvocation bool
}

Skill represents a discovered skill with its metadata and location.

func LoadSkills

func LoadSkills(annaHome, workspace, cwd string) []Skill

LoadSkills discovers skills from project, workspace, and common directories. annaHome is the anna home directory (e.g. ~/.anna), workspace is the workspace dir (e.g. ~/.anna/workspace), cwd is the working directory. Priority order: cwd/.agents/skills/ > workspace/skills/ > ~/.agents/skills/ > builtin

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 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