Documentation
¶
Overview ¶
Package runtime executes agent conversations in already-resolved sessions.
The only entry point for callers is Runtime.Chat. Callers must obtain a validated session.Info from session.Registry before calling Chat. Runtime never creates or repairs session metadata.
Index ¶
- Variables
- func MessageText(message MessageContent) string
- type BeforeRunFunc
- type CompactionConfig
- type Config
- type Event
- type FileEvent
- type ImageEvent
- type MessageContent
- type NewRunnerFunc
- type Option
- type Runner
- type RunnerParams
- type Runtime
- func (rt *Runtime) Chat(ctx context.Context, info session.Info, msg MessageContent, opts ...Option) <-chan Event
- func (rt *Runtime) Close() error
- func (rt *Runtime) CloseSession(_ context.Context, sessionID string) error
- func (rt *Runtime) Factory() NewRunnerFunc
- func (rt *Runtime) Memory() memory.Provider
- func (rt *Runtime) ResetRunners() error
- func (rt *Runtime) ResetRunnersForUser(userID string) error
- func (rt *Runtime) SetDefaultModel(model string)
- func (rt *Runtime) SetDelegateRunner(r delegatetool.SessionRunner)
- func (rt *Runtime) SetFactory(f NewRunnerFunc)
- func (rt *Runtime) SetHooks(fn func() []hooks.HookPlugin)
- func (rt *Runtime) StartReaper(ctx context.Context)
- type SnapshotPromptFunc
- type StepEvent
- type ToolUseEvent
Constants ¶
This section is empty.
Variables ¶
var ErrChatTimeout = agenterr.ErrChatTimeout
ErrChatTimeout is emitted when a chat turn exceeds its deadline.
var ErrSessionBusy = agenterr.ErrSessionBusy
ErrSessionBusy is returned when a session already has an active chat turn.
Functions ¶
func MessageText ¶
func MessageText(message MessageContent) string
MessageText extracts and joins all text from a MessageContent.
Types ¶
type BeforeRunFunc ¶
type BeforeRunFunc func(ctx context.Context, info session.Info, model, msgText, system string, history []ai.Message) (systemOut string, err error)
BeforeRunFunc is called before each chat turn to inject/override the system prompt.
type CompactionConfig ¶
CompactionConfig controls automatic compaction thresholds.
func (CompactionConfig) WithDefaults ¶
func (c CompactionConfig) WithDefaults() CompactionConfig
WithDefaults returns the config with zero values replaced by defaults.
type Config ¶
type Config struct {
Factory NewRunnerFunc
Memory memory.Provider
IdleTimeout time.Duration
Compaction CompactionConfig
DefaultModel string
FastModel string
HooksFn func() []hooks.HookPlugin
BeforeRun BeforeRunFunc
SnapshotPrompt SnapshotPromptFunc
}
Config holds all dependencies for a Runtime instance.
type Event ¶
type Event struct {
Text string
Reasoning string
Image *ImageEvent
File *FileEvent
ToolUse *ToolUseEvent
Step *StepEvent
Store ai.Message // non-nil → append to session history
Err error
}
Event is the consumer-facing stream event.
type ImageEvent ¶
ImageEvent carries a base64-encoded image.
type MessageContent ¶
type MessageContent = any
MessageContent is a user message: string (text) or []ai.ContentBlock (multimodal).
type NewRunnerFunc ¶
type NewRunnerFunc func(ctx context.Context, params RunnerParams) (Runner, error)
NewRunnerFunc creates a new Runner with the given params.
type Option ¶
type Option func(*chatOptions)
Option configures a single Chat call.
func WithExcludedTools ¶
WithExcludedTools hides the named tools for this Chat call.
func WithSystemOverride ¶
WithSystemOverride overrides the system prompt for this Chat call.
type Runner ¶
type Runner interface {
Chat(ctx context.Context, history []ai.Message, message MessageContent) <-chan Event
Alive() bool
Busy() bool
LastActivity() time.Time
SystemPrompt() string
Close() error
}
Runner executes prompts against an AI backend.
type RunnerParams ¶
type RunnerParams struct {
Model string
Memory any // memory.Provider — typed as any to avoid circular imports
UserID string
SessionID string
AgentID string
ProjectID string
HooksFn func() []hooks.HookPlugin
ExtraTools []tools.Tool
DelegateRunner delegatetool.SessionRunner
}
RunnerParams holds dependencies for creating a new Runner.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime executes agent conversations in already-resolved sessions. It owns the runner cache, runner factory, and event streaming. It does NOT own session creation, kind validation, or list/archive APIs.
func (*Runtime) Chat ¶
func (rt *Runtime) Chat(ctx context.Context, info session.Info, msg MessageContent, opts ...Option) <-chan Event
Chat executes a user message inside the given session and streams events back. info must have been obtained from session.Registry — this method does not create or repair session metadata.
Only one active turn per session is allowed. A second concurrent Chat on the same session returns ErrSessionBusy immediately.
func (*Runtime) CloseSession ¶
CloseSession closes the runner for a single session without affecting others.
func (*Runtime) Factory ¶
func (rt *Runtime) Factory() NewRunnerFunc
Factory returns the current runner factory. Used by the task system to create standalone runners with custom tools.
func (*Runtime) ResetRunners ¶
ResetRunners closes all live runners while keeping session metadata in storage.
func (*Runtime) ResetRunnersForUser ¶
ResetRunnersForUser closes live runners for a specific user.
func (*Runtime) SetDefaultModel ¶
SetDefaultModel updates the default model for new runners.
func (*Runtime) SetDelegateRunner ¶
func (rt *Runtime) SetDelegateRunner(r delegatetool.SessionRunner)
SetDelegateRunner wires the delegate session runner into new runners. Call after construction so runners can spawn persistent child sessions.
func (*Runtime) SetFactory ¶
func (rt *Runtime) SetFactory(f NewRunnerFunc)
SetFactory replaces the runner factory. Existing runners are not affected until their session is next reused.
func (*Runtime) SetHooks ¶
func (rt *Runtime) SetHooks(fn func() []hooks.HookPlugin)
SetHooks updates the hook getter used when creating new runners.
func (*Runtime) StartReaper ¶
StartReaper begins the idle-runner eviction loop. Call in a goroutine.
type SnapshotPromptFunc ¶
type SnapshotPromptFunc func(ctx context.Context, info session.Info, snap memory.SessionSnapshot) string
SnapshotPromptFunc builds a system prompt from the session's snapshot version.