Documentation
¶
Overview ¶
Adapted from Goose ee8500d5 and 14741e9a (Apache-2.0). See ../model/LICENSE.goose.
Package engine owns ordered turn execution and its committed effects.
Index ¶
- func CountedTool(tools []Tool, name string) (telemetry.Tool, bool)
- func ForegroundToolContext(ctx, operation context.Context) context.Context
- func MCPToolName(server, tool string) string
- func Steered(ctx context.Context) bool
- type Options
- type Runtime
- func (r *Runtime) BeginOperation(turn protocol.TurnID) (context.Context, func(), bool)
- func (r *Runtime) BeginStop()
- func (r *Runtime) CommandPython(ctx context.Context, turn protocol.TurnID) (*python.Execution, error)
- func (r *Runtime) Committed()
- func (r *Runtime) Elicit(ctx context.Context, turn protocol.TurnID, parent canonical.ToolRequest, ...) (*sdk.ElicitResult, error)
- func (r *Runtime) GuidanceSignal(turn protocol.TurnID) <-chan struct{}
- func (r *Runtime) LockDecision(command protocol.Command) func()
- func (r *Runtime) LockPublication() func()
- func (r *Runtime) OperationContext(turn protocol.TurnID) (context.Context, bool)
- func (r *Runtime) QueueCommitted(update protocol.ConversationQueueUpdate, ...)
- func (r *Runtime) RecordMediaUsage(ctx context.Context, session protocol.SessionID, turn protocol.TurnID, ...) error
- func (r *Runtime) RecordSearchUsage(ctx context.Context, session protocol.SessionID, turn protocol.TurnID, ...) error
- func (r *Runtime) Recover(ctx context.Context) error
- func (r *Runtime) Refresh(session protocol.SessionID)
- func (r *Runtime) RefreshCommitted(session protocol.SessionID, changedChildren ...protocol.TurnID)
- func (r *Runtime) RefreshStatistics(session protocol.SessionID)
- func (r *Runtime) RefreshStatisticsCommitted(session protocol.SessionID)
- func (r *Runtime) RequestStatisticsCommitted(session protocol.SessionID)
- func (r *Runtime) Start()
- func (r *Runtime) Stop()
- func (r *Runtime) StopCommitted(run protocol.ConversationRun)
- func (r *Runtime) Wake()
- type Tool
- type ToolResult
- type ToolResultReader
- type TurnObservation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountedTool ¶
CountedTool is how a call of one of a turn's registered tools is counted. A name the turn did not register is not counted. A tool without a package binding was registered by the Node itself and is a built-in under its registered name, unless telemetry.UncountedBuiltins leaves it out. A package's tool is named only when its owner is a package the application ships (operations.Official); a connected server's tool and any other package's tool are counted without a name.
func ForegroundToolContext ¶ added in v0.2.7
ForegroundToolContext lets a command observe steering only during foreground execution. Its preparation and durable receipts use the operation owner.
func MCPToolName ¶
MCPToolName is the name an MCP tool is offered under when it is unique.
Types ¶
type Options ¶
type Options struct {
Python *python.Manager
ValidateWorktree func(context.Context, protocol.WorktreeID) error
Attachment func(context.Context, protocol.TurnID, protocol.AttachmentID) (protocol.Attachment, bool, error)
AttachmentBytes func(context.Context, protocol.Attachment) ([]byte, error)
Clock clock.Clock
Model func(context.Context, model.Binding) (fantasy.LanguageModel, error)
AuthorizeProvider func(context.Context, *store.AgentInvocation) error
Tools []Tool
ToolsForTurn func(context.Context, *store.AgentInvocation) ([]Tool, error)
HooksForTurn func(context.Context, *store.AgentInvocation) *hooks.Binding
// AfterTurn, when set, runs after a main task turn's end is stored. It
// receives the settled run and what the execution observed.
AfterTurn func(context.Context, *store.AgentInvocation, protocol.ConversationRun, TurnObservation)
Telemetry *telemetry.Control
// Working, when set, brackets every running turn.
Working func() func()
// StopCommands, when set, stops a session's background commands. The
// engine calls it for a child session whose run has ended.
StopCommands func(protocol.SessionID)
// StopTransient, when set, stops a session's non-service background
// commands. The engine calls it once a durable stop of the session's
// running turn commits: a user stop, Send now or a disabled package.
StopTransient func(protocol.SessionID)
}
Options exposes the actual model and clock boundaries to deterministic tests.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
func (*Runtime) BeginOperation ¶
BeginOperation and drainOperations share the execution lock, sealing admission before terminal history is committed and waiting for already admitted effects.
func (*Runtime) BeginStop ¶ added in v0.2.7
func (r *Runtime) BeginStop()
BeginStop interrupts turns before the Node cancels their dependencies. Stop joins their settlement after the command lanes have released their locks.
func (*Runtime) CommandPython ¶
func (*Runtime) Committed ¶
func (r *Runtime) Committed()
Committed wakes owners only after a controller transaction has committed. The durable queue remains the sole source of admitted work.
func (*Runtime) Elicit ¶
func (r *Runtime) Elicit(ctx context.Context, turn protocol.TurnID, parent canonical.ToolRequest, request *sdk.ElicitRequest) (*sdk.ElicitResult, error)
func (*Runtime) GuidanceSignal ¶
func (*Runtime) LockDecision ¶
LockDecision claims the owner before a decision transaction can wait for COMMIT. Expiry uses the same owner, so it cannot overtake a claimed answer.
func (*Runtime) LockPublication ¶
func (r *Runtime) LockPublication() func()
LockPublication orders commits, their frames and pinned controller snapshots. Acquire decision ownership first; acquire storage leases only after this lock.
func (*Runtime) OperationContext ¶
OperationContext borrows a running turn's cancellation owner. The caller must finish its admitted effect before returning to the loop or closing the Node.
func (*Runtime) QueueCommitted ¶ added in v0.2.7
func (r *Runtime) QueueCommitted(update protocol.ConversationQueueUpdate, selection *protocol.CommandGuideQueuedTurnPayload)
QueueCommitted reconciles steering against the durable queue under publication.
func (*Runtime) RecordMediaUsage ¶
func (r *Runtime) RecordMediaUsage(ctx context.Context, session protocol.SessionID, turn protocol.TurnID, provider protocol.ConversationProvider, name string, kind protocol.MediaKind, usage canonical.Usage) error
RecordMediaUsage records one media call under the provider and model that actually ran it, after cancellation as well.
func (*Runtime) RecordSearchUsage ¶
func (r *Runtime) RecordSearchUsage(ctx context.Context, session protocol.SessionID, turn protocol.TurnID, provider protocol.ConversationProvider, name string, usage canonical.Usage) error
RecordSearchUsage completes the billed response append after cancellation.
func (*Runtime) Recover ¶
Recover closes interrupted owners and holds every surviving queue. It never replays a model request or an external tool operation.
func (*Runtime) RefreshCommitted ¶
RefreshCommitted publishes a pinned metadata read while its caller owns publication, so no newer interaction or queue can overtake the read.
func (*Runtime) RefreshStatistics ¶
RefreshStatistics coalesces committed changes under the Node lifetime. A read made dirty by a later change cannot replace that change's controller state.
func (*Runtime) RefreshStatisticsCommitted ¶
RefreshStatisticsCommitted follows this commit's frames under publication.
func (*Runtime) RequestStatisticsCommitted ¶
RequestStatisticsCommitted fences the new reservation's snapshot. An older flight may predate writes made after the last observer closed, when metadata and policy changes need not have scheduled statistics.
func (*Runtime) StopCommitted ¶ added in v0.2.3
func (r *Runtime) StopCommitted(run protocol.ConversationRun)
StopCommitted delivers a durable Stop before projecting the changed history. The caller holds the publication lock, so the turn cannot finish or be replaced between this decision and cancellation of its owned work.
type Tool ¶
type Tool struct {
Definition fantasy.FunctionTool
SchemaJSON json.RawMessage
ReadOnly bool
Concurrent bool
Deferred bool
Delegation bool
Approval bool
// Confirm reports whether one prepared call of a tool without Approval
// asks first: a read-only tool with an optional project write.
Confirm func(canonical.ToolRequest) bool
Binding *store.ApprovalBinding
Execute func(context.Context, canonical.ToolRequest) ToolResult
Prepare func(context.Context, canonical.ToolRequest) error
// ReleasePrepared drops transient preparation even when the call never
// reaches Execute. It is safe to call after Execute has consumed it.
ReleasePrepared func(canonical.ToolRequest)
ObserveHistory func([]canonical.Record)
ConfigureApproval func(context.Context, *sql.Conn, canonical.ToolRequest, protocol.ConversationApproval) (protocol.ConversationApproval, error)
Approved func(canonical.ToolRequest, protocol.ApprovalID, protocol.RequestID)
Close func() error
Instruction string
TurnInstruction prompt.Part
ContextParts []string
BeforeModel func(context.Context, []canonical.Record, ToolResultReader) (bool, error)
BindDelegation func(Tool) Tool
// Guidance makes BindDelegation receive guide_agent instead of spawn_agent.
Guidance bool
// Hosted marks a package tool whose script runs with neither a bound
// operation nor a flow, within the package's declared actions. Flow lists
// the operations a flow tool may run. A child without a tool list keeps
// such tools by these declarations.
Hosted bool
Flow []protocol.ToolOperation
// Exposed is the name an MCP tool is offered under when no other tool
// owns it. A package tool is offered under its declared name.
Exposed string
// SearchLabels are the captured display labels and translations used only
// for discovery. They do not enlarge the model's tool declarations.
SearchLabels []string
// ExecutePrepared runs a call with arguments a package prepared. The call
// keeps the identity the model sent; the arguments are what executes.
ExecutePrepared func(context.Context, canonical.ToolRequest, json.RawMessage) ToolResult
// contains filtered or unexported fields
}
Tool is one captured declaration and executor. Concurrency and authority are properties of the captured registration, never arguments supplied by a model.
type ToolResult ¶
type ToolResult struct {
Collect *collectedChild
Meta *map[string]json.RawMessage
ReturnedFailure *protocol.ToolFailure
ReturnedError bool
Value any
Format canonical.ToolFormat
Error bool
Failure *protocol.Fault
Context *canonical.Context
// Attachments are stored assets shown with the result and never sent to
// the model.
Attachments []canonical.Attachment
}
type ToolResultReader ¶ added in v0.2.4
type ToolResultReader func(*canonical.ToolResponse) (json.RawMessage, error)
ToolResultReader materializes a selected result for a package hook. The canonical history passed to the hook retains its stored asset references.
type TurnObservation ¶
TurnObservation is what one execution saw that storage does not keep apart: the tool calls the model made, by the name it called, and the approvals and questions that expired unanswered.
Source Files
¶
- assets.go
- assistant_tools.go
- attachments.go
- background_input.go
- builtin.go
- builtin_history.go
- builtin_search.go
- compaction.go
- context_pressure.go
- delegation_descriptions.go
- delegation_display.go
- delegation_runtime.go
- delegation_settlement.go
- delegation_tools.go
- elicitation.go
- inference.go
- instructions.go
- interactions.go
- names.go
- operations.go
- progress.go
- runtime.go
- search_usage.go
- skills_tools.go
- statistics.go
- telemetry.go
- timeline.go
- tool_media.go
- tool_steering.go
- tools.go
- turn.go