orchestration

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package orchestration turns a single goal into a graph: its Spawner is the concrete fan-out that creates and governs child goals. It is the mission.Fanout the executor calls when a run delegates a sub-goal, and it composes the existing foundation rather than adding new mechanism: a child is an ordinary Goal resource owned by its parent (so it is torn down with the parent), carrying a capability grant narrowed to a subset of the parent's (so a delegation can never widen authority), charging one shared budget pool reserved per child before it is created (so a fan-out cannot overshoot), at a bounded delegation depth (so agents spawning agents cannot recurse without end), under a concurrency cap (so the blast radius is bounded). Poll reports each child's outcome from its goal status.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Spawner)

Option configures a Spawner.

func WithConcurrency

func WithConcurrency(n int) Option

WithConcurrency caps how many children may be outstanding at once; a spawn past the cap is refused rather than queued. Zero (default) leaves it uncapped (budget and depth still bound the fan-out).

func WithMaxDepth

func WithMaxDepth(n int) Option

WithMaxDepth sets the maximum delegation depth (default defaultMaxDepth). A child past this depth is refused, so recursion is bounded.

func WithReservation

func WithReservation(est budget.Spent) Option

WithReservation bounds a fan-out by budget: each child reserves est against the shared pool before it is created, and the reservation is released when the child finishes, so the number of concurrent children is capped by what the pool can cover. The zero estimate (default) disables budget bounding.

type Spawner

type Spawner struct {
	// contains filtered or unexported fields
}

Spawner is the concrete mission.Fanout over the resource store. It creates child goals, governs them, and reports their outcomes. It is safe for concurrent use.

func NewSpawner

func NewSpawner(store resource.Store, ledger *budget.Ledger, opts ...Option) *Spawner

NewSpawner builds a Spawner over store and an optional budget ledger. Bind the enqueue function (SetEnqueue) before driving runs: it is how a created child is handed to the runtime, and is injected rather than taken at construction so the spawner does not depend on the runtime it feeds.

func (*Spawner) Poll

func (s *Spawner) Poll(ctx context.Context, ids []string) ([]mission.ChildResult, bool, error)

Poll reports each child's outcome and whether all have finished. A converged child yields its final answer; a stalled one yields a failure. A child still running leaves allDone false. When a child reaches a terminal state, its budget reservation and concurrency slot are released exactly once.

func (*Spawner) SetEnqueue

func (s *Spawner) SetEnqueue(fn func(ctx context.Context, key resource.Key) error)

SetEnqueue binds the function that hands a created child goal to the runtime for reconciliation. It is set after the runtime exists, breaking the construction cycle between the executor (which holds the spawner) and the runtime (which holds the executor).

func (*Spawner) Spawn

func (s *Spawner) Spawn(ctx context.Context, parent resource.Resource, sub mission.SubGoal) (string, error)

Spawn creates a child goal for sub, owned by parent, with a narrowed grant, a reserved share of the shared budget, at the next depth, under the concurrency cap. It returns the child's id, or a refusal (depth exceeded, budget exhausted, at capacity) the model sees as a failed spawn it can adapt to.

Jump to

Keyboard shortcuts

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