flows

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 23 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package flows reads, checks and writes workflows (spec_043_workflows): steps joined into a graph, in .agents/workflows/<name>.flow.yaml, beside the .md commands there.

Index

Constants

View Source
const (
	// Agent runs an agent on the step's instructions and its input.
	Agent = "agent"
	// Refine has an agent improve its input as the instructions say.
	Refine = "refine"
	// Script runs a skill's script, its input as its last argument.
	Script = "script"
	// Browser has an agent reach a goal with its browser tool.
	Browser = "browser"
	// Accumulate joins its inputs, each under its step's title.
	Accumulate = "accumulate"
	// Summarize has an agent sum up its input.
	Summarize = "summarize"
	// ReadFile reads a workspace file: its text is the step's output.
	ReadFile = "read_file"
	// SaveFile writes its input to a workspace file (asked first).
	SaveFile = "save_file"
	// Extract pulls named fields out of its input (a model, to a schema):
	// they're its data.
	Extract = "extract"
	// MCPCall calls a tool of an MCP server; A2ACall sends a message to a
	// remote agent (A2A); APICall makes an HTTP request (WF-14).
	MCPCall = "mcp_call"
	A2ACall = "a2a_call"
	APICall = "api_call"
	// Call runs another workflow on its input (BPMN's call activity).
	Call = "workflow"
	// HumanTask waits for a person to fill in its form (A2UI); Timer
	// waits for a time (WF-16).
	HumanTask = "human_task"
	Timer     = "timer"
	// Exclusive takes its first link whose condition holds (else its
	// default); Inclusive every one (else its default); Parallel every
	// link. Each passes its input on.
	Exclusive = "exclusive"
	Inclusive = "inclusive"
	Parallel  = "parallel"
	// Data runs a query on one of the workspace's connections and hands
	// on its result as a table (spec_059_data). Email is shown, not run
	// yet.
	Email = "email"
	Data  = "data"
)

A step's type.

View Source
const (
	OutputTable  = "table"
	OutputChunks = "chunks"
	OutputRows   = "rows"
)

A Data step's outputs (DAT-20): the whole table, or (not run yet) its rows in chunks or one at a time.

View Source
const (
	TriggerManual    = "manual"
	TriggerSchedule  = "schedule"
	TriggerPreCommit = "git.pre_commit"
	TriggerPrePush   = "git.pre_push"
)

The triggers (WF-30).

View Source
const MaxDataRows = 100_000

MaxDataRows is the most rows a Data step may ask for (DAT-20).

View Source
const Suffix = ".flow.yaml"

Suffix ends a workflow's file name.

Variables

DataOutputs are a Data step's outputs, the default first.

View Source
var ErrUnknown = errors.New("no such workflow")

ErrUnknown means there's no workflow of that name.

View Source
var Methods = []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"}

Methods are an API call's HTTP methods.

Modes are the permission modes a workflow can run in, auto first (the default). Plan isn't one: a workflow carries its steps out.

Triggers are every trigger.

Types are the step types, in the order the palette shows them.

Functions

func CallLoops

func CallLoops(all []Flow) map[string]string

CallLoops says which workflows call themselves, through others: for each workflow in a loop, the shortest loop from it ("a → b → a"). Each is a breadth-first search, so workflows that share sub-workflows don't make the paths walked grow exponentially.

func Check

func Check(f Flow) []string

Check says what doesn't hold in f: its name, its steps' types and settings, its edges, and loops.

func CheckExpr

func CheckExpr(expr string) error

CheckExpr reports whether expr is a CEL expression on the variables.

func CheckTemplate

func CheckTemplate(text string) error

CheckTemplate reports whether each {{ … }} in text is an expression.

func DataOf

func DataOf(text string) any

DataOf is the JSON in an answer, if it's JSON alone (a code fence around it allowed): an object or a list.

func Delete

func Delete(dir, name string) error

Delete removes workflow name from dir.

func Eval

func Eval(expr string, vars Vars) (ref.Val, error)

Eval evaluates expr against vars.

func Fill

func Fill(text string, vars Vars) (string, error)

Fill replaces each {{ expression }} in text with its value: text as it is, anything else as JSON.

func FillValue

func FillValue(v any, vars Vars) (any, error)

FillValue is v (a map, a list, a string, or anything else as it is) with each string's templates filled in; a string that is one template alone takes the expression's value, not its text ("{{ steps.a.data }}" stays an object).

func Holds

func Holds(expr string, vars Vars) (bool, error)

Holds evaluates a condition: it must be true or false.

func IsAgentType

func IsAgentType(t string) bool

IsAgentType reports whether a step type is run by an agent (a turn).

func IsFlow

func IsFlow(file string) bool

IsFlow reports whether a file name is a workflow's.

func IsGateway

func IsGateway(t string) bool

IsGateway reports whether a step type routes rather than works.

func List

func List(expr string, vars Vars) ([]any, error)

List evaluates a for-each expression: it must give a list.

func ModeOf

func ModeOf(f Flow) api.PermissionMode

ModeOf is the permission mode f's steps ask to run in: its mode, or auto.

func ParseDuration

func ParseDuration(s string, def time.Duration) (time.Duration, error)

ParseDuration reads a Go duration ("90s", "5m"); "" is def.

func Pauses

func Pauses(t string) bool

Pauses reports whether a step type pauses its run until it's resumed.

func Save

func Save(dir string, f Flow, previous string) (string, []string, error)

Save writes dir/<name>.flow.yaml from f and returns its path, or the problems that keep it from being saved. previous is the workflow edited ("" for a new one).

func SchedulePermissions added in v0.9.1

func SchedulePermissions(f Flow) []string

SchedulePermissions are what a job that runs f may do without asking (spec_043_workflows WF-20), worked out from its steps as they are when the job runs, so a step added or removed later is followed: write the files its save steps save, reach the hosts its service and agent calls call, use its MCP steps' tools, and browse (web:*) for its browser steps. A templated path (reports/{{name}}.md) grants its folder (write:reports/); one whose folder would be the whole workspace, or is outside it (/{{x}}.md, ~/{{x}}.md, ../{{x}}.md), grants nothing, and its step asks (a scheduled run: is refused) as any other write does.

func Text added in v1.2.0

func Text(f Flow) (string, error)

Text is f as Save writes it: what an approval shows as its diff.

func ValidName

func ValidName(name string) bool

ValidName reports whether name can be a workflow's.

Types

type Auth

type Auth struct {
	// Type is bearer, basic, api_key or oauth2 (client credentials).
	Type string `yaml:"type"`
	// Token is a bearer token.
	Token string `yaml:"token,omitempty"`
	// Username and Password are basic auth's.
	Username string `yaml:"username,omitempty"`
	Password string `yaml:"password,omitempty"`
	// Name, Value and In (header, the default, or query) are an API key's.
	Name  string `yaml:"name,omitempty"`
	Value string `yaml:"value,omitempty"`
	In    string `yaml:"in,omitempty"`
	// TokenURL, ClientID, ClientSecret, Scopes and Audience are OAuth2
	// client credentials'.
	TokenURL     string   `yaml:"token_url,omitempty"`
	ClientID     string   `yaml:"client_id,omitempty"`
	ClientSecret string   `yaml:"client_secret,omitempty"`
	Scopes       []string `yaml:"scopes,omitempty"`
	Audience     string   `yaml:"audience,omitempty"`
}

Auth is how an API call authenticates. Its values take templates and {secrets:key}.

type Edge

type Edge struct {
	From string `yaml:"from"`
	To   string `yaml:"to"`
	// When is a condition (a CEL expression on output, input and steps);
	// If one in plain English, judged by a model. Without either, the
	// link is taken whenever its step succeeds.
	When string `yaml:"when,omitempty"`
	If   string `yaml:"if,omitempty"`
	// Default is taken when none of its step's conditional links is.
	Default bool `yaml:"default,omitempty"`
	// Error is taken when its step fails (instead of stopping the run),
	// with the error as its input.
	Error bool `yaml:"error,omitempty"`
	// Label is what the canvas shows on it.
	Label string `yaml:"label,omitempty"`
}

Edge carries a step's output to another.

func Outputs

func Outputs(f Flow, id string) []Edge

Outputs are the links out of id, in the order they're listed.

func (Edge) Conditional

func (e Edge) Conditional() bool

Conditional reports whether a link has a condition.

type Field

type Field struct {
	Name string `yaml:"name"`
	// Type is string (the default), number, boolean or list (of strings).
	Type        string `yaml:"type,omitempty"`
	Description string `yaml:"description,omitempty"`
}

Field is a value an extract step pulls out.

type Flow

type Flow struct {
	// Name is its file's name without .flow.yaml: run as /name.
	Name        string `yaml:"-"`
	Path        string `yaml:"-"`
	Description string `yaml:"description,omitempty"`
	// Mode is the permission mode its steps run in (WF-21): auto when
	// empty, and never looser than the workspace's.
	Mode string `yaml:"mode,omitempty"`
	// Triggers are what runs it besides /name (WF-30): manual (the
	// default), schedule (a job's), git.pre_commit and git.pre_push (its
	// workspace's git hooks: a commit or push it fails is stopped).
	Triggers []string `yaml:"triggers,omitempty"`
	Nodes    []Node   `yaml:"nodes"`
	Edges    []Edge   `yaml:"edges,omitempty"`
	Problem  string   `yaml:"-"`
}

Flow is a workflow file.

func Load

func Load(dir string) []Flow

Load reads every workflow (*.flow.yaml) in dir, by name.

func Parse

func Parse(name, path string, data []byte) Flow

Parse reads a workflow file; what doesn't hold is its Problem. A key it doesn't know is one: a link's misspelt condition would be taken always.

func (Flow) RunsOn added in v1.1.0

func (f Flow) RunsOn(trigger string) bool

RunsOn reports whether f runs on trigger.

type Form

type Form = a2ui.Form

Form is a human task's form, in A2UI v0.9's basic catalog: components (a flat list, one with id root) and data, the form's starting values; templates in either are filled as the step starts.

type Node

type Node struct {
	ID       string   `yaml:"id"`
	Type     string   `yaml:"type"`
	Title    string   `yaml:"title,omitempty"`
	Position Position `yaml:"position"`
	// Agent is the agent an agent, refine, summarize or browser step runs
	// (none: the active one).
	Agent string `yaml:"agent,omitempty"`
	// Skills are given to the agent with the step's prompt.
	Skills []string `yaml:"skills,omitempty"`
	// Instructions are what the step is to do (a browser step's goal).
	Instructions string `yaml:"instructions,omitempty"`
	// Rules are rules the step's output must pass (judged, as after-agent
	// gates are: spec_041_gates).
	Rules []string `yaml:"rules,omitempty"`
	// Skill and ScriptName are a script step's script; Args its arguments.
	Skill      string   `yaml:"skill,omitempty"`
	ScriptName string   `yaml:"script,omitempty"`
	Args       []string `yaml:"args,omitempty"`
	// Path is a read_file or save_file step's file, in the workspace.
	Path string `yaml:"path,omitempty"`
	// Fields are what an extract step pulls out.
	Fields []Field `yaml:"fields,omitempty"`
	// Server and Tool are an MCP call's; Arguments its arguments (string
	// values take templates).
	Server    string         `yaml:"server,omitempty"`
	Tool      string         `yaml:"tool,omitempty"`
	Arguments map[string]any `yaml:"arguments,omitempty"`
	// URL is an API call's (or an A2A agent's, where its card is); Method,
	// Query, Headers, Body (text) or JSON (a value: string values take
	// templates) and Auth the request's. An A2A call's message is its
	// instructions (its input when none); Headers go with its requests.
	URL string `yaml:"url,omitempty"`
	// Connector is an organization's API connector an API step calls
	// (WF-31): its URL is then a path under the connector, the call made
	// through the organization's service, with its token, as the person.
	Connector string `yaml:"connector,omitempty"`
	Method    string `yaml:"method,omitempty"`
	Query     []Pair `yaml:"query,omitempty"`
	Headers   []Pair `yaml:"headers,omitempty"`
	Body      string `yaml:"body,omitempty"`
	JSON      any    `yaml:"json,omitempty"`
	Auth      *Auth  `yaml:"auth,omitempty"`
	// Connection is the connection a data step queries (one of the
	// workspace's databases); SavedQuery one of its queries, its
	// parameters Arguments (by name), or SQL a statement, its parameters
	// Params (in order). Templates go into parameters only, never into
	// the SQL. Describe is what the SQL was drafted from (DAT-20).
	Connection string `yaml:"connection,omitempty"`
	SavedQuery string `yaml:"saved_query,omitempty"`
	SQL        string `yaml:"sql,omitempty"`
	Params     []any  `yaml:"params,omitempty"`
	Describe   string `yaml:"describe,omitempty"`
	// Output is table (the default), chunks or rows; ChunkRows the rows in
	// a chunk (100 when unset).
	Output    string `yaml:"output,omitempty"`
	ChunkRows int    `yaml:"chunk_rows,omitempty"`
	// MaxRows (1,000 when unset) and MaxBytes (8 MB) are the most of the
	// result it hands on: the rest is cut and said, unless FailWhenCut
	// (DAT-22). AllowWrites lets its SQL write (the run asks first,
	// DAT-21); MaxCost is the most a billed query may cost, in dollars ($1
	// when unset, DAT-24).
	MaxRows     int     `yaml:"max_rows,omitempty"`
	MaxBytes    int     `yaml:"max_bytes,omitempty"`
	FailWhenCut bool    `yaml:"fail_when_cut,omitempty"`
	AllowWrites bool    `yaml:"allow_writes,omitempty"`
	MaxCost     float64 `yaml:"max_cost,omitempty"`
	// Workflow is the workflow a call step runs.
	Workflow string `yaml:"workflow,omitempty"`
	// Form is a human task's form: A2UI v0.9 (components, and data, its
	// starting values); its instructions are shown above it.
	Form *Form `yaml:"form,omitempty"`
	// Wait (a Go duration) or Until (a time, RFC 3339) is how long a
	// timer waits; both take templates.
	Wait  string `yaml:"wait,omitempty"`
	Until string `yaml:"until,omitempty"`
	// ForEach (a CEL expression giving a list) runs the step once per
	// item, Concurrency at a time (4 when unset), item and index in its
	// templates (WF-15).
	ForEach     string `yaml:"for_each,omitempty"`
	Concurrency int    `yaml:"concurrency,omitempty"`
	// Retry tries a failing step again; Timeout (a Go duration) stops a
	// step that runs too long.
	Retry   *Retry `yaml:"retry,omitempty"`
	Timeout string `yaml:"timeout,omitempty"`

	// Secrets are the {secrets:…} its own settings name, as written,
	// before templates are filled (scope, NUL, key): the only ones put
	// into its call, so a filled-in value (an agent's answer, a fetched
	// page) can't name one. Nil until the step is filled.
	Secrets []string `yaml:"-" json:"-"`
}

Node is a step.

func Order

func Order(f Flow) ([]Node, error)

Order is f's steps in the order they run: each after the steps that feed it, otherwise as listed. A loop is an error.

type Pair

type Pair struct {
	Name  string `yaml:"name"`
	Value string `yaml:"value"`
}

Pair is a named value: a header, a query parameter.

type Position

type Position struct {
	X float64 `yaml:"x"`
	Y float64 `yaml:"y"`
}

Position is where a step sits on the canvas.

type Result

type Result struct {
	Text string `json:"text"`
	Data any    `json:"data,omitempty"`
}

Result is what a step produced: its text, and its data when it has some (JSON an agent answered with, an extract step's fields, an API's response).

func (Result) Value

func (r Result) Value() map[string]any

Value is r as CEL sees it.

type Retry

type Retry struct {
	// Attempts is how many times in all (1: no retry).
	Attempts int `yaml:"attempts"`
	// Delay is the wait before the first retry, doubled each time (Go
	// duration; 1s when unset).
	Delay string `yaml:"delay,omitempty"`
}

Retry is how a failing step is tried again.

type Vars

type Vars struct {
	Input  string
	Output *Result
	Steps  map[string]Result
	// Item and Index are a repeated step's (WF-15).
	Item  any
	Index int
}

Vars are what an expression is evaluated against.

Jump to

Keyboard shortcuts

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