Workflow & orchestration
panto-subagents
Delegation and workflows for Pantograph. A primary agent can start specialized child agents, run several at once, and continue their conversations later.
Install
[extensions]
rocks = ["panto-subagents"]For a local checkout, use paths = ["/path/to/panto-subagents"] instead. A paths entry loads the code but installs nothing, so put the dependencies below in panto's own rocks tree first:
TREE="$(echo ~/.local/share/panto/rocks/lua-*)"
luarocks --lua-version 5.4 --tree "$TREE" install toml2lua
luarocks --lua-version 5.4 --tree "$TREE" install api7-lua-tinyyamlThe migrated child runner requires a Pantograph host that provides panto.ext.async.run and owner-loop coroutine resumption. There is no legacy job/wake_fd fallback; older hosts must be upgraded first.
Dependencies
| Rock | Used for | If missing |
|---|---|---|
api7-lua-tinyyaml | Profile frontmatter | Profiles don't load |
toml2lua | Layered config.toml, then workflow profiles | Activation fails |
luv | Filesystem discovery, timers, timing helpers | Ships with panto |
jsonschema | Structured workflow output; optional | A built-in validator handles the schema subset those results use |
Both YAML and TOML parsers are pure Lua.
api7-lua-tinyyamldoes not cover anchors/aliases or plain multi-line scalars; both raise a parse warning rather than silently misreading.- Full-spec
lyamlwas rejected: binding the system libyaml makes the rock fail to build wherever that library is absent. jsonschemais not declared because it needs a system PCRE; without it, a built-in validator handles the schema subset results use.
Configuration
At most five children run concurrently. Extra children queue. Raise the limit in any layered config.toml; later layers win:
[subagents]
max_concurrent = 10max_concurrent must be a positive integer.
Subagent profiles
A profile is a Markdown file with YAML frontmatter:
---
name: reviewer
description: Reviews changes for correctness and missing tests
model: anthropic:sonnet
reasoning: high
---
You are a focused code reviewer. Report only concrete findings.Profiles load recursively from agents/ beneath every config layer, lowest precedence first: the built-in base layer, ${XDG_CONFIG_HOME:-$HOME/.config}/panto/, .panto/, and .panto/local/. A more local profile overrides an earlier one with the same name.
name defaults to the filename. model and reasoning are optional. Each value follows the same precedence: tool call, then profile, then primary agent. Models use full provider:model names.
Loadable agent reference
The primary receives a short discovery and safety hint, not the full orchestration manual. Topics load through std.lua:
return require("subagents.docs").workflow| Topic | Covers |
|---|---|
.delegation | run, models, continuation |
.workflow | Callback API, structured workers, lifecycle |
.recipes | Staging, fan-out, branching |
.inventory | Discovered profiles, workflows, warnings |
Inventories use the same activation-time snapshots as the tools; workflow-local profiles stay local. Static tool descriptions retain inventories and bounded warnings, and the TUI header still shows inventories.
The host installs active tools after extension activation, so descriptions cannot yet confirm whether policy allows std.lua. At session_ready the hint checks the primary's actual tool list, and reports inspection unavailable when std.lua is disabled or namespace registration failed.
All topics are primary-only, checked on every lookup even through Lua's shared require cache. Loading docs never registers or exposes a child namespace. This preserves lane visibility, not a sandbox for unsandboxed Lua.
Prompt-cost baseline, with no configured profiles or workflows and a cl100k_base tokenizer, so provider tokenizers may differ:
| Measure | Before | After | Change |
|---|---|---|---|
| Injected guidance | 1,466 tokens (5,916 B) | 169 tokens (741 B) | −88% |
| Guidance plus tool descriptions | 1,671 tokens | 431 tokens | −74% |
Configured inventories still contribute to static tool descriptions. The specs execute every fenced Lua reference example and bound hint size; mise run e2e checks discovery, loading, and child isolation against the host.
Delegation
Start a background child from a profile:
subagents.run {
profile = "reviewer",
prompt = "Review the authentication changes.",
}Or skip the saved profile with an inline system prompt:
subagents.run {
system_prompt = "You are a focused code reviewer.",
prompt = "Review the authentication changes.",
}profile, system_prompt, and id are mutually exclusive.
Each call returns a session-scoped name such as agent-1 immediately, and the child continues on Pantograph's event loop. Terminal completion wakes the primary. A std.lua script can read its field-read-only record:
local a = subagents.agents["agent-1"]
return a.status .. (a.output and ("\n" .. a.output) or "")Each child runs through the host's panto.ext.async coroutine stream. The extension consumes progress events on one host-scheduled coroutine per admitted child; it owns no polling descriptors or loop watchers. jobs.await parks only a yieldable caller and raises requires a yieldable coroutine if it would need to park a plain script.
The record exposes name, status, output, error, id, and cancel(). The id is the durable child conversation ID:
subagents.run {
id = "0198...",
prompt = "Now focus on the missing tests.",
}Children start a fresh conversation with the fixed child-role instruction and their profile prompt; the primary's system prompt and conversation are not copied. They share its workspace and tools except for subagents.*.
Multiple calls run independently in the background, and their tagged assistant and tool activity is visible in the TUI while they work.
Child conversations are stored as normal JSONL sessions beneath their owning primary session. They stay resumable without appearing in the /resume picker, and a child ID cannot be resumed from another primary conversation.
subagents.models provides bounded search and validation for configured providers, models, and model-specific reasoning levels without placing the whole catalog in every tool prompt.
Workflows
A workflow profile is a TOML file defining a fixed dependency graph. Workflows load from workflows/ beneath the same config layers as profiles, then surface as /workflow:<name> commands and the subagents.workflow tool.
The tool is omitted only when the discovery inventory is empty; invalid entries still count. Load .inventory for the list and any discovery warnings.
Ready steps run concurrently, and each dependent step receives its predecessors' labeled outputs. The workflow reports its terminal steps, or exactly the steps a top-level output = ["id", ...] array names, in that order.
A workflow can define profiles only it uses:
[profile.ship-auditor]
description = "Audits one repo before release" # optional
model = "anthropic:sonnet" # optional; inherits the primary
reasoning = "high" # optional; inherits the primary
system_prompt = """
You audit one repository...
"""name defaults to the section key. Workflow-local profiles shadow discovered ones of the same name and never appear in the primary's profile list.
Both entry points run the workflow in the background, like workflows started from std.lua. The tool returns its workflow id.
The command instead records the typed line and an equivalent subagents.workflow call in the primary's history. That renders as the call's live progress board, survives a resume, and tells the primary the workflow is running; the conversation can continue meanwhile.
Completion wakes the primary with the usual workflow notice, and the report is subagents.workflows[id].result. A command-started workflow survives interrupting a primary turn.
For dynamic branching and fan-out, start a workflow from a std.lua script:
subagents.workflow(function(ctx)
local a = ctx:agent { name = "draft", profile = "writer", prompt = "Draft it." }
local b = ctx:agent { name = "check", profile = "reviewer", prompt = "Review: " .. a.output }
return b.output
end, { profiles = { ... } })The script receives its field-read-only workflow record. Optional opts.profiles are scoped to that workflow and shadow discovered profiles. Work continues on Pantograph's event loop; completion wakes the primary, and later scripts can inspect subagents.workflows[id], including named child status and outputs.
Workflow records render the progress board in their std.lua tool entry, and resume replay reattaches that board from durable child data. While one is live the extension emits balanced background_work_start and background_work_end events, so lifecycle integrations remain busy across the primary turn boundary.
Every ctx:agent needs a workflow-unique name, and the callback must return the workflow's string result. Callbacks run in background coroutines, so they cannot call panto.ext.call_tool, panto.ext.start_tool, or tools.*; those belong to the top-level std.lua script.
The hidden single-agent workflows used by subagents.run do not appear in subagents.workflows; only their agent records appear in subagents.agents.
The same read-only tables are exposed to other extensions as panto.ext.workflows and panto.ext.agents. A status of running identifies in-flight background work.
Fields are read-only, but two cancels exist: workflow:cancel() requests cancellation for every running agent, and workflow.agents[name]:cancel() for one. Both return true only while their target is running.
Settled workflow and direct-agent records are saved as JSON under the owning primary session's child store and reloaded at session_ready, so results and IDs survive session rebuilds and restarts. The store is per primary session, not per /tree branch; records from abandoned branches remain visible to keep IDs unique across branches.
Events
Guidance for the primary is installed at session_ready. The header and progress cards use render_header, render_tool_call_complete, render_tool_result, and render_tool_collapse.
While any workflow, including the one behind a subagents.run child, is running, session_end_request vetoes tearing the session down. /new, /resume, /last, /tree and /reload are refused instead of cancelling the work; /reload! forces. session_end (quit, or a forced switch) cancels what is still running and records it as cancelled.
The header's workflow inventory removes its exact workflow:<name> commands from the generic commands row when render_header.commands is available. Invocation and completion are unchanged.
Inline opts.profiles remain scoped to the workflow they start. The API can await one child or a group, and supports one-turn workers whose validated tool input is their structured result. Workflow profiles remain the simpler fixed-DAG surface.
Development
mise provides Lua 5.4 and LuaRocks:
mise run deps # install the rocks into ./.rocks (gitignored)
mise run check # run the specs against that treeWithout mise, install the same rocks with any LuaRocks targeting Lua 5.4 and run lua spec/run.lua from the repo root. panto lua spec/run.lua runs the suite inside panto's own interpreter and rocks tree, skipping whatever cases that tree has no rock for.
The specs are plain Lua asserts, no framework. spec/run.lua loads every spec/test_*.lua, each returning an ordered array of { name, function } cases.
A case asserts and returns nothing to pass, or returns "skip", reason when an optional rock is missing; skips do not fail the run.
spec/fake_ext.lua is a scriptable stand-in for the panto.ext host seam. It queues callback-ready deliveries and resumes stream consumers only when a spec explicitly advances its deterministic harness.