Workflows
Validated dependency chains, bounded fan-out, and ordered fan-in.
Bash and Zsh
make install, Nix, and release archives install a sourceable library at <prefix>/share/tny/tny-workflows.sh.
. "$HOME/.local/share/tny/tny-workflows.sh"tny_workflow_begin
trap 'tny_workflow_cleanup' EXIT
tny_task architecture --task review --provider codex -- "Audit the architecture"
tny_task tests --task review --provider openai -- "Audit the tests"
tny_task implement \
--after architecture --after tests --no-context --provider codex -- \
"Implement from the architecture report after both reviews finish"
tny_workflow_run --jobs 2
tny_result implement
The two root tasks run together. implement starts only after both succeed, receives the architecture output, and treats tests as ordering-only. --no-context applies to the immediately preceding --after edge.
Execution contract
| Rule | Behavior |
|---|---|
| Preflight | Undefined dependencies and cycles fail before an agent starts. |
| Parallelism | Ready tasks run up to --jobs; default four. |
| Failure | A failure blocks descendants only. Independent branches finish. |
| Context | Successful direct-dependency outputs are appended in declaration order. |
| Ordering only | --after NAME --no-context makes that edge wait without appending output. |
| Storage | Shell tasks are ephemeral by default; captured streams live under TNY_WORKFLOW_DIR. |
Task options
tny_task accepts repeated --after, plus --task, --provider, --model, --effort, --cwd, --system-prompt, --permission-mode, --max-steps, --ssh, --ssh-cwd, --agent, --fast, --persist, --stdin, and --no-context. Arguments are passed directly; the helper never uses eval.
Each task starts in its own process group using setsid, or Perl with POSIX::setsid on macOS, so cancellation can terminate descendants and escalate to KILL after a bounded grace period.
Inspect with tny_status NAME, tny_result NAME, tny_result_path NAME, tny_stderr NAME, and tny_workflow_report.
Runtime task presets
A task preset is reusable runtime configuration: system-level instructions that describe how an agent should approach a workflow node, while the task prompt remains the concrete job. The workflow helper passes --task NAME directly to tny, so the CLI, TUI, SDKs, and shell use the same definitions. Built-ins are review, optimizer, document, retro, and task-creation.
tny_task review-change --task review -- "Review the current diff"
tny_task optimize --task optimizer --after review-change -- "Optimize accepted findings"
tny_task docs --task document --after optimize -- "Document final behavior"
tny_task retro --task retro --after docs -- "Capture durable lessons"
Create a workflow-local type without editing the library:
tny_task_type security-review --stdin <<'TASK'
Act as a security reviewer. Inspect trust boundaries, auth, secrets, and input handling.
TASK
tny_task audit --task security-review -- "Audit this change"
tny_task_types
Custom workflow types remain available for compatibility. They are stored under $TNY_WORKFLOW_DIR/task-types/ and exposed to each child through an explicit TNY_WORKFLOW_TASK_DIR; bodies are resolved by tny, never composed by the shell. The launcher sets an explicit empty value when no workflow-local override applies, preventing ambient path leakage. For persistent cross-surface presets, use .tny/tasks/NAME.md or ~/.tny/tasks/NAME.md. See issue #81.
Python and TypeScript
Both native SDKs expose Workflow with the same validated graph, bounded concurrency, direct-output fan-in, blocked-descendant behavior, and result ordering. Each active task owns a separate native runtime, preserving libtny's owner-thread rules.
# Python
workflow = tny.Workflow(config, max_concurrency=2)
workflow.task("inspect", "Inspect")
workflow.task("tests", "Test")
workflow.task("implement", "Implement", depends_on=(
"inspect", tny.WorkflowDependency("tests", include_output=False)
))
result = await workflow.run_async()
// TypeScript
const workflow = new Workflow({ runtime, maxConcurrency: 2 });
workflow.task("inspect", "Inspect");
workflow.task("tests", "Test");
workflow.task("implement", "Implement", {
dependsOn: ["inspect", { name: "tests", includeOutput: false }],
});
const result = await workflow.run();
Task failures remain values so independent work can finish. Call raise_for_failure() in Python or raiseForFailure() in TypeScript when the aggregate should throw.
Safety and limits
Dependency output is untrusted model text. The envelope labels it as context but cannot eliminate prompt injection. Keep permissions least-privileged and use separate worktrees for parallel agents that write files.
Direct dependency output is bounded to 1 MiB by default. Runs have no implicit retry, cache, distributed queue, or resume policy. The shell reaches every native HTTP CLI profile; SDK workflows use the shared OpenAI-compatible libtny runtime. No external agent bridge is required.