Documentation
¶
Overview ¶
Human-readable aliases for registered actions. An alias points at the SAME *BuiltAction as its canonical name; no wrapper, no reflection. Resolved once at boot; the DSL compiler sees an ordinary registry entry.
A canonical name always wins over an alias for the same word, so an application can safely define its own `read` action.
flow/cost.go
Index ¶
- Constants
- Variables
- func AcquireStateFromGraphState(s *State) *dag.State
- func AsCostHook(reserver cost.Reserver, estimateMicros int64, _ ...int64) action.AnyHook
- func BuildCatalogAction(reg Registry) action.AnyAction
- func CompilePipeline(expr string, reg Registry) (*action.Builder[any, any], error)
- func CompileSaga(expr string, reg Registry) (*action.Builder[any, any], error)
- func EvaluateCondition(condition string, state *State) (bool, error)
- func Execute[Req, Res any](ctx context.Context, act *action.BuiltAction[Req, Res], req Req) (Res, error)
- func ExponentialJitterOr(base, maxDelay time.Duration) func(attempt int) time.Duration
- func GuardCost(reserver cost.Reserver, estimateMicros int64) action.AnyHook
- func LibraryNames(libs []Library) []string
- func MaxTokensFromCtx(ctx context.Context, def int) int
- func NewExecuteAction(compiler *Compiler) *action.BuiltAction[GraphExecReq, GraphExecRes]
- func RegisterAliases(reg *MapRegistry)
- func RegisterPipelines(reg *MapRegistry, pipelines []Pipeline) error
- func SanitizeDSL(rawContent string) string
- func WithApprovalGate(g ApprovalGate) func(*Compiler)
- func WithHooks(hooks ...action.AnyHook) func(*Compiler)
- func WithJournal(j journal.BranchJournal) func(*Compiler)
- func WithMaxTokens(ctx context.Context, n int) context.Context
- func WithReserver(r cost.Reserver) func(*Compiler)
- type ActionMeta
- type Alias
- type ApprovalGate
- type BranchMode
- type CapabilitySpec
- type CompiledEdge
- type CompiledGraph
- type Compiler
- type Config
- type EdgeSpec
- type EffectClass
- type FanInPolicy
- type GraphDefinition
- type GraphExecReq
- type GraphExecRes
- type GraphPolicy
- type Layer
- type Library
- type MapRegistry
- type Metadata
- type NodeKind
- type NodeResult
- type NodeSpec
- type Pipeline
- type PipelineCompiler
- type Preprocessed
- type RecoveryPolicy
- type RecoveryStrategy
- type Registry
- type Requirement
- type Resolved
- type RetryPolicy
- type Runner
- type SpawnedNode
- type State
- type SystemAssembler
- func (s *SystemAssembler) Actions() []action.AnyAction
- func (s *SystemAssembler) AssembleFile(path string) ([]action.AnyAction, error)
- func (s *SystemAssembler) AssembleManifest(manifestDSL string) ([]action.AnyAction, error)
- func (s *SystemAssembler) Register(name string, act action.AnyAction) *SystemAssembler
- type WorkflowFixture
- type WorkflowResult
Constants ¶
const APIVersion = "nexss.ai/v1"
Variables ¶
var DefaultAliases = map[string][]string{
"workspace.read_file": {"read", "open", "read_file"},
"workspace.write_file": {"write", "save_file", "write_file"},
"workspace.edit_file": {"edit", "edit_file"},
"prompt.summarize": {"summarize", "summary"},
"prompt.translate": {"translate"},
"prompt.code_review": {"review", "review_code"},
"ai.complete": {"llm"},
"ai.prompt": {"ask"},
"agent.planner": {"plan", "planner"},
"agent.architect": {"code", "write_code", "fix"},
"agent.critic": {"critic", "evaluate"},
"agent.swarm": {"swarm"},
"sandbox.exec": {"run", "exec", "shell"},
"sandbox.test": {"test", "run_tests"},
"sandbox.test_runner": {"test_runner"},
"bench.run": {"bench", "benchmark"},
"bench.save": {"save_bench"},
"bench.compare": {"compare", "diff"},
"log.info": {"log", "info"},
"log.warn": {"warn"},
"log.error": {"error"},
"distribute.map": {"map", "fanout", "parallel"},
"distribute.reduce": {"reduce", "fold"},
}
DefaultAliases maps a canonical action name to the short words a non-programmer can type in a .flow file.
Append from an init() function to add application-specific words. Not safe for concurrent mutation at runtime.
Functions ¶
func AcquireStateFromGraphState ¶
AcquireStateFromGraphState converts a graph.State into a pooled dag.State without manual map copying.
func AsCostHook ¶
AsCostHook provides an alias for GuardCost to attach cost governance hooks to actions.
func BuildCatalogAction ¶
BuildCatalogAction returns a system action exposing the capability catalog over HTTP/A2A.
func CompilePipeline ¶
func CompileSaga ¶
CompileSaga parses Arrow DSL with embedded transaction rollbacks into a Saga Node.
func Execute ¶
func Execute[Req, Res any](ctx context.Context, act *action.BuiltAction[Req, Res], req Req) (Res, error)
Execute is a type-safe generic invoker helper.
func ExponentialJitterOr ¶ added in v0.6.0
func GuardCost ¶ added in v0.3.0
GuardCost returns an action hook that reserves budget before execution and commits or releases it upon completion based on execution outcome.
func LibraryNames ¶ added in v0.6.0
LibraryNames returns the names of the given libraries, in order.
func NewExecuteAction ¶
func NewExecuteAction(compiler *Compiler) *action.BuiltAction[GraphExecReq, GraphExecRes]
NewExecuteAction exposes dynamic graph execution over CLI, HTTP REST, MCP, and A2A.
func RegisterAliases ¶ added in v0.5.0
func RegisterAliases(reg *MapRegistry)
RegisterAliases walks reg once and adds every alias that does not collide with an existing canonical name. Safe to call more than once.
func RegisterPipelines ¶ added in v0.6.0
func RegisterPipelines(reg *MapRegistry, pipelines []Pipeline) error
RegisterPipelines installs named pipelines into an existing registry.
Each pipeline becomes a Proxy action under its own name, so pipelines can reference each other and any other action regardless of declaration order. Cycles between pipelines are detected before any compilation runs. The registry is mutated in place.
func SanitizeDSL ¶ added in v0.5.0
SanitizeDSL converts a full .flow manifest into the line-oriented pipeline the flow compiler consumes.
One statement per line. Comments (# or //), config directives (@config:, @assert:, @require, …), and route declaration headers (unindented lines that bind :route= or :http= and contain no pipeline arrow) are dropped. Everything else is preserved verbatim so the lexer can terminate an unquoted @prompt annotation at the end of its line.
func WithApprovalGate ¶
func WithApprovalGate(g ApprovalGate) func(*Compiler)
func WithJournal ¶
func WithJournal(j journal.BranchJournal) func(*Compiler)
func WithReserver ¶ added in v0.3.0
Types ¶
type ActionMeta ¶ added in v0.6.0
ActionMeta describes a .flow file that declares itself as an action via @action and (optionally) @description.
type Alias ¶ added in v0.6.0
Alias associates a canonical action name with one or more short names that .flow authors may use in its place.
Aliases are a slice, not a map: duplicate declarations are errors, not silent last-wins.
type ApprovalGate ¶
type BranchMode ¶
type BranchMode string
const ( BranchFirstMatch BranchMode = "first_match" BranchAllMatches BranchMode = "all_matches" )
type CapabilitySpec ¶
type CapabilitySpec struct {
Name string `json:"name"`
Description string `json:"description"`
Route string `json:"route,omitempty"`
Method string `json:"method,omitempty"`
InputSchema map[string]any `json:"input_schema"`
OutputSchema map[string]any `json:"output_schema"`
Tags []string `json:"tags,omitempty"`
IsSystem bool `json:"is_system"`
}
CapabilitySpec represents a machine-readable action contract for AI agents & graph builders.
func ExtractCapabilities ¶
func ExtractCapabilities(reg Registry) []CapabilitySpec
ExtractCapabilities converts a Registry into an AI-friendly CapabilitySpec catalog.
type CompiledEdge ¶
type CompiledGraph ¶
type CompiledGraph struct {
Definition GraphDefinition
Layers [][]string
NodeByID map[string]NodeSpec
Edges []CompiledEdge
Outgoing map[string][]CompiledEdge
EdgeKeys []string
}
func Compile ¶
func Compile(def GraphDefinition) (*CompiledGraph, error)
func LoadYAML ¶
func LoadYAML(data []byte) (*CompiledGraph, error)
func LoadYAMLFile ¶
func LoadYAMLFile(path string) (*CompiledGraph, error)
func (*CompiledGraph) SelectOutgoing ¶
func (g *CompiledGraph) SelectOutgoing( source string, matches func(condition string) (bool, error), ) ([]CompiledEdge, error)
func (*CompiledGraph) SelectOutgoingDurable ¶
func (g *CompiledGraph) SelectOutgoingDurable( ctx context.Context, j journal.BranchJournal, runID, source string, state *State, ) ([]CompiledEdge, error)
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
func NewCompiler ¶
func (*Compiler) Compile ¶
func (c *Compiler) Compile(ctx context.Context, def GraphDefinition) (*dag.DAG, *CompiledGraph, error)
type Config ¶ added in v0.6.0
type Config struct {
Verbosity int
BudgetMicros int64
Approval string // "danger" | "all" | "none" — validated by the runner
MaxTokens int // 0 = per-node default
Observe string // "live" | "json" | "off"
Provider string
Model string
Sandbox string
OutputFormat string // "" | "json" | "text"
OutputDir string
}
Config is the complete set of runtime knobs for a flow run.
Zero values are meaningful defaults supplied by defaultConfig. Every field is optional in the .flow, in the environment, and on the CLI.
type EffectClass ¶
type EffectClass string
const ( EffectReadOnly EffectClass = "read_only" EffectSideEffect EffectClass = "side_effect" EffectHighRisk EffectClass = "high_risk" )
type FanInPolicy ¶
type GraphDefinition ¶
type GraphDefinition struct {
APIVersion string `json:"apiVersion" yaml:"apiVersion"`
Kind string `json:"kind" yaml:"kind"`
Metadata Metadata `json:"metadata" yaml:"metadata"`
Policy GraphPolicy `json:"policy,omitempty" yaml:"policy,omitempty"`
Nodes []NodeSpec `json:"nodes" yaml:"nodes"`
Edges []EdgeSpec `json:"edges" yaml:"edges"`
}
func ParseArrowDSL ¶
func ParseArrowDSL(name, dsl string) (GraphDefinition, error)
type GraphExecReq ¶
type GraphExecReq struct {
DSL string `json:"dsl,omitempty" cli:"dsl,d" usage:"Compact arrow pipeline expression"`
YAML string `json:"yaml,omitempty" cli:"yaml,y" usage:"Declarative YAML graph manifest"`
InitialPayload map[string]any `json:"initial_payload,omitempty" usage:"Initial state values passed to root nodes"`
}
GraphExecReq defines the omni-protocol input payload.
type GraphExecRes ¶
type GraphExecRes struct {
GraphName string `json:"graph_name"`
Outputs map[string]any `json:"outputs"`
LayersRun int `json:"layers_run"`
DurationMS int64 `json:"duration_ms"`
}
GraphExecRes defines the structured execution audit output.
type GraphPolicy ¶
type GraphPolicy struct {
MaxParallelNodes int `json:"max_parallel_nodes,omitempty" yaml:"max_parallel_nodes,omitempty"`
MaxContextBytes int64 `json:"max_context_bytes,omitempty" yaml:"max_context_bytes,omitempty"`
BudgetMicros int64 `json:"budget_micros,omitempty" yaml:"budget_micros,omitempty"`
ApprovalRequiredFor []EffectClass `json:"approval_required_for,omitempty" yaml:"approval_required_for,omitempty"`
FanInRecovery RecoveryPolicy `json:"fan_in_recovery,omitempty" yaml:"fan_in_recovery,omitempty"`
}
type Layer ¶ added in v0.6.0
type Layer uint8
Layer identifies where a resolved config value came from. The runner prints the layer next to each value at -vvv so the operator can see whether a knob came from the CLI, the environment, the .flow file, or a built-in default.
type Library ¶ added in v0.6.0
type Library struct {
Name string
Description string
Actions []action.AnyAction
Hooks []action.AnyHook
Aliases []Alias
Overrides []string
}
Library is a named bag of actions contributed by one package.
Library is a value type, not an interface: the fields are the whole contract, and the runtime only ever reads them.
Overrides lists canonical action names that this library intentionally replaces from an earlier library in the same BuildRegistry call. Any collision not listed here is a hard error.
func StandardLibrary ¶ added in v0.6.0
func StandardLibrary() Library
StandardLibrary returns the flow package's own action set: logging, benchmarking, distribution, and supervision.
type MapRegistry ¶
type MapRegistry struct {
// contains filtered or unexported fields
}
func BuildRegistry ¶ added in v0.6.0
func BuildRegistry(libs ...Library) (*MapRegistry, error)
BuildRegistry creates a MapRegistry from a set of libraries.
Rules:
- Every primary action is registered under its canonical name.
- When two libraries declare the same canonical name, the later library MUST list that name in its Overrides. Otherwise BuildRegistry returns an error naming both libraries.
- Hooks from every library are applied to every surviving action.
- Aliases are registered last, so a canonical name always wins over an alias, and an earlier library always wins over a later one on alias collisions.
func NewRegistry ¶
func NewRegistry(actions ...action.AnyAction) *MapRegistry
func (*MapRegistry) Actions ¶
func (r *MapRegistry) Actions() []action.AnyAction
func (*MapRegistry) CompilePipeline ¶
func (r *MapRegistry) CompilePipeline(expr string) (action.Executable, error)
type NodeResult ¶
type NodeResult[Res any] struct { Spawned SpawnedNode `json:"spawned"` Value Res `json:"value"` Err error `json:"error,omitempty"` }
type NodeSpec ¶
type NodeSpec struct {
ID string `json:"id" yaml:"id"`
Kind NodeKind `json:"kind" yaml:"kind"`
Capability string `json:"capability" yaml:"capability"`
Params map[string]any `json:"params,omitempty" yaml:"params,omitempty"`
InputBindings map[string]string `json:"inputs,omitempty" yaml:"inputs,omitempty"`
InputSchema string `json:"input_schema,omitempty" yaml:"input_schema,omitempty"`
OutputSchema string `json:"output_schema,omitempty" yaml:"output_schema,omitempty"`
Prompt string `json:"prompt,omitempty" yaml:"prompt,omitempty"`
Retry RetryPolicy `json:"retry,omitempty" yaml:"retry,omitempty"`
TimeoutMS int64 `json:"timeout_ms,omitempty" yaml:"timeout_ms,omitempty"`
MaxAttempts int `json:"max_attempts,omitempty" yaml:"max_attempts,omitempty"`
EstimateMicros int64 `json:"estimate_micros,omitempty" yaml:"estimate_micros,omitempty"`
Effect EffectClass `json:"effect,omitempty" yaml:"effect,omitempty"`
Approval bool `json:"approval_required,omitempty" yaml:"approval_required,omitempty"`
BranchMode BranchMode `json:"branch_mode,omitempty" yaml:"branch_mode,omitempty"`
}
type Pipeline ¶ added in v0.6.0
Pipeline is a named reusable subflow declared with @pipeline.
Pipelines live as a slice, not a map: a duplicate name is a declaration error, and the order in which they were written matters for diagnostics. The registry later converts each into an action.
type PipelineCompiler ¶ added in v0.5.0
type PipelineCompiler = contracts.PipelineCompiler
Aliases — istniejące sygnatury (flow.Registry, flow.PipelineCompiler) działają bez zmian; to ten sam typ.
type Preprocessed ¶ added in v0.6.0
type Preprocessed struct {
DSL string
Pipelines []Pipeline
Action *ActionMeta
Includes []string
Requires []Requirement
}
Preprocessed is the result of resolving @include directives and extracting @pipeline / @action / @require metadata from a .flow source.
func Preprocess ¶ added in v0.6.0
func Preprocess(path string) (*Preprocessed, error)
Preprocess reads path, resolves @include directives recursively, extracts metadata, and returns the flow body with directives removed.
type RecoveryPolicy ¶
type RecoveryPolicy struct {
Strategy RecoveryStrategy `json:"strategy,omitempty" yaml:"strategy,omitempty"`
MaxAttempts int `json:"max_attempts,omitempty" yaml:"max_attempts,omitempty"`
BackoffMS int64 `json:"backoff_ms,omitempty" yaml:"backoff_ms,omitempty"`
MaxBackoffMS int64 `json:"max_backoff_ms,omitempty" yaml:"max_backoff_ms,omitempty"`
RetryTransientOnly bool `json:"retry_transient_only,omitempty" yaml:"retry_transient_only,omitempty"`
}
type RecoveryStrategy ¶
type RecoveryStrategy string
const ( RecoveryFailFast RecoveryStrategy = "fail_fast" RecoveryRetryFailed RecoveryStrategy = "retry_failed" RecoveryContinuePartial RecoveryStrategy = "continue_partial" )
type Registry ¶
Aliases — istniejące sygnatury (flow.Registry, flow.PipelineCompiler) działają bez zmian; to ten sam typ.
type Requirement ¶ added in v0.6.0
type Requirement struct {
Import string
Version string
LocalPath string
ModuleRoot string
ModulePath string
}
Requirement is one @require directive, fully resolved.
Two forms are accepted in .flow files:
Local: @require ./relative/path
@require ../shared/actions
Remote: @require github.com/acme/text v1.0.0
Local paths are resolved at preprocess time to a canonical Go module path by walking up from the target directory until a go.mod is found and reading its module line.
func (Requirement) IsLocal ¶ added in v0.6.0
func (r Requirement) IsLocal() bool
type Resolved ¶ added in v0.6.0
Resolved pairs the final Config with per-field provenance.
func ResolveConfig ¶ added in v0.6.0
ResolveConfig applies CLI > env > DSL > default to every knob.
cliArgs is the raw flag slice; the parser ignores anything that is not a config knob, so it is safe to pass the same args the runner also uses for runner-specific flags (-i, --assert=, …).
type RetryPolicy ¶
type Runner ¶ added in v0.6.0
type Runner interface {
// RunFlow executes the flow file at path.
//
// args is the raw CLI flag slice; config knobs are parsed
// downstream by flow.ResolveConfig.
// libs are the libraries whose actions the flow may call.
// stdout receives the human-readable trace and metrics table.
// stderr receives fatal errors and warnings.
//
// Returns a process exit code: 0 on success, non-zero otherwise.
RunFlow(
ctx context.Context,
path string,
payload map[string]any,
args []string,
libs []Library,
stdout, stderr io.Writer,
) int
}
Runner is the shape of a flow execution engine.
The default implementation is flow/runner.Default. Products that need a different engine — remote execution, a custom observer, a custom approval flow — implement this interface and swap it in.
The interface is deliberately minimal: it captures only what callers actually need (flow path, initial payload, raw CLI args, libraries, and where to write output). The implementation owns the registry, the observer, the approval gate, and every other detail.
Callers that only need the default runner can import github.com/nexssp/flow/runner directly and skip this interface.
type SpawnedNode ¶
type SpawnedNode struct {
RunID string `json:"run_id"`
SourceNode string `json:"source_node"`
Edge CompiledEdge `json:"edge"`
TargetNode string `json:"target_node"`
Input *State `json:"input"`
SpawnIndex int `json:"spawn_index"`
}
func SpawnSelected ¶
func SpawnSelected(runID, source string, selected []CompiledEdge, input *State) ([]SpawnedNode, error)
SpawnSelected creates durable invocation units for each selected edge.
type State ¶
type State struct {
// contains filtered or unexported fields
}
func FanIn ¶
func FanIn[Res any]( ctx context.Context, input *State, results []NodeResult[Res], policy FanInPolicy, reduce func(context.Context, *State, []NodeResult[Res]) (*State, error), ) (*State, error)
FanIn deterministically orders parallel child outputs by SpawnIndex and calls reduce.
func NewStateFromDAG ¶
type SystemAssembler ¶ added in v0.4.0
type SystemAssembler struct {
// contains filtered or unexported fields
}
func NewAssembler ¶ added in v0.4.0
func NewAssembler(capabilities ...action.AnyAction) *SystemAssembler
func (*SystemAssembler) Actions ¶ added in v0.4.0
func (s *SystemAssembler) Actions() []action.AnyAction
func (*SystemAssembler) AssembleFile ¶ added in v0.4.0
func (s *SystemAssembler) AssembleFile(path string) ([]action.AnyAction, error)
func (*SystemAssembler) AssembleManifest ¶ added in v0.4.0
func (s *SystemAssembler) AssembleManifest(manifestDSL string) ([]action.AnyAction, error)
AssembleManifest compiles a manifest of action declarations. Each non-empty, non-comment line is one action; blank lines and lines starting with '#' or '//' are ignored.
Unlike CompilePipeline, this method does NOT run SanitizeDSL on the input. SanitizeDSL's route-header filter treats an unindented ":route=" line with no arrow as a whole-flow mount point, which is correct for a .flow file but wrong for a manifest-of-actions: every line here is its own declaration and route modifiers belong to the action on that line.
func (*SystemAssembler) Register ¶ added in v0.4.0
func (s *SystemAssembler) Register(name string, act action.AnyAction) *SystemAssembler
type WorkflowFixture ¶ added in v0.4.0
type WorkflowFixture struct {
// contains filtered or unexported fields
}
func NewWorkflowTest ¶ added in v0.4.0
func NewWorkflowTest(t testing.TB, reg Registry, dsl string) *WorkflowFixture
func (*WorkflowFixture) Execute ¶ added in v0.4.0
func (wf *WorkflowFixture) Execute(input any) *WorkflowResult
func (*WorkflowFixture) WithTimeout ¶ added in v0.4.0
func (wf *WorkflowFixture) WithTimeout(d time.Duration) *WorkflowFixture
type WorkflowResult ¶ added in v0.4.0
type WorkflowResult struct {
// contains filtered or unexported fields
}
func (*WorkflowResult) Duration ¶ added in v0.4.0
func (r *WorkflowResult) Duration() time.Duration
func (*WorkflowResult) ExpectError ¶ added in v0.4.0
func (r *WorkflowResult) ExpectError() *WorkflowResult
func (*WorkflowResult) ExpectSuccess ¶ added in v0.4.0
func (r *WorkflowResult) ExpectSuccess() *WorkflowResult
func (*WorkflowResult) Output ¶ added in v0.4.0
func (r *WorkflowResult) Output() any
Source Files
¶
- action.go
- aliases.go
- arrow_dsl.go
- assembler.go
- catalog.go
- compiler.go
- config.go
- config_cli.go
- config_dsl.go
- config_env.go
- cost.go
- definition.go
- dsl.go
- dsl_dynamic.go
- dsl_saga.go
- journal_helpers.go
- library.go
- parallel.go
- pipeline.go
- preprocess.go
- registry.go
- runner.go
- sanitize.go
- state.go
- state_adapter.go
- workflow_testkit.go
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
nexssflow
command
nexssp/flow/cmd/nexssflow/main.go
|
nexssp/flow/cmd/nexssflow/main.go |
|
nexssp/flow/compiler/ast.go
|
nexssp/flow/compiler/ast.go |
|
examples
|
|
|
08_typed_actions
command
|
|
|
Log nodes.
|
Log nodes. |
|
Package runner provides the shared dynamic-flow execution pipeline used by both `nexssflow` (standalone binary) and `nexssp flow` (subcommand).
|
Package runner provides the shared dynamic-flow execution pipeline used by both `nexssflow` (standalone binary) and `nexssp flow` (subcommand). |
|
bootstrap
Assembly is the single composition pipeline for a nexss binary.
|
Assembly is the single composition pipeline for a nexss binary. |
|
bootstrap/console
Package console exposes a small, generic, self-contained web UI for any Nexss binary.
|
Package console exposes a small, generic, self-contained web UI for any Nexss binary. |
|
capability
Package capability resolves flow-node names into runnable action.AnyAction values at flow-execution time.
|
Package capability resolves flow-node names into runnable action.AnyAction values at flow-execution time. |
|
testkit
Package testkit provides flow-runner-specific test helpers.
|
Package testkit provides flow-runner-specific test helpers. |
|
showcase
|
|
|
01_adaptive_rl_router
command
|
|
|
02_self_healing_borg
command
|
|
|
03_evolutionary_optimizer
command
|
|
|
04_grand_showcase
command
|
|