team

package
v0.61.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package team composes decision-driven collaboration from exact Programs. A coordinator consumes Turn and returns Decision; configured workers use ordinary inputs and outputs. Compile freezes those bindings and schemas with the Runtime's Compiler. Model-backed coordinators compose interaction with workflow transforms that render Turn and decode Decision.

ModeContinue starts another coordinator turn while workers remain active. ModeWait observes at least one task outcome before the next turn, including an outcome that arrived while the current coordinator was running. Start failures, task failures, and control rejections remain explicit facts. A coordinator failure or exhausted turn bound terminates the collaboration.

Decisions transfer their next working state and work declarations into the execution; a retained Decision never competes with those facts. Each task advances from Spawn Completion to child Exit. Only Exit proves subtree drain. Coordinator inputs are projections of current working state, tasks, controls, and configured workers, never an independently writable copy.

Controls compile to child Signal or Cancel Effects. A cancellation receipt establishes intent; the task's Exit establishes release. Signals follow the recipient's contract, including addressed InputGate waits or interaction steering. Task keys name finite executions; follow-up work uses a new key and explicit input carrying prior results or application-owned context.

Completion asks the Runtime to cancel and drain remaining descendants before publishing this process's Exit. No task outcome bypasses unresolved external effects. The Runtime's Log and inspection are the authoritative history and live projection; team owns no scheduler, mailbox, persistence, or session.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidDecision = run.NewClassifiedError(
		run.FailureKindContract,
		"team.decision.invalid",
		"team: invalid decision",
	)
	ErrInvalidExecutionState = run.NewClassifiedError(
		run.FailureKindContract,
		"team.state.invalid",
		"team: invalid execution state",
	)
	ErrInvalidProtocol = run.NewClassifiedError(
		run.FailureKindContract,
		"team.protocol.invalid",
		"team: invalid execution protocol",
	)
	ErrTurnLimit = run.NewClassifiedError(
		run.FailureKindExecution,
		"team.limit.turns",
		"team: turn limit reached",
	)
)

Execution sentinels own the Failure persisted when they reach Step. Wrapping one is the only way a Step error acquires its classification.

View Source
var ErrInvalidConfig = errors.New("team: invalid configuration")

ErrInvalidConfig rejects construction before execution and therefore carries no Failure classification.

Functions

func Compile

func Compile[I, O any](compiler *run.Compiler, cfg Config) (run.Program[I, O], error)

Types

type Config

type Config struct {
	Name        string
	Description string
	Coordinator run.ChildBinding
	Workers     []run.ChildBinding
	// MaxTurns is unlimited by default; a finite zero cannot admit the first turn.
	MaxTurns run.Quota
	// MaxTasks is unlimited by default; finite zero forbids worker startups.
	MaxTasks           run.Quota
	MaxConcurrentTasks uint32
	MaxControlsPerTurn uint32
}

Config grants the coordinator and workers their exact programs and resource authority. Input and output schemas come from Compile's type parameters.

type Control

type Control struct {
	Task         run.ChildKey `json:"task"`
	Signal       *run.Signal  `json:"signal,omitzero"`
	CancelReason *string      `json:"cancel_reason,omitzero"`
}

Control targets an already admitted task. Exactly one of Signal and CancelReason is present. Signal uses the recipient's own input contract and caller-stable identity; cancellation is intent, not proof of resource release. A task may exit during the coordinator turn; the runtime then decides the control's receipt without invalidating the coordinator's decision.

type ControlReceipt

type ControlReceipt struct {
	Control Control         `json:"control"`
	Result  *run.Settlement `json:"result,omitzero"`
}

type Decision

type Decision struct {
	Mode     Mode          `json:"mode,omitzero"`
	State    run.Payload   `json:"state"`
	Tasks    []TaskRequest `json:"tasks,omitempty"`
	Controls []Control     `json:"controls,omitempty"`
	Output   run.Payload   `json:"output,omitzero"`
}

Decision is the coordinator's output contract. The entire batch is validated before any action is declared. A present Output completes the collaboration and cancels unfinished descendants; it admits no Mode or actions. Otherwise Mode chooses how the next turn starts. An explicit JSON null is a present Output. Input and Output retain the configured domain schemas.

type Mode

type Mode string
const (
	ModeUndecided Mode = ""
	// ModeContinue starts the next turn after action receipts, while tasks run.
	ModeContinue Mode = "continue"
	// ModeWait starts the next turn after at least one outstanding task drains.
	// If no tasks remain outstanding, failed-start receipts trigger the next turn.
	// Older outstanding tasks still delay the turn when every new start fails;
	// use ModeContinue to process action receipts without waiting for those tasks.
	ModeWait Mode = "wait"
)

func (Mode) JSONSchemaEnum added in v0.61.0

func (Mode) JSONSchemaEnum() []string

JSONSchemaEnum publishes the decided modes. A completing Decision omits the member, so the undecided zero value never appears on the wire.

func (Mode) String

func (m Mode) String() string

func (Mode) Valid

func (m Mode) Valid() bool

type Task

type Task struct {
	Request   TaskRequest      `json:"request"`
	Process   *run.ProcessID   `json:"process,omitzero"`
	Outcome   *run.Termination `json:"outcome,omitzero"`
	Rejection *run.Failure     `json:"rejection,omitzero"`
}

type TaskRequest

type TaskRequest struct {
	Key    run.ChildKey `json:"key"`
	Worker string       `json:"worker"`
	Input  run.Payload  `json:"input"`
}

TaskRequest starts a new bounded execution of a configured worker. To follow up on a completed task, choose a new Key and carry the previous result in Input. Terminal Processes are immutable; continuation has a new lifecycle.

type Turn

type Turn struct {
	Number   uint64           `json:"number"`
	State    run.Payload      `json:"state"`
	Workers  []run.Descriptor `json:"workers"`
	Tasks    []Task           `json:"tasks"`
	Controls []ControlReceipt `json:"controls"`
}

Turn is the coordinator's complete portable input. Tasks are cumulative and request ordered. Controls contains the previous decision's action receipts. State is explicit working memory; a Decision replaces it in full. Workers exposes the exact configured input/output contracts without execution grants. Facts arriving while this turn runs are visible in the following turn.

Jump to

Keyboard shortcuts

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