Documentation
¶
Index ¶
- func BuildSystemPromptFromDB(ctx context.Context, p DBPromptParams) string
- func ChannelFromContext(ctx context.Context) (string, bool)
- func DecodeEvent(raw []byte) (ai.AssistantEvent, error)
- func DefaultAgentSoul() string
- func DefaultSystemPrompt() string
- func EncodeEvent(event ai.AssistantEvent) ([]byte, error)
- func MessageText(message MessageContent) string
- func SystemOverrideFromContext(ctx context.Context) (string, bool)
- func WithChannel(ctx context.Context, channel string) context.Context
- func WithSystemOverride(ctx context.Context, system string) context.Context
- type ActivityTracker
- type Aliver
- type DBPromptParams
- type Envelope
- type Event
- type GoRunner
- type GoRunnerConfig
- type HandlerFunc
- type ImageEvent
- type MessageContent
- type NewRunnerFunc
- type ProviderRegistryBuilder
- type Runner
- type RunnerParams
- type Stateful
- type SystemPrompter
- type ToolUseEvent
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:
- System prompt — the agent's base system prompt from DB
- Tools — always-available tool descriptions (in the template)
- Agent soul — per-user identity/personality from memory ProfileStore
- User profile — per-user facts/context from memory ProfileStore
- Extension prompt sections — stable prompt content owned by plugins
- Project context — AGENTS.md files from cwd ancestors
func ChannelFromContext ¶ added in v0.9.0
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
SystemOverrideFromContext returns the per-run system prompt override when present.
func WithChannel ¶ added in v0.9.0
WithChannel returns a child context that carries the current chat channel.
Types ¶
type ActivityTracker ¶
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 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
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 ¶
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 ¶
Close shuts down any subprocess-backed tools and the sandbox session. Guarantees cleanup of session resources regardless of state.
func (*GoRunner) LastActivity ¶
LastActivity returns the time of the last Chat call.
func (*GoRunner) SystemPrompt ¶ added in v0.9.0
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
PluginTools func(context.Context, plugintools.BuildContext) []tools.Tool
ToolRuntime pkgplugins.ToolRuntime
UserDataDir string // optional per-user data directory used by prompts, skills, and sandbox session setup
HookPlugins []hooks.HookPlugin // hook plugins for the engine loop
ToolLifecycle *coreagent.ToolLifecycle
Providers ProviderRegistryBuilder
Sandbox config.SandboxConfig
}
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 ¶
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 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.