Repository navigation
Conversation
Throwaway prototype to inform an RFC. Root chats get run_workflow and await_workflow behind the user-scoped chat-workflows experiment. - run_workflow compiles a Starlark script, starts it in a background goroutine, and returns a run ID at once. - Each agent()/spawn() step is a child subagent chat with a deterministic ID. The child gets a server-side workflow_report tool whose input schema is the step schema; a valid value ends its turn. - await_workflow waits up to 780 s. When a run ends and no call waits, chatd sends the parent a user message so the model awaits the run. - After a restart, run_workflow with resume_run_id reuses finished steps. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
The sender can still hold the queued message ID when await_workflow reads the result. It then deletes the message itself, so the test waits for the delete.
chat-workflows is user-scoped, so the rules list now has one more entry.
Workflow prototype: results for the RFCThe prototype answers the six RFC questions. All 11 workflow runs on the preview completed. After a coderd restart, no step got a second child chat. Queued steps waited for a 30-second poll, not for a free slot.
Answers
Q1 LanguageThe models wrote these Starlark constructs without help: lists of Limit of this test: each prompt described the structure of the workflow. I did not test vague tasks, long scripts, or a model that writes a wrong script first. The Q1 answer is "yes for clear tasks". Q2 Reports
Both counted events came from 2 steps that I told to break the rules:
Limit of this test: most steps were short (2 to 25 s). Only 3 steps used workspace tools (3 Q3 ReplayThe run had 6 sequential
Q4 Capacitychatd runs at most 10 sub-agent chats at the same time. A run with 15 parallel steps gave these times from step creation to first reply:
No other chats ran at that time. The limit applies to the whole deployment, so on a shared deployment other users' sub-agents also take slots. The first 10 steps ended after about 14 s. Steps 11 to 15 did not start then. They started about 15 s later. The likely cause is that a queued chat starts on the next acquire pass, and chatd runs that pass every 30 s ( For the RFC: each wave of steps above the limit adds up to 30 s of wait, in addition to the step time. Q5 Size
Replace before production:
Q6 Wake
In each chat the prompt told the model to end its turn after Other findings
Not tested
Evidence
Screenshots and videoA run started in the UI, in real time (32 s). The model starts the run, ends its turn, gets the end message, calls wake-demo.mp4The parent chat after the end message. The end message shows as a normal user bubble. The generic tool view shows the script as one escaped JSON string. The restart run. The first A step chat that replied without Generated with |
…ce file run_workflow takes script_path as an alternative to script. chatd reads the file from the chat's workspace through the agent connection, one time, when the run starts. The agent can then fix a script with small edits and start it again without sending the whole script in the tool call. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
A model often sends write_file and run_workflow with script_path in one batch. chatloop runs the calls of a batch at the same time, so run_workflow could read the file before the write. run_workflow now uses SerialToolCalls and runs after the other calls in its step. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
The PR conflicted with main, so GitHub ran no pull_request CI. The one conflict is the root tool list in turn_environment.go: it keeps the new acpTools from main and adds the workflow tools last.
…es (#28758) Moves the subagent tools' logic (`spawn_agent`, `wait_agent`, `message_agent`, `interrupt_agent`, `list_agents`, `list_subagent_models`) out of large inline closures in `subagent.go`. Child chat operations become typed `*Server` functions in `subagent_operations.go` that other code can call, such as the workflow prototype in #31189. The tools become adapters that parse arguments, apply defaults and build the JSON. ## Changes - `subagent_operations.go`: operations take chat IDs, a timeout or a busy behavior and return plain values. `awaitSubagent` wraps `awaitSubagentCompletion` with the computer_use desktop recording and a last status check, and returns the chat, report and recording, a timeout, or a `*subagentStatusError`. `sendSubagentMessage` and `interruptSubagent` are main's, unchanged. `listSubagents` returns unarchived children, most recently updated first. The helpers they call move from main unchanged. - `subagent.go`: keeps main's model override resolution. Each tool parses `chat_id`, applies the wait timeout or list paging defaults, reads the target chat so errors carry its `type`, and builds the JSON. `spawnAgent` validates the `spawn_agent` arguments. - Tool outputs are typed structs whose fields follow sorted key order, so the JSON the model sees is byte-identical to main's map output. ## Behavior No intended behavior change. Error strings, tool names, descriptions and schemas, hook fail-closed handling, the wait loop and recording lifetime match main. `wait_agent` reads the target chat once more, for the recording decision. > Xum (an AI coding agent) rebuilt this PR on behalf of @ibetitsmike. --------- Co-authored-by: Ethan Dickson <[email protected]>
…low errors A missing script_path file returned the agent's internal request URL, because the codersdk.Error from ReadFile prints its method and URL. The error now reads `read script_path "<path>": <message>`, plus the detail when the agent sends one. A compile error named workflow.star even when the script came from a file. compileWorkflow now uses the script_path as the file name, so compile errors and backtraces name the file the model edits.
run_flow is a declarative alternative to run_workflow for an A/B test of the two formats. A flow is a JSON graph: nodes with prompt templates and step schemas, edges with CEL conditions, and an optional CEL output. Any program in the workspace can write the JSON and pass it in flow_path, which reads like script_path. The run lifecycle stays shared. startWorkflowRun now takes a compiled workflowEngine, which the Starlark program and the new flowProgram both implement. The flow runner walks the graph with one cursor: it renders each node, starts its steps through startStep, waits for them, and takes the first edge whose when is empty or true. for_each nodes start one step per item at once and keep null for a failed item. max_visits bounds loops. Resume reuses the step chats because the rendered specs repeat, as for scripts. compileFlow checks the whole manifest before any step runs and returns every problem in one sorted list: unknown fields, bad IDs, types, schemas and max_visits, CEL parse and type errors, unknown nodes.<id> references, template syntax, dangling edges, unreachable nodes and the step budget. Each place in a flow has its own CEL environment, so item outside a for_each node or value outside when is a type error. await_workflow serves both tools. run_workflow and its description are unchanged.




Warning
Do not merge. This is a throwaway prototype. It exists to inform an RFC about workflow scripts in Coder Agents. The code goes away after the RFC.
Summary
A root chat can run a workflow: a Starlark script that starts sub-agent steps, waits for their structured results, and combines them. The work sits behind the user-scoped
chat-workflowsexperiment.run_workflowcompiles the script, starts it in a goroutine on the coderd replica, and returns arun_idat once.agent()andspawn()create child subagent chats (generalorexplore). Each child gets a server-sideworkflow_reporttool whose input schema is the step schema. chatd checks the value withgoogle/jsonschema-go. A valid value ends the child turn. A child that stops without a value gets one reminder, then the step fails (wait()givesNone,agent()fails the script).await_workflowwaits up to 780 s (default 600 s). If the run ends while no call waits, chatd sends the parent a user message that names the run, so an idle parent starts a new turn and callsawait_workflow. A queued message is deleted when anawait_workflowcall reads the result first.run_workflowwithresume_run_id, and finished steps are reused instead of run again. There is no new table.run_workflowtakes the script inline inscript, or asscript_path: the absolute path of a file in the chat's workspace. chatd reads the file through the agent connection one time, when the run starts. The model can then fix a script with small edits and start it again without resending it.run_workflowruns after the other tool calls of its step, so awrite_fileoredit_filescall in the same batch is done before the read.How to try it
PUT /api/experimental/experiments/rules/chat-workflowswith{"mode": "on", "expected_revision": 0}, or start coderd with--experiments chat-workflows. The previeweph-pr-31189has the rule on: https://3000--dev--eph-pr-31189--tk--apps.dogfood.cdr.dev (sign in as[email protected]).run_workflow. Example script:Limits of the prototype
workflow_reportis ignored.ARCHITECTURE.mdhas two TODOs for the human author.Validation
go test ./coderd/x/chatd/... ./codersdk/ -count=1passes. New tests:TestWorkflowReport,TestWorkflowReplay,TestWorkflowRemind,TestWorkflowNotice,TestWorkflowLimit(also with-race -count=2),TestWorkflowScriptPath.golangci-lint run ./coderd/x/chatd/... ./codersdk/ ./scripts/reports 0 issues.script_path: one writes a script, runs it, edits it in place and runs it again. The other edits the file and callsrun_workflowin one batch, and the run logs the edited line.📋 Implementation plan (claims of the approved html-plan)
main(args)and callsagent(),spawn()andwait(). It cannot read the clock, files or the network.agent()step returns a value that matches its schema, or fails. The child getsworkflow_reportwith the step schema as input. chatd runs it on the server. The tool checks the value in Go. If the child stops without a value, it gets one reminder.await_workflowwaits 780 s at most. If no call waits when the run ends, chatd sends the parent a message. Run and step IDs come from stored data. After a restart the model resumes the run and reuses finished steps.wait()run at the same time. A failed step givesNone. Steps above the subagent limit wait in the queue. A run can create 50 steps at most.Decisions: Starlark; the model calls again with the run ID plus a background run that messages the parent; a draft PR with a preview deployment.
Generated with
xum• Model:anthropic:claude-opus-5-5• Thinking:xhigh