OpenCode‘s agents configuration and Beads. A match made in heaven.
My flow until now
Working on a task starts with the Plan agent. I provide an initial prompt of what I want to achieve and the agent responds with a plan. If the plan needs adjustments I ask the agent to update it. When I’m satisfied with the final outcome I move to the execution of the plan. This will happen in one of two ways:
- If the context window is still small I simply change agents1 (move to Build) and ask it to proceed with the execution.
- If the context window is already big I ask the agent to save the plan in a markdown file, start a new session and ask the Build agent to read the file and execute the plan.
This flow works but there are a few drawbacks that bother me:
- There is no human in the loop. I end up reviewing all changes at the end of the execution.
- Even if I start a new session, depending on the size of the plan, the context window might get big causing the agent to misbehave. Especially in changes that must be repeated.
- I usually use Opus for planning and Haiku for execution. There are times though that I forget to make the change ending up using Opus for everything. Opus is good but is also expensive!
- You can’t easily pause the flow and continue from where you stopped.
My new flow
My new flow is based on one agent, one subagent and a database. In particular:
- Like before I start with an agent that will help me build a detailed plan that consists from a number of tasks.
- When I’m happy with the plan I ask the agent to use Beads and save each task under an epic.
- Then I ask the agent to start the execution loop.
Execution loop
- The agent uses Beads to figure out which task must be executed. It changes its status to
in_progressand asks the subagent to execute it. - The subagent reads the task, makes the necessary changes and informs the agent that it finished.
- The agent asks me to review the changes and approve them or not.
- If I approve the changes, the agent commits them, close the task and move to the next one.
- If I request changes, the agent asks the subagent to make them. At this point we move to step 2 again. We remain at this inner loop until I give my approval.
Pinky and the Brain2
If you didn’t make the connection yet, Brain is the name I gave to the agent (type primary) and Pinky is the subagent.
I did not created them on my own. I asked OpenCode to help me by describing the flow I wanted. OpenCode read its own docs, asked me a couple of clarifying questions and came up with these:
Brain: https://gist.github.com/le0nidas/aae1c9f1b35110a00b7157b6c2437444
Pinky: https://gist.github.com/le0nidas/b8a3a89131a639e39e42f7aaf794cf33
Benefits
- I am finally in the loop. I review fewer changes at a time and sooner!
- Using subagents for each task keeps both the agent’s and the subagent’s context window smaller and cleaner ending up in fewer, to none, misbehaviors.
- Brain is tied with Opus and Pinky with Haiku. No need to remember to change anything!
- The best of all, with Beads I can pause and resume whenever I want. The agent knows where to start from!
PS: if you are part of team and don’t want to pollute the codebase with various configurations, you can (a) init beads in stealth mode and (b) exclude .opencode folder from git
- according to the docs, all primary agents share the main conversation hence share the same context window ↩︎
- https://www.imdb.com/title/tt0112123/ ↩︎