A small engine that runs workflows described in JSON as a graph of nodes: each node runs one action, an ordered list of guarded transitions decides where the run goes next, and the state is persisted so a run can pause for an answer and resume.
Deterministic code does the work, guards check every boundary, and a model is called only where judgment is needed — the smallest model that can do it.
Why — the challenges this answers and where it applies: docs/motivation.md.
Quick start (Python 3.13+ and uv):
git clone https://github.com/VlSobProjects/workflow-engine.git && cd workflow-engine
uv sync
uv run workflow-engine run --workflow-file examples/folder-inventory-to-csv.json --input "scan_root:Path=examples" --export-dir out --json
The run walks examples/ and exports two deliverables into out/reports/: a flat CSV inventory
and a report with one table per folder. Its walkthrough is
examples/folder-inventory-to-csv.md.
The same run, and a run of approve-and-copy paused on its question and then answered both ways,
can be read without a clone: the demonstration site
plays a real run of every demonstration step by step and gives each a page of its own, with the
report each session wrote in CI and the two deliverables of the inventory as the run exported them.
The reports are rewritten by hand, by the Demonstration workflow in .github/workflows/demo.yml,
which calls no model. Beside them, every run of the Documentation digest workflow in
.github/workflows/digest.yml — started by hand with a scenario (judged, refined or simple),
the pages and a goal — publishes a page of its own with the digest as PDF and Markdown and the run
report of its session, read by a model on the owner's server; the
digests page sets the scenarios run on the
same pages side by side and lists every run. Both write the gh-pages branch the site is served
from, and .github/scripts/pages_index.py computes the site's pages from the published reports.
Status: in progress, not released.
- Works now: the graph runner with guards, validators and visit caps; persisted, resumable sessions;
interactive
asknodes that pause for an answer;llmnodes calling a model through provider adapters (OpenAI-compatible, LM Studio, Ollama, theclaudecommand run headless), with every call audited; per-visit node records and read commands (show-state,show-journal,show-records);show-definition, the process a definition resolves to with the hash that identifies it; areportcommand writing one self-contained HTML account of a session — graph, path, parameters, artifacts; a self-describing component help (help-components); six shipped example workflows. - Not done: the analysis of a load test, built in a project of its own on captures of a real system under test; agent-assisted authoring measured across vendors (next phase); a release — no package on an index and no delivery channel, so the engine runs from a clone.
Where to read next: the architecture as it is in
docs/architecture/overview.md, the phases in
docs/architecture/roadmap.md, the decisions in
docs/adr/, and how it was built, session by session, in
docs/sessions/. The project is developed with coding agents working
under the rules in docs/rules/; AGENTS.md is their
entry point.
Licensed under the MIT License — see LICENSE.
| Path | Contents |
|---|---|
src/workflow_engine/ |
The engine |
src/workflow_engine_providers/ |
The shipped provider adapters, an add-on package loaded through external_modules |
src/workflow_engine_content/ |
The shipped content components — fetch a page, its text and sections, a PDF — an add-on package loaded the same way |
tests/ |
Tests |
examples/ |
Example workflow definitions and a walkthrough for each |
docs/ |
Rules, architecture, ADRs and session notes |
Python 3.13 or newer. Dependencies are declared in pyproject.toml.
Every command below calls workflow-engine, the console script the package installs. Inside a clone
of this repository, run uv sync once and prefix the commands with uv run. From any other working
directory the script has to be reachable: either point uv at the project with
uv run --project <path-to-repo> workflow-engine ..., or install the package into an environment that
is on your PATH. A bare uv run workflow-engine outside the repository reports program not found.
Every command reads a JSON config file, so the options you'd otherwise repeat on every call
(--work-dir, --storage-dir, --export-dir) can be set once instead. Search order, first match
wins:
--config <path>, if given.<cwd>/.workflow-engine/workflow_engine_config.json, if it exists.- the OS user config directory (
platformdirs.user_config_dir(), e.g.%LOCALAPPDATA%on Windows,~/.configon Linux) under.workflow-engine/workflow_engine_config.json, if it exists — a place for settings shared across every project on the machine. - none of the above exists: the engine creates one with resolved defaults at the runtime root
(
<cwd>/.workflow-engine/unless--work-dir/WE_WORK_DIRsays otherwise) and uses it.
Whichever path is resolved, a file that is not there yet is created with the resolved defaults. That
includes an explicit --config <path> pointing at a file that does not exist: it is written where you
pointed it, not at the runtime root.
So the first command run in a fresh directory writes a starter config there, ready to edit:
| Key | Meaning | Default |
|---|---|---|
work_dir |
Runtime root; sessions live under <work_dir>/sessions/<session_id>/ |
<cwd>/.workflow-engine |
storage.storage_dir |
Where session state and workflow files are kept | <work_dir>/json-storage |
export_dir |
Destination deliverables are copied to on workflow completion; --export-dir on run/resume overrides it per call, and if neither is set nothing is exported |
null |
hard_max_nodes_visited |
Global safety cap on nodes visited per run/resume; config-only, no CLI flag (see "Hitting the hard node cap") | 1000 |
external_modules |
Extra Python module names imported at bootstrap to register plugin components (see "Writing a custom function") | [] |
providers |
The model providers an llm node may name: per provider name, the adapter that answers for it, its endpoint, its default model and the name of the environment variable holding the credential (see "Calling a model") |
{} |
work_dir and storage.storage_dir are also overridable per call with --work-dir/--storage-dir
or the WE_WORK_DIR/WE_STORAGE_DIR environment variables, which win over the config file. Full
precedence and path resolution: docs/architecture/overview.md.
On Windows without long-path support, keep the runtime root short. Artifacts live several levels below
work_dir, so a deep runtime root pushes them past the 260-character limit and the run fails while
writing the deliverable, with pretty_table_write_error and an [Errno 2] message.
examples/ ships six validated templates, each with its own walkthrough:
| Template | What it does | Waits for an answer |
|---|---|---|
folder-inventory-to-csv |
Walks a folder tree and writes what it finds twice: a flat CSV inventory and a report holding one table per folder | no |
flatten-copy-tree |
Copies every file of a tree into one flat directory and reports what it copied | no |
approve-and-copy |
Asks for a decision, and copies the file only if the answer approves it | yes |
reorganize-folder |
Audits a folder tree — hashes, duplicate groups, a category per file — and delivers a reorganization plan as prose and as a moves dictionary | no |
documentation-digest |
Fetches a list of public pages, has a model collect from each what serves a goal, and delivers one PDF digest | no |
support-ticket-triage |
Reads requests to a support desk and names the ticket each is about: a model reads, code confirms the identifier against the text and the known tickets, and what stays undecided is handed to a person with the reason | no |
folder-inventory-to-csv ships in three named variants beside its base definition — described,
tiered and chunked — in which a model writes what each file contains, proposes what to do with
the inventory, and reads a file too large for it part by part. They need a provider configured (see
"Calling a model"), and the "Variants" section of the
walkthrough covers all three.
documentation-digest ships in two variants beside its base definition — judged and refined —
in which a small model decides on every section of every page by its text before a second model
writes the entries, from the chosen sections at once or one section at a time; they name two
providers, judge and worker, and the "The two-phase variants" section of the
walkthrough covers both.
documentation-digest needs the content components and a provider. The components are a second
add-on package, workflow_engine_content, shipped in the wheel and loaded only when the configuration
names it; the PDF writer is its submodule workflow_engine_content.pdf, named on its own, and needs
the optional extra pdf — in a clone uv sync installs it with the development group, an installed
wheel needs workflow-engine[pdf] — without which naming it fails at load rather than in the run:
"external_modules": ["workflow_engine_content", "workflow_engine_content.pdf", "workflow_engine_providers"]help-components then lists fetch_url_to_artifact, html_text_to_artifact,
html_outline_to_artifact, html_sections_to_artifact, html_sections_to_params and
write_pdf_artifact with their error codes. The text and section functions take drop_navigation,
off by default, which leaves out nav elements and lists of nothing but in-page links. What a run fetches is the operator's responsibility: the fetch reads no robots.txt and
refuses no address beyond its scheme.
What holds for all of them is in examples/README.md. What follows here is the
engine's own contract rather than any template's: how inputs are bound, how a question is answered,
how a model is called, how the result is retrieved, and how a session is read.
--input NAME[:TYPE]=VALUE is repeatable; TYPE names a registered codec. help-components lists
codecs under their Python module path (e.g. pathlib._local.Path for Path on this Python version);
the bare name (Path) also resolves and is what the examples use. set-input only binds to a
session that has not started yet; run --input binds and starts in one call.
A Path input accepts native separators — --input "src:Path=C:\data\in.txt" binds the same value as
C:/data/in.txt — because the codec builds a pathlib.Path, which normalizes them. From there the
engine works in POSIX form everywhere: in state.json, in the JSON result, in a node output and in a
guard comparison. Forward slashes are still the safer form to write, for two reasons:
- A typed value is parsed as JSON before the codec sees it, with a fall back to the raw string. A bare
C:\data\in.txtis not valid JSON, so it falls back and arrives intact — but a value that carries its own quotes (--input 'src:Path="C:\data\in.txt"') is valid JSON, and there\dis rejected while\tand\fare a tab and a form feed. The path then binds silently as something else. Do not quote the value inside the assignment; the shell's own quotes around the wholeNAME=VALUEare fine. The same holds for a path inside a JSON answer, where a backslash must be written\\. pathlibnormalizes as it parses:.\reports\outbinds asreports/out. The path still resolves the same way, but the form you get back is not the form you wrote.
A run that reaches an ask node stops and waits: the command reports a paused workflow (exit code
2) and carries the question under data.question — the node, the text of the question, the
declared answer, and the error codes the node accepts. Nothing else happens until someone answers.
approve-and-copy shows a real one.
Answer it with resume --answer <json>, or --answer-file <path> for the same document in a file.
The answer document has one required field, status:
| Field | Meaning |
|---|---|
status |
success or failure. |
values |
The declared answer names and their values. Each is decoded by the codec its declaration names and written to the state. A failure carries none. |
text |
The output text of the node, which the transition guards compare. Defaults to "". |
error_code |
Required on failure: a code from error_catalogue, or the generic answer_failed. |
message |
Free text explaining a failure. |
actor |
Who answered, e.g. operator or agent:reviewer-bot. Recorded in the session journal. Defaults to unspecified. |
Anything else is refused with exit code 4 and changes nothing: an undeclared or missing name, a
value the codec cannot decode, an undeclared error code, a malformed document, or an answer sent to a
run that is not waiting for one. resume without an answer presents the same question again,
consuming neither an attempt nor a visit — that is how a caller who cannot answer hands the question
on.
An answer the node's transitions do not accept can be routed back to the same question, and the
node's max_attempts bounds that. It counts the repeats after the first run of the node, not the
runs: max_attempts N runs the node at most N + 1 times in one visit, so the default 3 asks at
most four times. When the repeats run out the node fails under max_attempts_exceeded. The bound
covers one visit only — leaving the node resets it, so a correction routed through another node
comes back as a fresh visit and starts the repeats over. A
node that a loop can re-enter that way is bounded by the optional max_visits — see "Bounding a
loop through one node".
Every field of the question is template text: ${param.<name>}, ${output.<node_id>} and
${artifact.<logical_name>} are replaced by the value they name when the question is presented, so
a value stands inside the sentence instead of beside it — "Copy ${param.source_file} to ${param.target_dir}?". $$ writes a literal $, and a field whose whole value is a bare
reference ("context": "param.source_file") keeps working as before. A $ that begins neither of
those refuses the node when the workflow is loaded, reported with the other node configuration
errors before anything runs; a reference that names nothing fails the run at the question instead
of reaching the answerer as written. A list or a dict is written into the text as compact JSON, a
path in POSIX form.
An ask node may also carry function_name and function_parameters, the same keys a function or
a stop node carries. The registered function then runs on an accepted answer, before that answer
becomes the output of the node: it is given the answer as its injected output argument, and what it
returns is the node output — the text the guards compare, the values written to the state, the
artifacts it registered, and the error code that fails the node. A failure answer routes on its own
code and never reaches the function. This is how one node routes on a declared answer value, keeps
every answer of a loop, or normalizes a reply that is nearly right, instead of a second node doing it;
help-component --component-type actions --component-name ask prints the keys and what the function
receives.
Two core functions take that injected answer, and a flow needs no code of its own to use the stage:
echo_answer puts a declared answer value into the output text, so the question that asked routes on
what it bound; collect_answer appends the answer to a list parameter prepared by init_list_param
and answers enough or more, so the question that asks accumulates its own answers and decides
when the loop is over. Both keep the writes the answer carried, and both fail the node under a code
rather than routing a value that is not there.
An llm node is the automatic counterpart of ask: the engine performs the call itself, inside the
run, and the run does not pause. The node names a configured provider, carries the prompt as template
text, and declares what the reply must yield in the same shape as an ask answer and a workflow
inputs block:
{
"id": "CLASSIFY_FILE",
"action_type": "llm",
"action_parameters": {
"provider": "local",
"prompt": "Classify the file ${param.cur_path}. Answer with a JSON object holding \"category\" and \"confidence\".",
"answer": [
{"name": "category"},
{"name": "confidence", "type": "float", "required": false}
],
"format": "json",
"options": {"temperature": 0},
"record": true
},
"max_attempts": 3,
"transitions": [
{"guard": {"no_error": true}, "next": "NEXT_FILE"},
{"errors": ["transient", "rate_limited"], "next": "CLASSIFY_FILE", "attempts": true},
{"errors": ["context_overflow"], "next": "SPLIT_FILE"},
{"fail": "classification_unavailable"}
]
}The prompt is template text under the same rules as the fields of a question: ${param.<name>},
${output.<node_id>} and ${artifact.<logical_name>} are replaced when the node runs, $$ writes a
literal $, and substitution is single-pass, so a value full of $ needs no escaping and cannot
smuggle a reference in. The values the reply carries are decoded through their codecs onto the bus,
and the raw reply is the output text of the node, which value guards compare.
format says how the reply is read. text (the default) binds the whole reply to the one declared
name; a second name is refused when the workflow is loaded. json reads an object whose keys are
the declared names, and takes the first JSON object the reply carries when the model wraps it in a
code fence, surrounds it with prose or annotates a member with a comment — what surrounds or
annotates the object is removed, the object's own syntax is never repaired. A reply the declaration
refuses is the routable node error llm_answer_invalid, with the raw reply still the output text.
A json node also asks the server to constrain what the model generates, derived from the answer
declaration — so a small model that writes broken JSON on every repeat cannot. constrain sets how
far: schema (the default) constrains the reply to the declared names and the form of each declared
type, json to any valid JSON object, and none asks for nothing. The reply is still read and bound
by the declaration exactly as above, so the constraint makes a reply more reliable and never changes
what it means; a declaration without a type constrains nothing but its name, so declare
"type": "str" where a member must be a string. A text reply is never constrained, and constrain
on a text node is refused when the workflow is loaded. An adapter that cannot translate the
constraint still makes the call, and the record of the call says what was applied.
options travels to the adapter unread by the engine: temperature, token limits, and anything else
the named adapter understands, including an instruction about its own resources such as releasing
the model after the call. help-component --component-type providers --component-name <adapter>
lists the options one adapter acts on.
A node names a provider, never an endpoint and never a vendor. The name is resolved in the
providers section of the configuration file, so the same definition runs against a laptop and
against a hosted vendor without being edited:
"external_modules": ["workflow_engine_providers"],
"providers": {
"local": {
"adapter": "openai_compatible",
"base_url": "http://127.0.0.1:1234/v1",
"model": "a-publisher/a-small-model",
"options": {"timeout": 300}
},
"hosted": {
"adapter": "openai_compatible",
"base_url": "https://api.example-vendor.com/v1",
"model": "the-vendor-model-id",
"api_key_env": "EXAMPLE_VENDOR_API_KEY",
"options": {"timeout": 60}
}
}| Key | Meaning |
|---|---|
adapter |
Which registered adapter answers for this name. Required |
base_url |
The endpoint root the adapter hangs its paths off |
model |
The model a node that names none is answered by |
api_key_env |
The name of the environment variable holding the credential, read at the moment of the call. Never the credential itself |
options |
What only the named adapter understands — a request timeout, what a model is loaded with — passed through unread |
A key beside those five is refused when the configuration is read rather than ignored, so a typo is found at load and not at the first model call. A node naming a provider the installation does not configure, and a block naming an adapter no loaded module registered, are configuration errors too: wrong before the run, not during it, and therefore not routable.
Six adapters exist. fake ships in the core: it answers scripted replies without leaving the
process, which is what the test suite and the shipped examples run on. The other five are in
workflow_engine_providers, an add-on package beside the engine that is loaded the way any plugin
is loaded, by naming it in external_modules — openai_compatible speaks the OpenAI-compatible
chat protocol and reaches a local server and a hosted vendor alike, and lmstudio speaks the same
protocol and additionally loads and unloads models on an LM Studio server, releasing only what the
run loaded itself. Both translate the constraint of a json node into the protocol's
response_format and leave a response_format the node sets in its own options as it is. LM
Studio refuses the protocol's JSON-only format, so lmstudio sends the json level as a schema of
any object — the one translation it overrides. A server that speaks the protocol but refuses its
structured output answers invalid_request, its message naming the level sent, and is served the
same way, by a subclass that overrides that one translation.
openai_compatible sends the options it does not act on itself to the server as fields of the
request body. One it acts on is body_fields: in the provider block's options, a mapping of
fields sent in the body of every call, so a server's switch such as {"reasoning_effort": "none"}
is set once in the configuration and never in a definition; a node's own option of the same key
wins. lmstudio and ollama inherit it.
ollama speaks the same protocol to an Ollama server and adds one thing the protocol does not
carry: after an answered call it reads the server's list of running models and reports which build
answered — the digest, the quantization and the context the model is loaded with. A name is not an
identifier there: a tag pulled again points the same name at another model, and the digest is what
tells the two apart in a record. It manages nothing on the server.
ollama_systemone asks a decision model on an Ollama server typed questions about
the prompt — yes or no, one of several options, a level on a scale — and returns their probabilities:
the questions go in the node's options under questions, in the server's own form, and the reply is
a JSON object of question name to answer, so format: json binds the probability of a yes-or-no
question as a float and the answer to the other two as a dict. It releases the models the run
brought onto the server when the run ends, unless it paused, and never one the server already held.
src/workflow_engine_providers/example_config.json carries a filled-in example
of all of it, and help-component --component-type providers lists what the installation has.
claude_cli reaches a model that has no endpoint the engine may call: one answered through the
claude command, typically under a subscription. The block names the adapter and a model and nothing
else — no base_url, no credential:
"subscription": {"adapter": "claude_cli", "model": "sonnet", "options": {"timeout": 300}}The command is an agent when it is started as it comes. The adapter starts it for one turn and takes
the rest away, with a fixed argument list no option reaches: no tool, no server, the operator's
instruction files, hooks and plugins off, no saved session, nobody to answer a permission prompt.
The model receives the prompt on standard input and nothing else: the command's own system prompt is
replaced — by the system option, else by one neutral sentence — and the command runs in an empty
directory created for the call. A reply that took more than one turn fails the call. The options it
reads are system, effort and timeout; every other option of a node is ignored, a temperature
included. What to know before using it:
- It bills nothing it was not told to. A key in
ANTHROPIC_API_KEYorANTHROPIC_AUTH_TOKENwould be used by the command in place of its login, so the adapter removes both from the command's environment unless the block names one inapi_key_env. The report of a call says which answered,command_loginorapi_key, underrequest.credential. - It applies no constraint. The command's schema validation asks the model again on a mismatch,
which is several calls inside one node, so a
format: jsonreply is read from the text andconstraint_appliedisnone. - A limit of a subscription lasts hours. It arrives as
rate_limited, and the adapter retries nothing. A transition that sends the class back to the node withattemptsspends them at once; one that leads to anasknode pauses the session until the operator resumes it. The wording of an exhausted limit was not observed: a failure the adapter does not recognize ispermanent. - A command that is not found is a configuration error at the first call. The block's
commandoption names another command line. - Every call is a process of its own. The command adds its own text around a prompt — about 750
tokens beside a prompt of one sentence — writes the whole prompt to the cache and, in the runs
measured, read none of it back. Two shipped digests measured through it are in
examples/documentation-digest.md.
An adapter that holds a resource is told when the run ends and decides for itself what to release.
If releasing fails, the failure is reported under a provider:<name> key in the errors of the
result and changes neither the outcome of the run nor its exit code: a model left resident on a
server is an operator's problem, not a failed workflow.
Every failure is a node error code a transition can route, so a retry, a smaller chunk or a different branch stays a decision of the graph. The adapter classifies its own failures into six:
| Class | What it says |
|---|---|
transient |
A hiccup; the same call may work again |
rate_limited |
The provider is throttling |
timeout |
No answer within the time the call allowed |
permanent |
The provider refuses and will keep refusing |
invalid_request |
The request itself is wrong |
context_overflow |
The provider refused the prompt as too large |
Three more belong to the action rather than to any provider: llm_answer_invalid for a reply the
answer declaration refused, provider_failed for an adapter that raised instead of classifying its
failure, and llm_record_failed for a call that was answered but whose audit files could not be
written.
context_overflow is a class of its own because the engine carries no tokenizer: the provider's
refusal is the only honest overflow signal there is, and a guard that sees it routes the run into a
branch that splits the data and calls the model per part. The chunked variant of
folder-inventory-to-csv is that branch, built and measured.
A server may also truncate an overlong prompt and answer it without refusing, so a graph can bound
a text before the call: the core guard is_text_length_at_most holds when a text is at most a
configured number of characters — characters, not tokens, chosen with a margin for the window — and
the documentation-digest routes a longer text to its split
branch with it.
There is no retry policy yet: a self-targeting transition bounded by the node's max_attempts is
the whole of it.
Every llm visit is accounted for in the node record of that visit, in its details: the provider,
the model the adapter reported (the one requested where it reported none), the model requested under
model_requested — the model of the node, else the one of the provider block, as it went into the
request — the model the adapter reported under model_answered, null where it reported none or the
call failed, so a reader tells a model the server confirmed from one it never named — the status of
the call, the error class where it failed, the token counts the adapter reported, and the
constraint the node requested and the adapter applied under constraint_requested and
constraint_applied — schema, json, none, or author where the node's own options carried
the adapter's structured output.
What the adapter reports about the call beyond that is the report of the same details, in three
groups: model, what is known of the model that answered; request, what the adapter sent;
metrics, what the call took. A fact is a name with its value and its source:
| Source | The adapter has the fact from |
|---|---|
reply |
the server, in the reply of this very call |
lookup |
the server, in a request of the adapter's own beside the call |
adapter |
itself: what it sent, the time it measured |
"report": {
"model": {"system_fingerprint": {"value": "fp_44709d6fcb", "source": "reply"}},
"request": {"options": {"value": {"temperature": 0}, "source": "adapter"}},
"metrics": {"duration_total_s": {"value": 1.482913, "source": "adapter"}}
}A fact the server does not give is absent — nothing is inferred, and nothing is taken from the name
of a model — and the record of an adapter that reports nothing carries no report. A failed call
reports what it sent and what it took, and no model. Which facts an adapter may report, what each
means and in which unit is its own declaration, printed before any run by
help-component --component-type providers --component-name <adapter> and carried by its --json
form under reported_facts. A few names mean the same on every adapter that uses them, and the
help marks them as reserved: digest, quantization, context_length and context_length_max of
the model, options of the request, and the metrics duration_total_s, duration_load_s,
duration_prompt_s, duration_generation_s and time_to_first_token_s, all in seconds. Every
other name is the adapter's own.
| Adapter | model |
request |
metrics |
|---|---|---|---|
openai_compatible |
system_fingerprint (reply) |
options (adapter) |
duration_total_s (adapter), service_tier (reply) |
lmstudio |
the same, and quantization, context_length, context_length_max (lookup) |
the same | the same |
ollama |
the same, and digest, quantization, context_length (lookup) |
the same | the same |
ollama_systemone |
digest, quantization, context_length (lookup) |
options (adapter) |
duration_total_s (adapter) |
claude_cli |
context_length_max (reply) |
options, credential (adapter), command_version (lookup) |
duration_total_s, time_to_first_token_s, duration_api_s, cost_usd, num_turns, stop_reason, service_tier, cache_creation_input_tokens, cache_read_input_tokens (reply) |
fake |
what its script gives it | what its script gives it | what its script gives it |
The options reported are the fields of the request body beyond the call itself — not the model, not
the prompt, a system message or the questions of a decision call, and not the structured output the
adapter derived from the constraint. The time is measured by the adapter around the request: none of
the three servers states a timing in the reply of these endpoints. The claude command does, so
the timings of claude_cli come from reply; its cost_usd is the command's estimate at list
prices, not a charge under a subscription, and the prompt tokens of its usage include those written
to and read from the cache. fake takes a report in a
scripted entry or as a call option, in the form above.
A looked-up fact is asked of the server after the call and kept per model for the life of the
process, so a resumed session asks again, and lmstudio asks again after a load it performed
itself. A lookup that fails never fails the call: its facts are absent. Between the call and the
lookup the model may have been replaced, and the source says so: only a fact from reply is tied to
the call it is reported for. LM Studio has no digest, and its loaded context is reported only while
the server holds one instance of the model.
workflow-engine show-records --session-id <SESSION_ID> --node DESCRIBE
... DESCRIBE visit 2 attempt 1 llm completed -> node COLLECT guards: no_error=pass writes: file_description (builtins.str, SET) artifacts: DESCRIBE.prompt.2.1, DESCRIBE.reply.2.1 details: {"constraint_applied":"none","constraint_requested":"none","model":"a-publisher/a-small-model","model_answered":"a-publisher/a-small-model","model_requested":"a-publisher/a-small-model","provider":"local","status":"answered","usage":{"prompt_tokens":181,"completion_tokens":17}}
The record stream is where this has to live: the state keeps one slot per node and the next visit overwrites it, so in a chunking branch or a retry loop only the records can say which model answered which call.
The prompt and the reply themselves are artifacts, written when the node sets record: true, named
after the node and numbered by the same visit and attempt the record carries
(<node_id>.prompt.<visit>.<attempt>, <node_id>.reply.<visit>.<attempt>), so the files of one
call and its record are found by the same two numbers. A node at constrain: schema also leaves the
schema the engine handed the adapter, <node_id>.schema.<visit>.<attempt> — the record's
constraint_applied says whether it was sent. They can be inspected after the run or declared
deliverables like any other artifact. A call the adapter answered with a classified failure leaves its
prompt and its schema and no reply; an adapter that raised instead leaves none of them.
The provider block is deliberately not part of the session record: it is the environment a run executes in rather than the identity of the run, so a session moved to another machine resolves the providers of the machine it runs on. What actually answered is in the records instead, per call.
The records are read after the run. A node of the same run that needs the facts of a call — to keep
the model and the token counts beside its own data — reads them from a parameter the llm node names
with save_call_as:
{
"id": "READ_TRIP",
"action_type": "llm",
"action_parameters": {"provider": "local", "prompt": "...", "answer": [...], "save_call_as": "read_call"},
"transitions": [...]
}The parameter is a dictionary written on every way out of the node, a failed call included, so the node a failure transition leads to reads it too:
| Key | Value |
|---|---|
provider |
The provider name the node called |
model_requested |
The model that went into the request: the node's model, else the provider block's |
model_answered |
The model the adapter reported for the answer; null on a failed call |
status |
answered or failed |
error_class |
The error class of a failed call, provider_failed for an adapter that raised; null on an answered call |
usage |
prompt_tokens and completion_tokens, each null where the adapter reported none |
constraint_requested |
The constraint level the node asked for: schema, json or none |
constraint_applied |
What the adapter applied: schema, json, author or none |
report |
What the adapter reported about the call: the groups model, request and metrics, always present, each fact a name with its value and its source; a group is empty where nothing was reported in it |
A function takes it by a reference, param.read_call, like any other input. A reply the answer
declaration refused is an answered call — its node error is llm_answer_invalid, the call itself has
no error class. The node's next call, a retry or a later visit, overwrites the parameter, so it holds
the last attempt; the records keep every call. The name must not be one the answer declaration
binds.
A completed run/resume reports the declared deliverables and every registered artifact by
absolute path in its data. By default the file stays where the engine wrote it, inside the
session's own sandbox — nothing is copied anywhere on completion unless you ask for it:
"deliverables": ["file_scan_table"],
"artifacts": {
"file_scan_table": {
"path": ".../sessions/<SESSION_ID>/artifacts/reports/file_scan_table.csv",
"description": "Pretty table text from parameter: table_rows"
}
}Three ways to get the file itself:
-
Read the absolute
pathdirectly from that output — it points inside the session sandbox, not into the directory you ran the command from. -
Pass
--export-dir <dir>torunorresume(or setexport_dironce in the config file — see "Configuration file"): on completion the engine copies every declared deliverable into<dir>, preserving its relative artifact path. The result reports where they went:"export": { "destination": "<dir>", "exported": {"file_scan_table": "<dir>/reports/file_scan_table.csv"} }
The key is present only when that export ran: a destination was resolved, the workflow declares
deliverables, and the run completed. -
Run
export-artifact --session-id <SESSION_ID> --target-dir <dir> --all(or--artifact-name <name>for one artifact) after the fact. Works for completed, paused and failed sessions.
Four commands read a session, each with one shape of result. All four are info commands: they report
where the workflow stands in workflow_status without taking its exit code, so they answer 0 on
command success and 4 on an unresolvable session or name.
-
show-state --session-id <SESSION_ID>is the state of the run and nothing else: status, last event, errors, current node, the visit counters and budget, the guard answers of the latest attempt per node inguard_results, and what there is to fetch —deliverables,artifacts,artifacts_absoluteandartifacts_path. It carries noparameters, nooutputsand noinputs; those grow with the run and have their own doors below. -
list-parameters --session-id <SESSION_ID>names what the run accumulated —name, the codectypeand thesource_nodethat wrote it — and never a value. -
show-parameter --session-id <SESSION_ID> --name <NAME>returns one value: the plain output is the rendered value, and--jsoncarries the codec envelope exactly as the state keeps it, so the value feedsset-inputof another session unchanged. An unknown name is an error, not an empty answer."data": { "name": "reviewer", "source_node": "ASK_APPROVAL", "value": {"object": "ops", "object_type": "builtins.str"} }
object_typeis the registered codec name, the same onehelp-component --component-type codecslists and--input NAME:TYPE=VALUEaccepts. -
show-journal --session-id <SESSION_ID>prints the session event journal — timestamp, code, actor, event id and details. The whole journal by default;--tail <n>keeps the lastnevents and--node <NODE_ID>keeps the events that name a node, and the two compose. The journal records names, codec names and ordinals, never the values themselves. -
show-records --session-id <SESSION_ID>prints what the run did, one line per concluded node visit — the node with its visit and attempt ordinals, the action and the function it ran, the status with its error code, the guards that were asked, the transition that was taken, and the parameters and artifacts the visit wrote.--tail <n>and--node <NODE_ID>bound and filter it the same way. This is where the history of a loop survives: the state keeps one slot per node and the next visit overwrites it. Like the journal, a record names a value and never carries it.
The state keeps one slot per parameter and per node output, and the next write replaces it. After a
loop, what an earlier visit of a node read is gone. A session created with --keep-entry-state keeps
it: before every execution of an action the engine stores what that execution is about to read.
workflow-engine run --workflow-file my_flow.json --keep-entry-state
workflow-engine show-entry-state --session-id <SESSION_ID> --node <NODE_ID> --visit 2
- The switch is given once, on
runorinit-new-session, and is written into the session record;resumedoes not take it. A session started without it keeps nothing and cannot be given it later. It is off by default: every kept value is one more copy of the data of the run. show-entry-stateanswers for one execution —--visitand, inside a visit that was retried,--attempt(default1), both counted from 1, the ordinalsshow-recordsprints. Under--jsonit carriesparameters, each with itssource_nodeand itsvaluein the codec envelopeshow-parameter --jsonprints;outputs, the output text of every node that had one; andartifacts, the logical names with their paths. The content of an artifact is not kept, so an artifact overwritten later is not restored.- An execution is kept when it starts, so a question left pending has an entry state before it has a record. A question presented again with no answer in between keeps nothing more.
- A record of
show-recordsnames the entry state of its execution inentry_state, for exampleCLASSIFY.2.1, andnullin a session that keeps none. - A value is stored once however many executions read it, so the store grows with what the run writes, not with the number of its visits.
This is how one step is tested alone on what it received in an earlier run: read the entry state of the visit, and bind its values as the inputs of a definition of that one step.
A definition file is not yet the process the engine runs: the engine fills what the file leaves out —
a node's max_attempts, the format of an llm node, an argument a function defaults — and expands
validators into leading failure transitions. show-definition prints the process as the engine
built it, the resolved definition:
workflow-engine show-definition --workflow-file my_flow.json
workflow-engine show-definition --session-id <SESSION_ID>
The first form starts no session and writes nothing, so it also checks that a definition builds: one
that does not is a command error, exit 4, with the configuration errors a run would have reported.
The second resolves the definition a session runs, the same answer on every storage backend. Both
are info commands. The plain output names the hash and one line per node; --json carries the form:
form_version— the version of the form itself,1;process—schema_version,flow_id,start_node_id,inputs,deliverables, every node andfiles. A node carries itsaction, itsparameterswith the defaults applied,save_as,max_attempts,max_visitsand itstransitionsin order, each with itsorigin(validators[0],transitions[1]), itsguardin parts,attempts, and where it leads (kindnode,endorfail, andtarget). A reference such asparam.namestays as written.parameters_sourceisbuiltwhen the action stated its parameters, andwrittenfor an external action that does not, whose parameters are then the ones of the file;files— every file a parameter names, such as a template: the node, the parameter, the path as written, andstatuswithsha256.hashedcarries the hash of the content;missing,reference(the path is aparam.reference, known only at run time) andunresolvedcarry none;hash— the SHA-256 of the canonical JSON ofprocess: UTF-8, keys sorted, no insignificant whitespace. It is the identity of the process. Two spellings of one process share it; a changed parameter, a changed default of the engine and an edited template each change it;components— every registered component the definition names:kind,name,source(coreorexternal),module, and thedistributionthat provides the module with itsname,versionand, for an installation from a version control address,revision. The components stand beside the hash and are not part of it, so the hash does not move with every commit of the engine.
run and resume report the same identity in data.definition:
"definition": {
"form_version": "1",
"hash": "0df9034a…",
"hash_at_start": "0df9034a…",
"form_version_at_start": "1"
}hash is what this call resolved and hash_at_start what the session was created under, kept in its
session record. They differ when the engine or a file changed in between: the run continues, and the
journal gains a definition_resolution_changed event naming both. hash_at_start is null for a
session created before the record kept it.
The read commands each answer one question. report writes one HTML document that answers them
together, for a person reading the run in a browser:
workflow-engine report --session-id <SESSION_ID>
The document lands in the session directory as report.html, and a second report of the session
replaces the first; --output <file> writes it elsewhere instead. The result names the written file
in data.path, beside visits, the number of node records it covers. Like the read commands,
report is an info command: it reads the session, changes nothing in it and answers 0 wherever the
workflow stands.
The document shows how the run ended — completed, failed under a code, or paused, with the command
that continues it — and, on five tabs, the graph drawn and listed, the path of visited nodes with
their guards and transitions and the loops folded, the parameters with their codecs and values, the
artifacts by path relative to the session directory, and the journal. A node opens with its
configuration as written and with its transitions as built, validators expanded. Every tab, node
and visit has an anchor of its own, so a link can point at one visit of a run.
- Values are shown by default, rendered as
show-parameterrenders them and cut at 160 characters; a cut value says so and gives its full length.--no-valuesleaves the values out, and with them the resolved text of a pending question. - The home directory of the machine writing the report is replaced by
~in the values and in the resolved text of a pending question, and the document says so. A path outside it stays as the session names it. The details of the journal are shown as they are stored and are not covered:artifacts_exportednames the destination of an export, so a report of a session exported under a home directory carries that path. - The file carries its styles, its script and its data and loads nothing: it opens from a disk or a static host with no network, and it never reaches the session. It needs JavaScript and says so without it.
- The report is not an artifact of the session and is not exported with the deliverables.
Exit codes: 0 success, 2 workflow paused, 3 workflow failed, 4 command-level setup or
resolution error. A malformed command line is a 4 too: the message and the usage go to stderr, and
with --json stdout still carries one command result with "command_status": "error", so a caller
that parses stdout never gets usage text instead of a document. data carries error_code and
error_message only when workflow_status is failed, naming the code the workflow failed under; an
error a transition routed leaves a completed or paused run without them and stays in errors and in
show-records. Full CLI and artifact contracts: docs/architecture/overview.md.
A session is run by one process at a time. A command that writes the session — run, resume,
set-input, set-limit — holds it for the duration of the call, and a second one asking for the same
session is refused with exit code 4 and a message naming the process that holds it:
Session 6f1c... is held by process 4812 since 2026-08-25T09:14:03+00:00. If that process is gone,
remove the lock file to release the session: <work_dir>/sessions/<SESSION_ID>/session.lock
The hold is that session.lock file in the session directory. Reading a session never waits: the five
read commands and export-artifact answer while a run is in progress.
The lock does not expire, because a node waiting on a slow model call holds its session legitimately for minutes. If a process was killed and left the file behind, delete it — nothing else uses it.
The state file itself is replaced rather than rewritten, so a run interrupted mid-write leaves the previous state readable and the session resumable.
A recursive scan over a large tree can pause with event_code: "workflow_paused_safety_limit" (exit
code 2) well before a short task flow would, because the hard node cap
(docs/architecture/overview.md, "Shape of a run") is one global number. Recovery: raise
hard_max_nodes_visited in the config file (see "Configuration file") and resume the session — the
run continues from where it paused. The cap's long-term scope (host vs. workflow vs. workflow class)
is open, tracked in
docs/architecture/notes/2026-08-19-hard-node-cap-scoping.md.
A node may declare max_visits, a whole number beside max_attempts:
{ "id": "ASK_ROOT", "action_type": "ask", "action_parameters": {}, "max_visits": 3 }The engine refuses to enter the node once it has completed that many visits and fails the run with
"error_code": "max_visits_exceeded" (exit code 3), naming the node. The check happens before the
action, so a question beyond the cap is never published and never paid for, and the node's own
transitions cannot route the exhaustion — it is a failure of the workflow, like
max_attempts_exceeded.
There is no default: a node without the key is bounded only by the run-wide node caps above, which
stop the run at whatever node the budget ran out on rather than at the loop that ate it. Declare
max_visits as a seatbelt, an order beyond the passes the flow expects — a loop designed for up to
ten follow-ups declares, say, thirty. How many passes a task actually needs is flow logic, not a
safety cap: keep that number in the flow data, as a parameter that a guard or a function compares
against, so a run can decide "enough" from its own context.
A function/functions action node calls a Python function registered with @register_function.
The same import-time decorator mechanism registers every kind of pluggable component (see
docs/architecture/overview.md, "Registries"): @register_action
(workflow_engine.registry.action_registry) for actions, @register_validator
(workflow_engine.registry.function_registry) for guard validators, and @register_type
(workflow_engine.registry.type_registry) for codecs. Everything below — the launcher-script path,
external_modules, and the importability requirement — applies the same way to all four; a function
is the concrete example.
Two ways to make one available, both verified against a real run:
Registration is a decorator side effect that runs the moment Python imports the function's module. Define the function and call the CLI in the same process, before any config change:
# run_it.py
from typing import Annotated
from workflow_engine.output import ActionNodeOutput
from workflow_engine.registry.function_registry import register_function
@register_function(summary="Shout a string in upper case.")
def shout(text: Annotated[str, "Text to upper-case"]) -> ActionNodeOutput:
return ActionNodeOutput(output_text=text.upper())
from workflow_engine.cli.main import main
import sys
main(sys.argv[1:])Run it as python run_it.py run --workflow-file my_flow.json --json instead of workflow-engine run .... No external_modules entry needed: the function is already in the registry by the time
the workflow starts.
List the module by its importable name in the config file's external_modules (see "Configuration
file"):
"external_modules": ["my_functions"]The engine imports it with importlib.import_module, Python's standard mechanism — a script merely
sitting next to where you run workflow-engine from is not found on its own. Make the module
importable, either:
PYTHONPATH=<folder-containing-my_functions.py> workflow-engine run ..., or- turn the folder into an installed package (
uv pip install -e .) for anything more than a quick one-off script.
- One
@register_function-decorated function per registration; the decorator takes an optionalsummarystring. - Every parameter needs an
Annotated[<type>, "<description>"]hint; the description surfaces inhelp-component. - The function must declare
ActionNodeOutputas its return type and return one. - A parameter that names a file kept beside the workflow definition adds
DefinitionFile()(workflow_engine.registry.function_registry) to its hint —Annotated[str, "<description>", DefinitionFile()]— soshow-definitionlists the file and its content enters the hash of the process. help-component --component-type functions --component-name <name>shows the registered contract, including whether it loaded from a core or an external module.
Run tests from the repository root:
uv run pytest
The report viewer is checked in a real browser by a separate suite that the default run leaves out.
It needs the browser dependency group and Chromium, which Playwright downloads once:
uv run --group browser playwright install chromium
uv run --group browser pytest -m browser
Read AGENTS.md for the entry point into the project rules, and docs/README.md for the
documentation map.