Documentation
¶
Index ¶
- func BuildSessionKey(agentID, platform, externalUserID, channelContext string) string
- func BuildSystemPromptFromDB(ctx context.Context, p DBPromptParams) string
- func BuildUserSessionKey(agentID string, authUserID int64, channelContext string) 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 ExcludedToolsFromContext(ctx context.Context) []string
- func MessageText(message MessageContent) string
- func SaveAsset(assetsDir, fileName string, data []byte) (string, error)
- func SetupUserWorkspace(agentID, basePath string, userID int64) (string, error)
- func SetupWorkspace(agentID, basePath string) (string, error)
- func SystemOverrideFromContext(ctx context.Context) (string, bool)
- func UserAssetsDir(userRoot string) string
- func UserRoot(userWorkspace string) string
- func UserSkillsDir(userWorkspace string) string
- func WithChannel(ctx context.Context, channel string) context.Context
- func WithExcludedTools(ctx context.Context, names ...string) context.Context
- func WithSystemOverride(ctx context.Context, system string) context.Context
- type ActivityTracker
- type Aliver
- type BeforeRunBuilder
- type BuiltinToolsFactory
- type ChatOption
- type CompactionConfig
- type DBPromptParams
- type Envelope
- type Event
- type FileEvent
- type GoRunner
- type GoRunnerConfig
- type HandlerFunc
- type ImageEvent
- type MessageContent
- type NewRunnerFunc
- type PluginHooksBuilder
- type PluginPromptsBuilder
- type PluginToolsBuilder
- type Pool
- func (p *Pool) ActiveSession(channel string) (SessionInfo, bool)
- func (p *Pool) AgentID() string
- func (p *Pool) ArchiveSession(sessionID string) error
- func (p *Pool) Chat(ctx context.Context, sessionID string, message MessageContent, ...) <-chan Event
- func (p *Pool) Close() error
- func (p *Pool) CompactSession(ctx context.Context, sessionID string) (string, error)
- func (p *Pool) CreateSession(channel string, userID ...int64) (SessionInfo, error)
- func (p *Pool) GetSession(sessionID string) (SessionInfo, error)
- func (p *Pool) History(sessionID string) []ai.Message
- func (p *Pool) ListSessions(includeArchived bool) ([]SessionInfo, error)
- func (p *Pool) NeedsCompaction(sessionID string) bool
- func (p *Pool) ResetRunners() error
- func (p *Pool) ResetRunnersForUser(userID int64) error
- func (p *Pool) ResolveSession(channel string, userID ...int64) (SessionInfo, error)
- func (p *Pool) RotateSession(channel string, userID ...int64) (SessionInfo, error)
- func (p *Pool) SetDefaultModel(model string)
- func (p *Pool) SetFactory(factory NewRunnerFunc)
- func (p *Pool) SetFastModel(model string)
- func (p *Pool) SetHooks(fn func() []hooks.HookPlugin)
- func (p *Pool) StartReaper(ctx context.Context)
- type PoolManager
- func (pm *PoolManager) AddBuiltinTool(ctx context.Context, tool tools.Tool) error
- func (pm *PoolManager) Close() error
- func (pm *PoolManager) DefaultPool() *Pool
- func (pm *PoolManager) Get(agentID string) *Pool
- func (pm *PoolManager) HookPlugins() []hooks.HookPlugin
- func (pm *PoolManager) InvalidateUser(userID int64) error
- func (pm *PoolManager) ReloadPluginHooks(ctx context.Context) error
- func (pm *PoolManager) ReloadPluginProviders(ctx context.Context) error
- func (pm *PoolManager) ReloadPluginTools(ctx context.Context) error
- func (pm *PoolManager) SetOAuthRegistry(r *oauth.ProviderRegistry)
- func (pm *PoolManager) SetVaultEnvLoader(ctx context.Context, v VaultEnvLoader)
- func (pm *PoolManager) StartAll(ctx context.Context) error
- func (pm *PoolManager) SyncAgent(ctx context.Context, agentID string) error
- type PoolManagerOption
- func WithBeforeRunBuilderPM(b BeforeRunBuilder) PoolManagerOption
- func WithBuiltinTools(tools []tools.Tool) PoolManagerOption
- func WithBuiltinToolsFactory(f BuiltinToolsFactory) PoolManagerOption
- func WithCompactionPM(cfg CompactionConfig) PoolManagerOption
- func WithIdleTimeoutPM(d time.Duration) PoolManagerOption
- func WithPluginHooksBuilder(b PluginHooksBuilder) PoolManagerOption
- func WithPluginPromptsBuilder(b PluginPromptsBuilder) PoolManagerOption
- func WithPluginToolsBuilder(b PluginToolsBuilder) PoolManagerOption
- func WithPromptSectionsBuilder(b PromptSectionsBuilder) PoolManagerOption
- func WithPromptToolsBuilder(b PromptToolsBuilder) PoolManagerOption
- func WithProviderRegistryBuilder(b ProviderRegistryBuilder) PoolManagerOption
- func WithSessionPluginViewBuilder(b SessionPluginViewBuilder) PoolManagerOption
- func WithSkillStore(s pkgplugins.SkillStore) PoolManagerOption
- func WithTokenManager(tm *oauth.TokenManager) PoolManagerOption
- func WithToolLifecyclePM(tl *coreagent.ToolLifecycle) PoolManagerOption
- func WithVaultEnvLoader(v VaultEnvLoader) PoolManagerOption
- type PoolOption
- func WithAgentID(id string) PoolOption
- func WithBeforeRunBuilder(b BeforeRunBuilder) PoolOption
- func WithCompaction(cfg CompactionConfig) PoolOption
- func WithDefaultModel(model string) PoolOption
- func WithFastModel(model string) PoolOption
- func WithIdleTimeout(d time.Duration) PoolOption
- func WithSnapshotPromptBuilder(...) PoolOption
- type PromptSectionsBuilder
- type PromptToolsBuilder
- type ProviderRegistryBuilder
- type Runner
- type RunnerParams
- type Session
- type SessionInfo
- type SessionPluginViewBuilder
- type Stateful
- type SystemPrompter
- type ToolUseEvent
- type VaultEnvLoader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildSessionKey ¶ added in v0.8.0
BuildSessionKey constructs a session key from agent, platform, user, and context. Format: {agentID}:{platform}:{externalUserID}:{channelContext}
func BuildSystemPromptFromDB ¶ added in v0.17.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 BuildUserSessionKey ¶ added in v0.9.0
BuildUserSessionKey constructs a session key for a linked auth user. Linked users share a single session across all channels (for the same agent and channel context), so the key omits the platform-specific external ID. Format: {agentID}:user:{authUserID}:{channelContext}
func ChannelFromContext ¶ added in v0.17.0
ChannelFromContext returns the current chat channel when present.
func DecodeEvent ¶ added in v0.17.0
func DecodeEvent(raw []byte) (ai.AssistantEvent, error)
DecodeEvent deserializes envelope to concrete event type.
func DefaultAgentSoul ¶ added in v0.17.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.17.0
func DefaultSystemPrompt() string
DefaultSystemPrompt returns the default system prompt text.
func EncodeEvent ¶ added in v0.17.0
func EncodeEvent(event ai.AssistantEvent) ([]byte, error)
EncodeEvent serializes normalized assistant events.
func ExcludedToolsFromContext ¶ added in v0.17.0
ExcludedToolsFromContext returns the per-run excluded tool names when present.
func MessageText ¶ added in v0.17.0
func MessageText(message MessageContent) string
MessageText extracts and joins all text from a message.
func SaveAsset ¶ added in v0.17.0
SaveAsset writes data to assetsDir with a timestamp-prefixed filename to avoid collisions, returning the absolute path of the saved file.
func SetupUserWorkspace ¶ added in v0.9.0
SetupUserWorkspace ensures per-user directories exist within an agent workspace. Creates:
- basePath/workspaces/{agentID}/users/{userID}/.agents/skills/
- basePath/workspaces/{agentID}/users/{userID}/data/
- basePath/workspaces/{agentID}/users/{userID}/assets/
Returns the absolute path to the user's workspace directory (basePath/workspaces/{agentID}/users/{userID}/).
func SetupWorkspace ¶ added in v0.8.0
SetupWorkspace ensures the per-agent workspace directory exists. Creates: basePath/workspaces/{agentID}/.agents/skills/ Returns the absolute path to the agent's workspace directory.
func SystemOverrideFromContext ¶ added in v0.17.0
SystemOverrideFromContext returns the per-run system prompt override when present.
func UserAssetsDir ¶ added in v0.17.0
UserAssetsDir returns the per-user assets directory within a user root. Uploaded files from all channels are stored here.
func UserRoot ¶ added in v0.10.1
UserRoot returns the per-user writable root path within a user workspace.
User-owned runtime data, skills, and presets all live under this root:
- users/{id}/data/
- users/{id}/.agents/skills/
- users/{id}/.agents/agents/
func UserSkillsDir ¶ added in v0.9.0
UserSkillsDir returns the per-user skills directory path within a user workspace.
func WithChannel ¶ added in v0.17.0
WithChannel returns a child context that carries the current chat channel.
func WithExcludedTools ¶ added in v0.17.0
WithExcludedTools returns a child context that hides the named tools for a single run.
Types ¶
type ActivityTracker ¶ added in v0.17.0
ActivityTracker is an optional interface for runners that track last activity.
type Aliver ¶ added in v0.17.0
type Aliver interface {
Alive() bool
}
Aliver is an optional interface for runners that can report liveness.
type BeforeRunBuilder ¶ added in v0.9.0
type BeforeRunBuilder func(ctx context.Context, build pkgplugins.BeforeRunContext) (pkgplugins.BeforeRunResult, error)
PromptToolsBuilder returns structured prompt inventory for the active plugin host.
type BuiltinToolsFactory ¶ added in v0.11.0
BuiltinToolsFactory creates agent-specific builtin tools given a snapshot. It allows callers to inject always-on tools that depend on per-agent configuration (for example, notifications).
type ChatOption ¶
type ChatOption func(*chatOptions)
ChatOption configures a single Chat call.
func WithModel ¶
func WithModel(model string) ChatOption
WithModel overrides the model for this Chat call. If the session already has a runner with a different model, the runner is replaced.
type CompactionConfig ¶
type CompactionConfig struct {
// MaxTokens triggers compaction when the estimated token count exceeds this.
// 0 (or omitted) uses the default of 80000. Negative values disable
// automatic compaction. Manual /compact still works.
MaxTokens int `yaml:"max_tokens"`
// KeepTail is the number of recent message entries to preserve verbatim
// after compaction. Default: 20.
KeepTail int `yaml:"keep_tail"`
}
CompactionConfig controls automatic session compaction.
func (CompactionConfig) WithDefaults ¶
func (c CompactionConfig) WithDefaults() CompactionConfig
WithDefaults returns a copy with zero-value fields replaced by defaults. MaxTokens 0 -> 80000; negative values are preserved (meaning disabled).
type DBPromptParams ¶ added in v0.17.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)
KnowledgeStore pkgplugins.KnowledgeStore // optional; injects ## Knowledge section when set
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
PluginPrompts []pkgplugins.SystemPromptSection
PromptSections []pkgplugins.SystemPromptSection
Host sandbox.Host
SnapshotVersion int64 // frozen memory version for this session; 0 means current
SnapshotUpdatedAt time.Time // wall-clock time of the last snapshot advance; used to filter knowledge
}
DBPromptParams holds the parameters for building a system prompt from DB-backed config.
type Envelope ¶ added in v0.17.0
type Envelope struct {
Type string `json:"type"`
Data json.RawMessage `json:"data"`
}
Envelope wraps stream events for transport.
type Event ¶ added in v0.17.0
type Event struct {
Text string
Image *ImageEvent
File *FileEvent
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 FileEvent ¶ added in v0.17.0
type FileEvent struct {
Path string // absolute path on disk
Name string // display filename (with extension)
}
FileEvent carries a local file path to be sent to the channel.
type GoRunner ¶ added in v0.17.0
type GoRunner struct {
// contains filtered or unexported fields
}
GoRunner implements Runner by calling LLM providers directly via agent.Runner.
func NewGoRunner ¶ added in v0.17.0
func NewGoRunner(ctx context.Context, cfg GoRunnerConfig) (*GoRunner, error)
NewGoRunner creates a Go runner with built-in providers.
func (*GoRunner) Alive ¶ added in v0.17.0
Alive reports whether the runner is healthy. Delegates to the session's lifecycle state.
func (*GoRunner) Chat ¶ added in v0.17.0
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 ¶ added in v0.17.0
Close shuts down any subprocess-backed tools and the sandbox session. Guarantees cleanup of session resources regardless of state.
func (*GoRunner) LastActivity ¶ added in v0.17.0
LastActivity returns the time of the last Chat call.
func (*GoRunner) SystemPrompt ¶ added in v0.17.0
SystemPrompt returns the runner's base system prompt before per-run overrides.
type GoRunnerConfig ¶ added in v0.17.0
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)
PluginPrompts []pkgplugins.SystemPromptSection
PromptSections []pkgplugins.SystemPromptSection
ExtraTools []tools.Tool // additional tools to register
PluginTools func(context.Context, plugintools.BuildContext) []tools.Tool
SessionEnvSpecs []pkgplugins.SessionEnvSpec
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
UserID int64 // auth user ID; used for vault secret injection
VaultEnvLoader VaultEnvLoader // optional; if set, vault secrets are injected into sandbox env
TokenManager *oauth.TokenManager // optional; if set, runtime OAuth tokens are injected into sandbox env
}
GoRunnerConfig configures the Go runner.
type HandlerFunc ¶ added in v0.17.0
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 ¶ added in v0.17.0
func (f HandlerFunc) Chat(ctx context.Context, history []ai.Message, message MessageContent) <-chan Event
Chat calls f(ctx, history, message).
type ImageEvent ¶ added in v0.17.0
ImageEvent carries a base64-encoded image to be sent to the channel.
type MessageContent ¶ added in v0.17.0
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 ¶ added in v0.17.0
type NewRunnerFunc func(ctx context.Context, params RunnerParams) (Runner, error)
NewRunnerFunc creates a new Runner instance with the given params.
func NewRunnerFactory ¶ added in v0.8.0
func NewRunnerFactory(snap *config.Snapshot, builtinTools []tools.Tool, pluginToolsBuilder PluginToolsBuilder, providerRegistryBuilder func(api, apiKey, baseURL string) (*providers.Registry, error), promptToolsFn func(context.Context) ([]pkgplugins.PromptToolInfo, error), promptSectionsFn func(context.Context, pkgplugins.SystemPromptContext) ([]pkgplugins.SystemPromptSection, error), pluginPromptsFn func() []pkgplugins.SystemPromptSection, sessionPluginViewFn SessionPluginViewBuilder, toolLifecycle *coreagent.ToolLifecycle, skillStore pkgplugins.SkillStore, sandboxBackendFn func(ctx context.Context) string, vaultEnvLoader VaultEnvLoader, tokenManager *oauth.TokenManager) (NewRunnerFunc, error)
NewRunnerFactory creates a NewRunnerFunc for a given config snapshot. The returned factory creates runners scoped to one agent's provider, model, workspace, and system prompt. Memory provider, user ID, and agent ID are injected per-session from RunnerParams. Runner execution is always user-scoped, so per-user workspace directories are created for every runner instance.
Hooks are not part of the factory — they are injected via RunnerParams.HooksFn by the Pool, keeping hook lifecycle fully decoupled from model/provider config.
type PluginHooksBuilder ¶ added in v0.9.0
type PluginHooksBuilder func(ctx context.Context) []hooks.HookPlugin
PluginHooksBuilder creates hook plugins from enabled plugin state. Called at startup and on hot-reload when a hook plugin is toggled.
type PluginPromptsBuilder ¶ added in v0.18.0
type PluginPromptsBuilder func() []pkgplugins.SystemPromptSection
PromptToolsBuilder returns structured prompt inventory for the active plugin host.
type PluginToolsBuilder ¶ added in v0.9.0
type PluginToolsBuilder func(ctx context.Context, build plugintools.BuildContext) []tools.Tool
PluginToolsBuilder creates tools from enabled plugin state. Called per runner so tool builders receive the active sandbox host.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool manages a set of sessions, each with its own history and It is the only type channels interact with.
func NewPool ¶
func NewPool(factory NewRunnerFunc, mem memory.Provider, opts ...PoolOption) *Pool
NewPool creates a new Pool with the given runner factory and memory provider. The memory provider is required — it is the sole persistence layer for sessions.
func (*Pool) ActiveSession ¶
func (p *Pool) ActiveSession(channel string) (SessionInfo, bool)
ActiveSession returns the most recent non-archived session for a channel.
func (*Pool) ArchiveSession ¶
ArchiveSession marks a session as archived, closes its runner, but keeps history on disk. The session is removed from the in-memory map; its metadata persists in the index.
func (*Pool) Chat ¶
func (p *Pool) Chat(ctx context.Context, sessionID string, message MessageContent, opts ...ChatOption) <-chan Event
Chat sends a message in a session and streams back events. Internally: gets/creates runner, passes history, collects events, appends to session log, streams to caller.
func (*Pool) CompactSession ¶
CompactSession delegates compaction to the memory engine and returns the summary text on success.
func (*Pool) CreateSession ¶
func (p *Pool) CreateSession(channel string, userID ...int64) (SessionInfo, error)
CreateSession creates a new session with a generated ID and persists its metadata.
func (*Pool) GetSession ¶
func (p *Pool) GetSession(sessionID string) (SessionInfo, error)
GetSession returns metadata for a session.
func (*Pool) History ¶
History returns the message history for a session, loading from the memory provider. Returns nil if the session has no history or the provider does not support it.
func (*Pool) ListSessions ¶
func (p *Pool) ListSessions(includeArchived bool) ([]SessionInfo, error)
ListSessions returns metadata for all sessions.
func (*Pool) NeedsCompaction ¶
NeedsCompaction reports whether a session's estimated token count exceeds the compaction threshold. Returns false if compaction is disabled or the memory provider does not support compaction.
func (*Pool) ResetRunners ¶ added in v0.10.0
ResetRunners closes all live session runners but keeps session metadata and history. The next chat on each session will recreate a runner from the current factory.
func (*Pool) ResetRunnersForUser ¶ added in v0.15.0
ResetRunnersForUser closes live runners belonging to a specific user. Other sessions are not affected. The next chat for that user recreates a
func (*Pool) ResolveSession ¶
func (p *Pool) ResolveSession(channel string, userID ...int64) (SessionInfo, error)
ResolveSession returns the active session for a channel, creating one if needed. The check-and-create is atomic to prevent duplicate sessions under concurrent access. An optional userID associates the session with a user (stored in conversations table).
func (*Pool) RotateSession ¶
func (p *Pool) RotateSession(channel string, userID ...int64) (SessionInfo, error)
RotateSession archives the active session for a channel (if any) and creates a new one.
func (*Pool) SetDefaultModel ¶
SetDefaultModel updates the default model used for new runners. Call this alongside SetFactory when the user switches models at runtime.
func (*Pool) SetFactory ¶
func (p *Pool) SetFactory(factory NewRunnerFunc)
SetFactory replaces the runner factory used for new runners. Existing runners are not affected until their session is reset.
func (*Pool) SetFastModel ¶ added in v0.10.0
SetFastModel updates the fast model used for compaction and utility work.
func (*Pool) SetHooks ¶ added in v0.9.0
func (p *Pool) SetHooks(fn func() []hooks.HookPlugin)
SetHooks updates the hook getter used when creating new runners. Changing hooks never requires rebuilding the factory or resetting sessions — new runners created after this call will use the updated hooks.
func (*Pool) StartReaper ¶
StartReaper runs a background goroutine that periodically checks for idle or dead runners. It returns when ctx is cancelled.
type PoolManager ¶ added in v0.8.0
type PoolManager struct {
// contains filtered or unexported fields
}
PoolManager manages a map of agent ID to Pool. It reads enabled agents from the config Store and creates one Pool per agent.
func NewPoolManager ¶ added in v0.8.0
func NewPoolManager(store config.Store, mem memory.Provider, opts ...PoolManagerOption) *PoolManager
NewPoolManager creates a new PoolManager.
func (*PoolManager) AddBuiltinTool ¶ added in v0.15.0
AddBuiltinTool appends a tool to the shared builtin list and rebuilds all pool factories so subsequent runners see the new tool.
func (*PoolManager) Close ¶ added in v0.8.0
func (pm *PoolManager) Close() error
Close shuts down all pools and hook plugins.
func (*PoolManager) DefaultPool ¶ added in v0.8.0
func (pm *PoolManager) DefaultPool() *Pool
DefaultPool returns the first pool found in the map, or nil if empty. Useful for backward compatibility with code expecting a single pool.
func (*PoolManager) Get ¶ added in v0.8.0
func (pm *PoolManager) Get(agentID string) *Pool
Get returns the Pool for the given agent ID, or nil if not found.
func (*PoolManager) HookPlugins ¶ added in v0.9.0
func (pm *PoolManager) HookPlugins() []hooks.HookPlugin
HookPlugins returns a snapshot copy of the current enabled hook plugins. Returns a copy so callers cannot mutate or alias the internal slice.
func (*PoolManager) InvalidateUser ¶ added in v0.15.0
func (pm *PoolManager) InvalidateUser(userID int64) error
InvalidateUser closes all live runners for userID across all pools. Satisfies the credentials.RunnerInvalidator interface.
func (*PoolManager) ReloadPluginHooks ¶ added in v0.9.0
func (pm *PoolManager) ReloadPluginHooks(ctx context.Context) error
ReloadPluginHooks rebuilds the hook plugin set from current plugin state and propagates it to every pool. No factory rebuild is needed — hooks live on the Pool and are injected via RunnerParams at runner-creation time.
func (*PoolManager) ReloadPluginProviders ¶ added in v0.9.0
func (pm *PoolManager) ReloadPluginProviders(ctx context.Context) error
ReloadPluginProviders rebuilds the runner factory for every pool so new sessions pick up changed provider credentials or enabled state. Provider creds are resolved from the Snapshot at factory-build time, so a simple factory rebuild is sufficient.
func (*PoolManager) ReloadPluginTools ¶ added in v0.9.0
func (pm *PoolManager) ReloadPluginTools(ctx context.Context) error
ReloadPluginTools updates the runner factory for every pool. Plugin tools are built per runner so builders can receive the active sandbox host.
func (*PoolManager) SetOAuthRegistry ¶ added in v0.16.0
func (pm *PoolManager) SetOAuthRegistry(r *oauth.ProviderRegistry)
SetOAuthRegistry wires the provider registry into the pool manager. When a vault env loader is later set, the constructed TokenManager also receives the registry so runners can resolve oauth.* session env sources.
func (*PoolManager) SetVaultEnvLoader ¶ added in v0.15.0
func (pm *PoolManager) SetVaultEnvLoader(ctx context.Context, v VaultEnvLoader)
SetVaultEnvLoader sets the vault env loader and rebuilds all pool factories so existing pools pick up the loader. Must be called after StartAll. If vs also satisfies oauth.VaultStore, a TokenManager is constructed and wired into the pool manager so runners can inject runtime OAuth tokens.
func (*PoolManager) StartAll ¶ added in v0.8.0
func (pm *PoolManager) StartAll(ctx context.Context) error
StartAll reads enabled agents from the store, creates a Pool per agent with per-agent runner factory, and starts reapers.
func (*PoolManager) SyncAgent ¶ added in v0.10.0
func (pm *PoolManager) SyncAgent(ctx context.Context, agentID string) error
SyncAgent reloads one agent's pool configuration immediately. If the agent was deleted or disabled, its pool is closed and removed. If it exists and is enabled, an existing pool is rebuilt and its live session runners are reset so subsequent requests use the latest snapshot.
type PoolManagerOption ¶ added in v0.8.0
type PoolManagerOption func(*PoolManager)
PoolManagerOption configures a PoolManager.
func WithBeforeRunBuilderPM ¶ added in v0.9.0
func WithBeforeRunBuilderPM(b BeforeRunBuilder) PoolManagerOption
func WithBuiltinTools ¶ added in v0.11.0
func WithBuiltinTools(tools []tools.Tool) PoolManagerOption
WithBuiltinTools sets the always-on builtin tools available to all agents.
func WithBuiltinToolsFactory ¶ added in v0.11.0
func WithBuiltinToolsFactory(f BuiltinToolsFactory) PoolManagerOption
WithBuiltinToolsFactory sets the function that creates per-agent builtin tools.
func WithCompactionPM ¶ added in v0.8.0
func WithCompactionPM(cfg CompactionConfig) PoolManagerOption
WithCompactionPM sets the compaction config for all pools.
func WithIdleTimeoutPM ¶ added in v0.8.0
func WithIdleTimeoutPM(d time.Duration) PoolManagerOption
WithIdleTimeoutPM sets the idle timeout for all pools.
func WithPluginHooksBuilder ¶ added in v0.9.0
func WithPluginHooksBuilder(b PluginHooksBuilder) PoolManagerOption
WithPluginHooksBuilder sets the function that builds hooks from plugin state.
func WithPluginPromptsBuilder ¶ added in v0.18.0
func WithPluginPromptsBuilder(b PluginPromptsBuilder) PoolManagerOption
func WithPluginToolsBuilder ¶ added in v0.9.0
func WithPluginToolsBuilder(b PluginToolsBuilder) PoolManagerOption
WithPluginToolsBuilder sets the function that builds tools from plugin state.
func WithPromptSectionsBuilder ¶ added in v0.9.0
func WithPromptSectionsBuilder(b PromptSectionsBuilder) PoolManagerOption
func WithPromptToolsBuilder ¶ added in v0.9.0
func WithPromptToolsBuilder(b PromptToolsBuilder) PoolManagerOption
WithPromptToolsBuilder sets the function that returns prompt inventory items.
func WithProviderRegistryBuilder ¶ added in v0.9.0
func WithProviderRegistryBuilder(b ProviderRegistryBuilder) PoolManagerOption
func WithSessionPluginViewBuilder ¶ added in v0.16.0
func WithSessionPluginViewBuilder(b SessionPluginViewBuilder) PoolManagerOption
func WithSkillStore ¶ added in v0.13.0
func WithSkillStore(s pkgplugins.SkillStore) PoolManagerOption
WithSkillStore sets the skill store for runner factories.
func WithTokenManager ¶ added in v0.15.0
func WithTokenManager(tm *oauth.TokenManager) PoolManagerOption
WithTokenManager sets the OAuth token manager for runtime token injection.
func WithToolLifecyclePM ¶ added in v0.9.0
func WithToolLifecyclePM(tl *coreagent.ToolLifecycle) PoolManagerOption
func WithVaultEnvLoader ¶ added in v0.15.0
func WithVaultEnvLoader(v VaultEnvLoader) PoolManagerOption
WithVaultEnvLoader sets the vault env loader for sandbox secret injection.
type PoolOption ¶
type PoolOption func(*Pool)
PoolOption configures a Pool.
func WithAgentID ¶ added in v0.8.0
func WithAgentID(id string) PoolOption
WithAgentID sets the agent ID this pool belongs to.
func WithBeforeRunBuilder ¶ added in v0.9.0
func WithBeforeRunBuilder(b BeforeRunBuilder) PoolOption
WithBeforeRunBuilder sets the per-run lifecycle hook builder used by the pool.
func WithCompaction ¶
func WithCompaction(cfg CompactionConfig) PoolOption
WithCompaction sets the compaction configuration.
func WithDefaultModel ¶
func WithDefaultModel(model string) PoolOption
WithDefaultModel sets the default model ID for new runners.
func WithFastModel ¶
func WithFastModel(model string) PoolOption
WithFastModel sets the model ID used for compaction and other fast tasks.
func WithIdleTimeout ¶
func WithIdleTimeout(d time.Duration) PoolOption
WithIdleTimeout sets the idle timeout for reaping runners.
func WithSnapshotPromptBuilder ¶ added in v0.18.0
func WithSnapshotPromptBuilder(fn func(ctx context.Context, userID int64, agentID string, snap memory.SessionSnapshot) string) PoolOption
WithSnapshotPromptBuilder sets the function used to build per-turn system prompts from a frozen snapshot version. When set, the pool calls this on every Chat to produce a stable system prompt for the session's snapshot version.
type PromptSectionsBuilder ¶ added in v0.9.0
type PromptSectionsBuilder func(ctx context.Context, build pkgplugins.SystemPromptContext) ([]pkgplugins.SystemPromptSection, error)
PromptToolsBuilder returns structured prompt inventory for the active plugin host.
type PromptToolsBuilder ¶ added in v0.9.0
type PromptToolsBuilder func(ctx context.Context) ([]pkgplugins.PromptToolInfo, error)
PromptToolsBuilder returns structured prompt inventory for the active plugin host.
type ProviderRegistryBuilder ¶ added in v0.9.0
PromptToolsBuilder returns structured prompt inventory for the active plugin host.
type Runner ¶ added in v0.17.0
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.17.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 Session ¶
type Session struct {
Info SessionInfo
Runner Runner
Model string // model ID the current runner was created with
}
Session holds the state of a single conversation: metadata and the currently assigned Message persistence is handled by the memory engine exclusively.
type SessionInfo ¶
type SessionInfo = memory.SessionInfo
SessionInfo is an alias for memory.SessionInfo.
type SessionPluginViewBuilder ¶ added in v0.16.0
type SessionPluginViewBuilder func(ctx context.Context) (pkgplugins.SessionPluginView, error)
PromptToolsBuilder returns structured prompt inventory for the active plugin host.
type Stateful ¶ added in v0.17.0
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.17.0
type SystemPrompter interface {
SystemPrompt() string
}
SystemPrompter is an optional interface for runners that expose their base system prompt.
type ToolUseEvent ¶ added in v0.17.0
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.
type VaultEnvLoader ¶ added in v0.17.0
type VaultEnvLoader interface {
LoadEnv(ctx context.Context, userID int64) (map[string]string, error)
}
VaultEnvLoader loads decrypted vault entries for a user as a name→value map. It is a subset of vault.Service and is defined here to avoid a circular import between the runner and vault packages.