Documentation
¶
Index ¶
- type AgentErrored
- type AgentFinished
- type AgentStarted
- type AssistantDelta
- type AssistantFinished
- type AssistantStarted
- type LoopEvent
- type Option
- type Runner
- type RunnerConfig
- type ToolCallContext
- type ToolCallMutation
- type ToolFinished
- type ToolFunc
- type ToolLifecycle
- type ToolResultContext
- type ToolResultMutation
- type ToolSet
- type ToolStarted
- type TurnFinished
- type TurnStarted
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentErrored ¶
type AgentErrored struct {
Err error
}
AgentErrored is emitted for terminal loop errors.
func (AgentErrored) Kind ¶
func (AgentErrored) Kind() string
type AgentFinished ¶
type AgentFinished struct{}
AgentFinished is emitted when loop completes.
func (AgentFinished) Kind ¶
func (AgentFinished) Kind() string
type AgentStarted ¶
type AgentStarted struct{}
AgentStarted is emitted when a loop begins.
func (AgentStarted) Kind ¶
func (AgentStarted) Kind() string
type AssistantDelta ¶
type AssistantDelta struct {
Event ai.AssistantEvent
Message ai.AssistantMessage
}
AssistantDelta forwards an incremental provider event with the current partial message.
func (AssistantDelta) Kind ¶
func (AssistantDelta) Kind() string
type AssistantFinished ¶
type AssistantFinished struct {
Message ai.AssistantMessage
}
AssistantFinished is emitted when the final assistant message is assembled.
func (AssistantFinished) Kind ¶
func (AssistantFinished) Kind() string
type AssistantStarted ¶
type AssistantStarted struct {
Message ai.AssistantMessage
}
AssistantStarted is emitted when assistant streaming begins.
func (AssistantStarted) Kind ¶
func (AssistantStarted) Kind() string
type LoopEvent ¶
type LoopEvent interface {
Kind() string
}
LoopEvent is the runtime event contract emitted by the agent loop.
type Option ¶
type Option func(*Runner)
Option configures optional Runner fields.
func WithInterrupt ¶
func WithInterrupt(ch <-chan struct{}) Option
WithInterrupt sets an interrupt channel to stop the loop.
func WithMaxTurns ¶
WithMaxTurns sets the maximum number of loop turns.
func WithStreamOptions ¶
func WithStreamOptions(opts ai.StreamOptions) Option
WithStreamOptions sets stream options (API key, base URL, etc.).
func WithToolLifecycle ¶
func WithToolLifecycle(tl *ToolLifecycle) Option
WithToolLifecycle sets optional tool lifecycle hooks for the loop.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner is a configured agent loop executor. It is safe for concurrent use. All configuration is set at construction time via RunnerConfig + options.
func NewRunner ¶
func NewRunner(cfg RunnerConfig, opts ...Option) (*Runner, error)
NewRunner constructs a Runner with the given config and options.
func (*Runner) Continue ¶
func (r *Runner) Continue(ctx context.Context, messages []ai.Message, emit func(LoopEvent)) ([]ai.Message, error)
Continue validates the history tail and resumes the agent loop.
func (*Runner) Run ¶
func (r *Runner) Run(ctx context.Context, messages []ai.Message, emit func(LoopEvent)) ([]ai.Message, error)
Run executes the agent loop from scratch.
func (*Runner) SetHookMeta ¶
SetHookMeta updates the hook metadata (session/agent/user context). Safe to call between Run invocations; not safe during a Run.
type RunnerConfig ¶
type RunnerConfig struct {
Providers providers.ProviderGetter
Model ai.Model
Tools ToolSet
ToolDefinitions []ai.ToolDefinition
}
RunnerConfig holds the required fields for constructing a Runner.
type ToolCallContext ¶
type ToolCallContext struct {
SessionID string
Channel string
UserID int64
AgentID string
ToolName string
ToolCallID string
Arguments map[string]any
}
ToolCallContext describes one tool call before execution.
type ToolCallMutation ¶
ToolCallMutation describes how a pre-tool lifecycle hook changes execution.
type ToolFinished ¶
type ToolFinished struct {
Result ai.ToolResultMessage
}
ToolFinished is emitted when tool returns.
func (ToolFinished) Kind ¶
func (ToolFinished) Kind() string
type ToolLifecycle ¶
type ToolLifecycle struct {
BeforeCall func(ctx context.Context, call ToolCallContext) (ToolCallMutation, error)
AfterCall func(ctx context.Context, result ToolResultContext) (ToolResultMutation, error)
}
ToolLifecycle carries optional tool-call lifecycle hooks for the agent loop.
type ToolResultContext ¶
type ToolResultContext struct {
SessionID string
Channel string
UserID int64
AgentID string
ToolName string
ToolCallID string
Arguments map[string]any
Result string
IsError bool
Duration time.Duration
}
ToolResultContext describes one completed tool call.
type ToolResultMutation ¶
ToolResultMutation describes how a post-tool lifecycle hook changes the final result.
type ToolSet ¶
ToolSet maps tool names to handlers.
func ToolSetFromRegistry ¶
ToolSetFromRegistry builds a ToolSet from a tools.Registry. Every registered tool is included. The returned ToolSet dispatches calls through the registry's Execute method.
func ToolSetFromRegistryFiltered ¶
func ToolSetFromRegistryFiltered(reg *tools.Registry, names []string) (ToolSet, []tools.Definition, error)
ToolSetFromRegistryFiltered builds a ToolSet including only the named tools. Returns the matching definitions and an error if any name is not found.
type ToolStarted ¶
ToolStarted is emitted for each tool invocation.
func (ToolStarted) Kind ¶
func (ToolStarted) Kind() string
type TurnFinished ¶
type TurnFinished struct {
Turn int
}
TurnFinished is emitted at the end of each loop turn.
func (TurnFinished) Kind ¶
func (TurnFinished) Kind() string
type TurnStarted ¶
type TurnStarted struct {
Turn int
}
TurnStarted is emitted at the start of each loop turn.
func (TurnStarted) Kind ¶
func (TurnStarted) Kind() string