diff options
Diffstat (limited to 'init.lua')
| -rw-r--r-- | init.lua | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -174,6 +174,35 @@ return subagents.workflow(function(ctx) end) ``` +**Deterministic code drives; agents advise.** A workflow is code you control wrapped around judgment you cannot. Put every decision that can be nailed down into Lua — loops, counts, ordering, retries, pass/fail gates — and spend agents only on discovery and judgment. When Lua needs a fact an agent found (a list to fan out over, a verdict, a chosen option), tell that agent to end its report with one machine-parseable line, parse it, and let the parsed value shape the rest of the graph. The sandbox has `json.encode(value)` and `json.decode(text)`, which returns the value or `nil, message`. + +```lua +return subagents.workflow(function(ctx) + local found = ctx:agent{ + name="inventory", + system_prompt="Inventory work items. Read-only.", + prompt="List every open PR in owner/repo. End with exactly one line: RESULT={\"prs\":[<numbers>]}", + }:await() + + local line = found.output and found.output:match("RESULT=([^\n]+)") + local items = line and json.decode(line) + if not items or not items.prs then return "inventory produced no parseable RESULT line" end + + local reviewers = {} + for _, pr in ipairs(items.prs) do + reviewers[#reviewers + 1] = ctx:agent{ + name = "review-" .. pr, + system_prompt = "Review one pull request.", + prompt = "Review PR #" .. pr .. " in owner/repo.", + } + end + + local reviews, out = ctx:await(reviewers, "all"), {} + for _, review in ipairs(reviews) do out[#out + 1] = review.output end + return table.concat(out, "\n\n") +end) +``` + Every `ctx:agent` needs a non-empty `name` unique within that workflow. A workflow callback must return a string. Inspect a running or finished workflow with a later `subagents.lua` call, for example: ```lua |
