composition

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package composition defines RFC 0010 workflow-composition types and their validation. It is a leaf package: it imports neither runtime/pipeline nor runtime/workflow, so workflow.State can reference these types without a cycle.

Index

Constants

View Source
const (
	ReduceAppend  = "append"
	ReduceReplace = "replace"
	ReduceBarrier = "barrier"
)

Reduce strategies (RFC 0010 v1).

Variables

This section is empty.

Functions

func ParseConfig

func ParseConfig(raw interface{}) (map[string]*Composition, error)

ParseConfig parses an untyped compositions map (typically config.Compositions, stored as interface{}) into typed Compositions keyed by name. Returns nil, nil when raw is nil. Mirrors workflow.ParseConfig.

Types

type Available

type Available struct {
	Prompts []string
	Tools   []string
	Evals   []string
}

Available holds the pack key sets a composition's references resolve against.

type Composition

type Composition struct {
	Version      int            `json:"version"`
	Description  string         `json:"description,omitempty"`
	InputSchema  string         `json:"input_schema,omitempty"`
	OutputSchema string         `json:"output_schema,omitempty"`
	Output       string         `json:"output,omitempty"` // step id; default = last step
	Steps        []*Step        `json:"steps"`
	Engine       map[string]any `json:"engine,omitempty"` // opaque runtime-specific config
}

Composition is a named step graph over the pack's prompts, tools, and evals.

type Predicate

type Predicate struct {
	Path   string       `json:"path,omitempty"`
	Op     string       `json:"op,omitempty"`
	Value  any          `json:"value,omitempty"`
	Exists *bool        `json:"exists,omitempty"`
	AllOf  []*Predicate `json:"all_of,omitempty"`
	AnyOf  []*Predicate `json:"any_of,omitempty"`
	Not    *Predicate   `json:"not,omitempty"`
}

Predicate is the constrained predicate language. Exactly one variant is set: compare (path+op+value), exists (path+exists), or a composite (all_of/any_of/not).

type Reducer

type Reducer struct {
	Strategy string `json:"strategy"` // append | replace | barrier
	Into     string `json:"into"`     // variable name the merged result is exposed under
}

Reducer declares how parallel branch outputs merge. Both fields required.

type RetryModifier

type RetryModifier struct {
	MaxAttempts int `json:"max_attempts,omitempty"`
}

RetryModifier re-runs a step on error up to MaxAttempts.

type Step

type Step struct {
	ID        string         `json:"id"`
	Kind      StepKind       `json:"kind"`
	DependsOn []string       `json:"depends_on,omitempty"`
	Modifiers *StepModifiers `json:"modifiers,omitempty"`

	// prompt, agent
	PromptTask   string       `json:"prompt_task,omitempty"`
	Input        any          `json:"input,omitempty"` // StepInput: "${...}" string or object
	OutputSchema string       `json:"output_schema,omitempty"`
	Tools        []string     `json:"tools,omitempty"`       // agent only
	Termination  *Termination `json:"termination,omitempty"` // agent only

	// tool
	Tool string         `json:"tool,omitempty"`
	Args map[string]any `json:"args,omitempty"`

	// branch
	Predicate *Predicate `json:"predicate,omitempty"`
	Then      string     `json:"then,omitempty"`
	Else      string     `json:"else,omitempty"`

	// parallel
	Branches []*Step  `json:"branches,omitempty"`
	Reduce   *Reducer `json:"reduce,omitempty"`
}

Step is a single node in a composition graph. Only the fields legal for Kind are set; per-kind legality is enforced by Validate.

type StepKind

type StepKind string

StepKind identifies a composition step's kind.

const (
	KindPrompt   StepKind = "prompt"
	KindAgent    StepKind = "agent"
	KindTool     StepKind = "tool"
	KindBranch   StepKind = "branch"
	KindParallel StepKind = "parallel"
)

Step kinds (RFC 0010 v1).

type StepModifiers

type StepModifiers struct {
	Retry *RetryModifier `json:"retry,omitempty"`
	Eval  []string       `json:"eval,omitempty"` // references to pack eval keys (observability)
}

StepModifiers are optional per-step behaviors (RFC 0010 v1: retry, eval).

type Termination

type Termination struct {
	MaxSteps   int    `json:"max_steps,omitempty"`
	ToolCalled string `json:"tool_called,omitempty"`
}

Termination bounds an agent step's tool loop. anyOf max_steps | tool_called.

type ValidationResult

type ValidationResult struct {
	Errors   []string
	Warnings []string
}

ValidationResult holds blocking errors and non-blocking warnings.

func Validate

func Validate(name string, c *Composition, avail Available) *ValidationResult

Validate checks a single composition against the available pack key sets. It implements composition-internal rules 2–11 from the design (rule 1 and the workflow/pack-level rules live in ValidateAll and Plan 3 respectively).

func ValidateAll

func ValidateAll(comps map[string]*Composition, avail Available) *ValidationResult

ValidateAll validates every composition in a pack map and checks pack-wide rules (rule 1: key uniqueness is inherent to the map; reserved-name collision).

func (*ValidationResult) HasErrors

func (r *ValidationResult) HasErrors() bool

HasErrors reports whether there are blocking validation errors.

Directories

Path Synopsis
Package engine is the deterministic orchestrator core for RFC 0010 workflow compositions.
Package engine is the deterministic orchestrator core for RFC 0010 workflow compositions.

Jump to

Keyboard shortcuts

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