engine

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteToolCalls

func ExecuteToolCalls(ctx context.Context, calls []ai.ToolCall, tools ToolSet, cb ToolCallbacks) ([]ai.ToolResultMessage, error)

ExecuteToolCalls runs each tool call in order and returns result messages.

Types

type AfterToolCallEvent added in v0.7.0

type AfterToolCallEvent struct {
	ToolName string `json:"toolName"`
	Result   string `json:"result"`
	IsError  bool   `json:"isError"`
}

AfterToolCallEvent is passed to after_tool_call hooks.

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 BeforeToolCallEvent added in v0.7.0

type BeforeToolCallEvent struct {
	ToolName  string         `json:"toolName"`
	Arguments map[string]any `json:"arguments"`
}

BeforeToolCallEvent is passed to before_tool_call hooks.

type Engine

type Engine struct {
	Providers ai.ProviderGetter
}

Engine coordinates model generation and tool execution.

func (*Engine) Continue

func (e *Engine) Continue(ctx context.Context, cfg LoopConfig, history []ai.Message, emit func(LoopEvent)) ([]ai.Message, error)

Continue validates that the transcript tail is a user or tool-result message and resumes the agent loop from the existing history.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context, cfg LoopConfig, history []ai.Message, emit func(LoopEvent)) ([]ai.Message, error)

Run executes the agent loop: repeatedly generating assistant responses and executing tool calls until the model stops calling tools, the turn limit is reached, or an interrupt/error occurs.

type LoopConfig

type LoopConfig struct {
	Model           ai.Model
	StreamOptions   ai.StreamOptions
	MaxTurns        int
	Tools           ToolSet
	ToolDefinitions []toolspec.Definition
	System          string
	Interrupt       <-chan struct{}
	PluginHooks     PluginHookRunner // optional plugin lifecycle hooks
}

LoopConfig configures the agent loop behavior.

type LoopEvent

type LoopEvent interface {
	Kind() string
}

LoopEvent is the runtime event contract emitted by the agent loop.

type PluginHookRunner added in v0.7.0

type PluginHookRunner interface {
	RunHooks(ctx context.Context, event string, data any) error
}

PluginHookRunner executes plugin lifecycle hooks. Defined as an interface here so the engine package does not import internal/plugin.

type SessionEvent added in v0.7.0

type SessionEvent struct {
	SessionID string `json:"sessionId"`
	Channel   string `json:"channel"`
}

SessionEvent is passed to session_start and session_end hooks.

type ToolCallbacks

type ToolCallbacks struct {
	OnStart     func(call ai.ToolCall)
	OnFinish    func(result ai.ToolResultMessage)
	PluginHooks PluginHookRunner // optional plugin lifecycle hooks
}

ToolCallbacks emits progress events around tool execution.

type ToolFinished

type ToolFinished struct {
	Result ai.ToolResultMessage
}

ToolFinished is emitted when tool returns.

func (ToolFinished) Kind

func (ToolFinished) Kind() string

type ToolFunc

type ToolFunc func(ctx context.Context, call ai.ToolCall) (ai.TextContent, error)

ToolFunc executes one tool invocation.

type ToolSet

type ToolSet map[string]ToolFunc

ToolSet maps tool names to handlers.

type ToolStarted

type ToolStarted struct {
	ToolCall ai.ToolCall
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL