How to orchestrate “sub-agents” with Codex CLI (queue/worker pattern) in parallel? MCPs fit? #3898
Replies: 1 comment
|
There are two separate patterns here, and I would not mix them too much. For interactive, human-supervised parallel work, Codex now has first-class subagent workflows. In the CLI/app you can explicitly ask it to spawn agents, for example: Codex handles spawning, waiting, routing follow-ups, and consolidating results. You can also define custom agents under For a true queue/worker system, I would still build the queue outside Codex and run Codex as a worker, not try to make Codex itself be the queue manager. The robust pattern is:
Use Example shape: codex exec \
--cd "$WORKTREE" \
--sandbox workspace-write \
--ask-for-approval never \
--json \
-o "$OUT/result.md" \
"$PROMPT"The biggest design rule: do not let multiple workers edit the same working tree at the same time. For write-heavy work, use one of these instead:
For read-heavy work, parallel subagents are much safer: exploration, triage, test-log analysis, dependency review, docs summarization, security review, etc. For shared state, keep it boring and transactional:
MCP fits, but as an integration boundary, not as the scheduler by itself. Good MCP uses here:
Bad MCP use here:
So I would choose based on the goal:
Your proposed planner-first schema is basically the right direction. I would change two things:
That gives you parallelism without turning the repository into a shared mutable conflict zone. |
Uh oh!
There was an error while loading. Please reload this page.
1. Goal
I’d like to run multiple sub-agents with Codex CLI that collaborate via a queue (producer/consumer). A supervisor agent splitting work and N worker agents processing tasks sequentially or in parallel, with shared state (files/folders).
2. What I understand so far
3. Questions
What I’m thinking (proposal)
Planner-first pattern (one Codex call plans, N workers execute)
Flow
Planner (single Codex CLI run) → outputs a machine-readable task list (JSONL/JSON) with:
id,role,cwd,message,context_files, explicit rules/allowlist (what the worker may touch), and optionaldepsfor ordering.Validator checks/normalizes the planner’s JSON (schema).
Workers run in parallel (Bash, RabbitMQ, or MCP), each consuming one task and applying the rules.
1) Task schema (JSON)
{ "id": "string", "role": "builder | tester | research | <custom>", "cwd": "string", // base folder "message": "string", // brief instruction for the worker "context_files": ["string"], // files to read only "rules": { "write_root": "outputs/<id>/", // write-only sandbox "allow_write_globs": ["outputs/<id>/**"], "forbid_write_globs": ["**/*.lock","runs/**"], "shell_allowed": true }, "deps": ["id-optional"] // tasks that must complete first }2) Planner prompt (Codex CLI)
Example planner output (
tasks.json)[ { "id": "t1", "role": "research", "cwd": "workspace", "message": "Summarize alternatives based on notes/brief.md and specs/A.md.", "context_files": ["notes/brief.md","specs/A.md"], "rules": { "write_root": "outputs/t1/", "allow_write_globs": ["outputs/t1/**"], "forbid_write_globs": ["runs/**"], "shell_allowed": false } }, { "id": "t2", "role": "builder", "cwd": "workspace", "message": "Implement module A in src/, guided by specs/A.md. Produce draft in outputs/t2/.", "context_files": ["specs/A.md","src/"], "rules": { "write_root": "outputs/t2/", "allow_write_globs": ["outputs/t2/**"], "forbid_write_globs": ["**/*.lock","runs/**"], "shell_allowed": true }, "deps": ["t1"] }, { "id": "t3", "role": "tester", "cwd": "workspace", "message": "Write and run tests for module A. Report results.", "context_files": ["tests/","outputs/t2/"], "rules": { "write_root": "outputs/t3/", "allow_write_globs": ["outputs/t3/**"], "forbid_write_globs": ["runs/**"], "shell_allowed": true }, "deps": ["t2"] } ]3) Validate the plan (Node, quick)
4A) Feed workers (Bash, parallel) — with rules applied
4B) Feed workers (RabbitMQ) — same idea, plus leases/retries
All reactions