Documentation
¶
Overview ¶
Package workflow implements agentcore's execution model: a composition tree of typed nodes where each primitive owns its own execution loop.
The package exposes constructors (workflow.New, workflow.Agent, workflow.Goal, workflow.Convergence, workflow.Sequence) that return values of unexported types. Direct struct-literal construction is impossible by design — every composition boundary deep-copies its arguments, so a node placed into one parent cannot alias into another.
Two orthogonal interfaces describe what nodes are:
- Node: anything traversable for validation and observability.
- Step: anything that executes (Agent, Goal, Convergence).
Node and Step are independent — Step does not embed Node. The concrete types that need both implement each separately.
Index ¶
- func Agent(name, prompt string) *agent
- func Convergence(name, description string, within int) *convergence
- func Goal(name, description string) *goal
- func Sequence(name string) *sequence
- func Validate(w *Workflow, rt *Runtime) error
- type ConvergenceCapReached
- type GoalEnded
- type GoalStarted
- type Kind
- type MCPManager
- type Node
- type Override
- type Parameter
- type PostCheckpoint
- type PreCheckpoint
- type PreflightFailed
- type ReconcileResult
- type Runtime
- type State
- type Step
- type SubagentCompleted
- type SubagentSpawned
- type SuperviseRequest
- type SuperviseResult
- type Supervisor
- type Verdict
- type Workflow
- func (w *Workflow) Add(sequences ...*sequence) *Workflow
- func (w *Workflow) Children() []Node
- func (w *Workflow) Execute(ctx context.Context, rt *Runtime, inputs map[string]string) (state *State, err error)
- func (w *Workflow) Input(parameters ...Parameter) *Workflow
- func (w *Workflow) Kind() Kind
- func (w *Workflow) Name() string
- func (w *Workflow) Scope(scope string) *Workflow
- func (w *Workflow) Security(mode security.Mode) *Workflow
- func (w *Workflow) Supervise() *Workflow
- func (w *Workflow) SuperviseByHuman() *Workflow
- type WorkflowEnded
- type WorkflowStarted
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Agent ¶
func Agent(name, prompt string) *agent
Agent constructs an agent with the given name and persona prompt. Each call returns an independent instance.
func Convergence ¶
Convergence constructs a convergence with the given name, description, and iteration cap. within must be > 0; this is checked at Validate time. Pass 0 and call WithinVar to defer resolution until Execute (see WithinVar).
func Goal ¶
func Goal(name, description string) *goal
Goal constructs a goal with the given name and interpolated description. $var references in description resolve at execution time against State.
func Sequence ¶
func Sequence(name string) *sequence
Sequence constructs a sequence with the given name. Use .Steps(...) to populate it.
func Validate ¶
Validate performs preflight checks on w and rt. It composes each subtree's Validate() with workflow-level and cross-tree checks (parameter conflicts, output-name collisions, sequence-name uniqueness, runtime requirements).
Workflow.Execute calls Validate before doing anything; consumers may also call it directly for ahead-of-time checks.
Types ¶
type ConvergenceCapReached ¶
//////////////////////////////////////// ConvergenceCapReached fires when Convergence hits its WITHIN limit without the model emitting CONVERGED.
func (ConvergenceCapReached) Attrs ¶
func (e ConvergenceCapReached) Attrs() []slog.Attr
func (ConvergenceCapReached) Err ¶
func (e ConvergenceCapReached) Err() error
func (ConvergenceCapReached) Level ¶
func (e ConvergenceCapReached) Level() slog.Level
func (ConvergenceCapReached) Name ¶
func (e ConvergenceCapReached) Name() string
type GoalEnded ¶
//////////////////////////////////////// GoalEnded fires when a Goal or Convergence completes (success path only).
type GoalStarted ¶
//////////////////////////////////////// GoalStarted fires when a Goal or Convergence begins execution.
func (GoalStarted) Attrs ¶
func (e GoalStarted) Attrs() []slog.Attr
func (GoalStarted) Err ¶
func (e GoalStarted) Err() error
func (GoalStarted) Level ¶
func (e GoalStarted) Level() slog.Level
func (GoalStarted) Name ¶
func (e GoalStarted) Name() string
type Kind ¶
type Kind string
Kind identifies the type of a workflow node returned by Node.Kind().
Valid values are exactly:
"workflow", "run", "goal", "convergence", "agent"
The set is closed — only types defined in this package implement Node, and each returns one of these literals. Compare against literals at the call site:
if n.Kind() == "agent" { ... }
type MCPManager ¶
type MCPManager interface {
AllTools() []mcp.ToolWithServer
FindTool(name string) (server string, found bool)
CallTool(ctx context.Context, server, tool string, args map[string]any) (*mcp.Result, error)
}
MCPManager is the slice of agentkit's *mcp.Manager that the workflow package uses. Defining it as an interface here — consumer-defines- interfaces — lets tests fake MCP without standing up a real server; *mcp.Manager satisfies it as-is, so existing wiring keeps working.
type Node ¶
Node is any element that can be visited when walking the workflow tree. Every node carries a name and a kind, so a traversal can act on a node without relying on type assertions to unexported types.
type Override ¶
type Override struct {
Model llm.Model
Tools *tools.Registry
MCP MCPManager
Policy policy.Lookup
SystemContext string
}
Override is the curated subset of Runtime fields a step may customize for its own subtree. Set via (*goal).Customize / (*convergence).Customize / (*agent).Customize / (*sequence).Customize. Zero-valued fields inherit from the parent's Runtime; non-zero fields replace it.
SystemContext is the one append-not-replace field: a step's SystemContext is concatenated to the parent's, separated by a blank line. This way each level can layer information for the LLM without erasing what the parent already declared.
Telemetry, Guard, Debug, and SecurityScope are deliberately NOT in Override — they are workflow-wide concerns (single sink for events, taint surface across the whole run, run-wide debug flag) and have no per-node meaning.
type Parameter ¶
Parameter declares one entry in a workflow's input set. Construct via struct literal:
workflow.Parameter{Name: "topic"} // required
workflow.Parameter{Name: "style", Default: "formal"} // optional with default
An empty Default means the parameter is required at execution time. A non-empty Default makes the parameter optional, falling back to that value when the caller does not supply one.
Parameter is a value type containing only strings, which are immutable in Go. Shallow copy is deep copy; no clone or independence work is needed.
type PostCheckpoint ¶
type PostCheckpoint struct {
StepID string
ActualOutput string
MetCommitment bool
Deviations []string
Concerns []string
Unexpected []string
Timestamp time.Time
}
PostCheckpoint records the agent's self-assessment after EXECUTE. Built by the POST phase via an LLM call against rt.Model.
type PreCheckpoint ¶
type PreCheckpoint struct {
StepID string
StepKind string
Instruction string
Interpretation string
ScopeIn []string
ScopeOut []string
Approach string
PredictedOutput string
Confidence string
Assumptions []string
Timestamp time.Time
}
PreCheckpoint records the agent's stated intent before EXECUTE runs. Built by the COMMIT phase via an LLM call against rt.Model.
type PreflightFailed ¶
//////////////////////////////////////// PreflightFailed fires when Validate rejects the workflow before execution.
func (PreflightFailed) Attrs ¶
func (e PreflightFailed) Attrs() []slog.Attr
func (PreflightFailed) Err ¶
func (e PreflightFailed) Err() error
func (PreflightFailed) Level ¶
func (e PreflightFailed) Level() slog.Level
func (PreflightFailed) Name ¶
func (e PreflightFailed) Name() string
type ReconcileResult ¶
type ReconcileResult struct {
StepID string
Triggers []string
Escalate bool // whether SUPERVISE should fire
}
ReconcileResult is the deterministic drift signal produced by Supervisor.
type Runtime ¶
type Runtime struct {
// Model is the default LLM for goals, convergences, and agents that did
// not customize a different model. Required.
Model llm.Model
// Tools is the built-in tool registry. Nil means no tools available.
Tools *tools.Registry
// MCP is the MCP server manager. Nil means no MCP tools. Typed as the
// MCPManager interface so tests can substitute fakes; pass any
// *mcp.Manager to satisfy it in production.
MCP MCPManager
// Policy enforces tool access rules. Nil means allow-all.
Policy policy.Lookup
// Guard is the contentguard instance for taint tracking and tier-based
// security review. When the workflow declares a security mode and Guard
// is nil, Workflow.Execute builds one from the declared mode using Model.
Guard *contentguard.Guard
// SystemContext is content appended to the system prompt of every Goal,
// Convergence, and Agent invocation. Use it for any cross-cutting
// information the LLM should see on every call: workspace layout,
// behavior guidelines, environment notes, etc. Empty = nothing appended.
//
// The field is deliberately a free-form string. The package does not
// inspect or validate its contents — whatever is supplied is concatenated
// after the package's default system message.
SystemContext string
// Telemetry receives workflow events. Nil means events are silently
// dropped. The agentcore/observe package provides the canonical
// implementations: Logger (slog), Counter (OTel metrics), and
// NewHandlers (typed callbacks). Compose with observe.Tee. Tracing is
// emitted directly by this package via OTel — no sink wiring required.
Telemetry observe.EventSink
// Supervisor judges supervised steps' work. Required when any node in
// the workflow has Supervise() or SuperviseByHuman() set; nil is fine
// when no node is supervised. Validate enforces this.
Supervisor Supervisor
// MaxReorientAttempts is the per-step limit on VerdictReorient retries.
// When exhausted, the pipeline escalates to AskHuman (if HumanCh is wired)
// or Halt. Default 1 when zero or unset.
MaxReorientAttempts int
// HumanCh is the channel used when a step set SuperviseByHuman() or the
HumanCh chan string
// Debug enables verbose logging of prompts and responses.
Debug bool
}
Runtime holds the immutable dependencies a workflow needs to execute. It is wired once by the caller and passed by pointer to Workflow.Execute.
At each step's execution the package merges the step's Override (set via .Customize) on top of the parent's Runtime to produce an effective Runtime for that subtree. Children inherit unless they override in turn.
Only Model is required. Everything else is optional and silently disabled when nil or unset.
type State ¶
type State struct {
Inputs map[string]string
Outputs map[string]string
Failures map[string]int // goal name → iteration cap reached
}
State carries mutable data through execution. Inputs are bound at workflow start; Outputs accumulate as steps complete. Failures records goals that hit their WITHIN cap without converging.
CurrentGoal and supervision status are passed via context.Context, not here.
type Step ¶
type Step interface {
Execute(ctx context.Context, rt *Runtime, state *State) error
// contains filtered or unexported methods
}
Step owns its own execution loop. It reads from and writes to State, using Runtime for all external dependencies.
The unexported clone method closes the interface to this package — only types defined here can implement Step. clone is called at every composition boundary to enforce node independence.
type SubagentCompleted ¶
//////////////////////////////////////// SubagentCompleted fires when a child Step in a fan-out finishes.
func (SubagentCompleted) Attrs ¶
func (e SubagentCompleted) Attrs() []slog.Attr
func (SubagentCompleted) Err ¶
func (e SubagentCompleted) Err() error
func (SubagentCompleted) Level ¶
func (e SubagentCompleted) Level() slog.Level
func (SubagentCompleted) Name ¶
func (e SubagentCompleted) Name() string
type SubagentSpawned ¶
//////////////////////////////////////// SubagentSpawned fires when Goal.fanOut starts a child Step.
func (SubagentSpawned) Attrs ¶
func (e SubagentSpawned) Attrs() []slog.Attr
func (SubagentSpawned) Err ¶
func (e SubagentSpawned) Err() error
func (SubagentSpawned) Level ¶
func (e SubagentSpawned) Level() slog.Level
func (SubagentSpawned) Name ¶
func (e SubagentSpawned) Name() string
type SuperviseRequest ¶
type SuperviseRequest struct {
OriginalGoal string
Pre *PreCheckpoint
Post *PostCheckpoint
Triggers []string
HumanRequired bool
Model llm.Model // fallback model; used when no dedicated supervisor model is configured
}
SuperviseRequest is the input to the LLM-driven SUPERVISE phase.
type SuperviseResult ¶
type SuperviseResult struct {
StepID string
Verdict Verdict
Correction string // populated when Verdict == Reorient or AskHuman
Question string // populated when Verdict == AskHuman; sent to human for approval
Reason string // populated when Verdict == Halt; explains why execution stopped
}
SuperviseResult is the verdict and any correction/question.
type Supervisor ¶
type Supervisor interface {
Reconcile(pre *PreCheckpoint, post *PostCheckpoint) *ReconcileResult
Supervise(ctx context.Context, req SuperviseRequest) (*SuperviseResult, error)
}
Supervisor is the consumer-supplied policy that judges a step's work. Implementations live outside the workflow package (e.g., agentcore/supervision).
type Workflow ¶
type Workflow struct {
// contains filtered or unexported fields
}
workflow is the root of the execution tree. It owns the declared inputs and the ordered list of sequences. Implements Node but not Step.
Constructed via workflow.New — never directly.
func New ¶
New constructs a workflow with the given name. This is the package's primary type, hence the New() prefix per Go convention.
func (*Workflow) Add ¶
Add appends one or more sequences to this workflow. Each argument is deep-copied — passing the same sequence to multiple workflows is safe.
func (*Workflow) Children ¶
Children implements Node. Workflow children are runs only — inputs are arguments to the workflow, not navigable nodes.
func (*Workflow) Execute ¶
func (w *Workflow) Execute(ctx context.Context, rt *Runtime, inputs map[string]string) (state *State, err error)
Execute binds inputs, validates the workflow, then executes each sequence in declared order. State accumulates across sequences.
If the workflow declared a security mode and rt.Guard is nil, Execute builds a content guard from the declared mode/scope using rt.Model. The caller's *env is never mutated — execution uses a derived shallow copy.
func (*Workflow) Input ¶
Input declares the workflow's parameter set in a single call. Each entry is a workflow.Parameter struct; an empty Default makes the parameter required, a non-empty Default makes it optional with that fallback.
wf.Input(
workflow.Parameter{Name: "topic"},
workflow.Parameter{Name: "style", Default: "concise"},
)
May be called multiple times to append additional parameters; each call adds to the workflow's parameter set.
func (*Workflow) Scope ¶
Scope declares the free-text scope for security.Research mode. It is embedded in the reviewer stage's system prompt so the supervisor knows what is permitted within the declared engagement.
func (*Workflow) Security ¶
Security declares the workflow-level content-guard mode. Calling this opts the workflow in to building a *contentguard.Guard at Execute time using Runtime.Model. For security.Research, pair this call with .Scope.
func (*Workflow) SuperviseByHuman ¶
SuperviseByHuman marks the workflow for supervision requiring human approval.
type WorkflowEnded ¶
//////////////////////////////////////// WorkflowEnded fires when Workflow.Execute returns (success or error).
func (WorkflowEnded) Attrs ¶
func (e WorkflowEnded) Attrs() []slog.Attr
func (WorkflowEnded) Err ¶
func (e WorkflowEnded) Err() error
func (WorkflowEnded) Level ¶
func (e WorkflowEnded) Level() slog.Level
func (WorkflowEnded) Name ¶
func (e WorkflowEnded) Name() string
type WorkflowStarted ¶
type WorkflowStarted struct {
Workflow string
}
//////////////////////////////////////// WorkflowStarted fires when Workflow.Execute begins.
func (WorkflowStarted) Attrs ¶
func (e WorkflowStarted) Attrs() []slog.Attr
func (WorkflowStarted) Err ¶
func (e WorkflowStarted) Err() error
func (WorkflowStarted) Level ¶
func (e WorkflowStarted) Level() slog.Level
func (WorkflowStarted) Name ¶
func (e WorkflowStarted) Name() string
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package security defines the workflow's content-guard tier modes and the logic that turns a mode into a fully-configured *contentguard.Guard.
|
Package security defines the workflow's content-guard tier modes and the logic that turns a mode into a fully-configured *contentguard.Guard. |