Documentation
¶
Overview ¶
Package engine is the loop itself. Start at Run.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Deps ¶
type Deps struct {
Model model.ToolCallingChatModel
Caller ModelCaller
Tools ToolDispatcher
Stop StopPolicy
Finish *Finisher
StopInstructions string
Inbox Inbox
Compactor HistoryCompactor
State *state.Run
Emitter *emitter.Emitter
Audit *audit.Recorder
Transcript *transcript.Logger
Logger *slog.Logger
TotalTimeout time.Duration
Reviewer Reviewer
MaxReopens int // finishes re-opened after a failed finish review
}
Deps is everything an Engine works with. wire.go fills it. State, emitter, audit and transcript are concrete: each has one implementation.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) ConfigChanged ¶
func (e *Engine) ConfigChanged()
ConfigChanged reports a settings change; the inbox has already applied it.
func (*Engine) Run ¶
Run is the loop. loop.Loop.Start runs it as its own goroutine (1). Each model call may add two short-lived goroutines inside modelcall (2: the stream reader, 3: the iteration-timeout watcher); both end when that call returns. Run always ends through Finisher.Close, which closes the event channel.
func (*Engine) Seed ¶
Seed returns the conversation the run starts from: messages plus the stop instructions, placed after the caller's own system messages. Providers such as Anthropic accept system messages only before the first user message. A conversation that already has them, such as a resumed run, is returned unchanged.
type Finisher ¶
type Finisher struct {
// contains filtered or unexported fields
}
Finisher ends a run. Every way a run can end goes through it, and the emitter delivers only the first done event, so a run has one outcome. It also implements dispatch.Ender.
func NewFinisher ¶
func (*Finisher) Close ¶
func (f *Finisher) Close()
Close runs when Engine.Run returns, whatever path ended it: it makes sure a done event exists, settles the status and closes the event channel.
func (*Finisher) Done ¶
func (f *Finisher) Done(reason event.DoneReason, finalContent string)
Done ends the run for reason.
func (*Finisher) EndAwaitingHuman ¶
func (f *Finisher) EndAwaitingHuman(awaiting event.AwaitingInputData)
EndAwaitingHuman ends the run so a person can answer later.
func (*Finisher) EndStopped ¶
func (f *Finisher) EndStopped()
EndStopped ends the run because it was told to stop.
type HistoryCompactor ¶
HistoryCompactor shapes the history sent to the model; the stored history is not changed. → the caller's loop.HistoryCompactor, or defaults.FullHistory
type ModelCaller ¶
type ModelCaller interface {
Call(ctx context.Context, m model.ToolCallingChatModel, msgs []*schema.Message, opts ...model.Option) (*schema.Message, error)
}
ModelCaller makes one logical model call. → internal/modelcall
type Reviewer ¶
type Reviewer interface {
// AfterIteration judges one iteration's messages against the task.
AfterIteration(ctx context.Context, task, iteration []*schema.Message) (reflection.Verdict, error)
// AtFinish judges the final answer against the task.
AtFinish(ctx context.Context, task []*schema.Message, answer string) (reflection.Verdict, error)
}
Reviewer is the run's reflection policy, chosen once in wire.go. Each method returns the zero Verdict when it does not review. → internal/reflection
type StopPolicy ¶
type StopPolicy interface {
Label() string
// Instructions returns the instructions for the stop condition.
Instructions() string
// FinishCall returns the call that ends the run, when the reply has one.
FinishCall(reply *schema.Message) (schema.ToolCall, bool)
// AfterText says whether a text-only reply ends the run, and what
// message, if any, to send the model when it does not.
AfterText() (ends bool, nudge string)
}
StopPolicy is the run's stop condition, chosen once in wire.go. → internal/stopping