Lessons Learned While Improving Agent Flows

Lessons Learned While Improving Agent Flows

Introduction

Deciding to use an AI coding agent for work was not a matter of installing a single tool. It meant redefining the way we worked. At first, I thought it would be enough to use prompts or skills well. But after a few months, what remained was not the prompts. It was rule documents, failure records, and the repetitive process of turning failures into rules.

In this article, I summarize the structure and background of the agent flow I currently use, along with what works well and what is still lacking. All dates and figures are taken from the records that remain.

What Was the Problem?

The setting is an internal platform. It has an MSA structure in which services such as authentication, organizations, an event broker, and knowledge management are each divided into backend, frontend, and GitOps repositories. The reason this structure is difficult for an agent to handle is that a single feature spans three repositories. Once people learn the structure, they can apply it to a new project without much difficulty, but an agent has to start over from scratch whenever the session changes.

Initially, we proceeded simply. I would explain the requirements, the agent would build them, and I would check the work intermittently before explaining the next step. This approach could not last. The points where a person had to intervene were bottlenecks. Whenever we added a domain model to a microservice backend, we had to run a code generator appropriate to the platform structure and tell the agent that it was complete before it could move on. Similar stoppages occurred at several stages in both the backend and frontend. The intervention also came too late. Trying to correct a wrong direction during implementation meant throwing away all the tokens and time spent up to that point.

After that, I established two principles: "Make every decision that needs to be made before starting the task, and do not involve a person in the normal execution flow" and "When the task is complete, receive a report and make the next decision based on it." The only exceptions were cases where a new decision was needed during execution or an unrecoverable problem occurred. Most of the skills I organized afterward exist to uphold these principles.

The Current Structure

Three Repositories in One Workspace

Each service has its own workspace, with the backend, frontend, and GitOps repositories connected inside it via symlinks. The repositories themselves contain no agent-related directories. Rules, agents, skills, and work documents such as docs and tasks are managed only in this workspace.

image1.png

The reason for grouping the three repositories into one workspace is to track the work history in one place. Building a feature starts with the backend API contract, passes through a frontend stub, and continues through deployment manifests. When the repositories are handled separately, this flow is scattered across three commit histories, and a person has to remember which frontend change was caused by which backend change. If we plan by User Story in a single workspace and commit each repository at every wave, we can find the commits from all three repositories together in a single US document.

Separating rules/ and lanes/ was also an important decision. Since rules/ is automatically included in every context, it must remain small and must not depend on a specific project. lanes/ contains repository-specific stacks, patterns, constraints, and points of caution, which the agent reads directly when needed. When I measured this a month ago, 245KB—about 60,000 tokens—was included in every context while the lane documents were under rules/. I found that coder calls that did not need the lanes/ content at all were starting with 175,000 tokens, so I separated them that same day.

Five Roles and Common Rules

There are five sub-agents, each with a specific role. planner divides a backlog item into Tasks and evaluates itself, refining the plan until it scores above 95. coder implements one Task and does not write tests. test-writer writes tests based only on the specification and interface contract. reviewer evaluates test quality and completeness against the plan, assigning one of PASS, CONCERNS, or FAIL. self-improver analyzes cycles in which problems occurred and proposes improvements to the rule documents, but does not apply them before approval.

There is a reason test-writer is not allowed to see the implementation code. Initially, we had a sub-agent that wrote tests first in a TDD-style process. However, when the tests failed, this agent directly modified the implementation code until they passed. Since all the tests passed, the report showed no problem, but in reality the tests were not validating the implementation; the implementation was being adjusted to fit the tests. So we changed the order. First, the implementation is written. Then the tests are written without reading the implementation code. This rule appears on the first line of the test-writer prompt, and Hook also blocks access to implementation files.

The rules shared by all five sub-agents are collected in one file: "Do not modify files outside your assigned files," "Only the orchestrator makes commits," "Save the report to a file before writing the response," "Keep the response to ten lines or fewer," and "Exit immediately when the task is complete." We added the last rule after an agent that had finished its work woke up three more times, increasing token usage from 320,000 to 370,000.

The run Skill: Completing One Backlog Item from Start to Finish

The orchestrator receives one backlog item and proceeds in the following order.

image2.png

There are two cases in which execution stops midway. If something needs to be decided, it asks a question together with a recommendation. If the problem cannot be resolved by any answer, it puts that backlog item on hold and moves on to the next one. Backlog items with no overlap in modified files are processed concurrently, and a checkpoint commit is left at the end of each wave. Decisions and execution logs are recorded in files immediately. Based on these records, the final report creates a Gantt chart showing time and token usage. Information left only in the context disappears during summarization.

The interview skill comes before the run skill. It listens to the requirements and divides the backlog into Tasks, but the truly important part comes before that. If the requirements are unclear or open to two interpretations, it first runs ducking. Rubber Duck Debugging is a debugging technique in which the person explaining a problem discovers logical gaps while explaining it to a rubber duck. It then goes through a mandatory confirmation step. For every ambiguous point, it presents a recommendation and alternatives, and writes nothing before receiving an answer. We have repeatedly learned that filling gaps with guesses is the most expensive mistake.

The vigen Skill: Eliminating the Last Manual Step

The purpose of creating the vigen skill was not to save tokens. Its purpose was to eliminate the work a person had to do midway between the end of interview and receiving the completion report. Token savings followed as a result.

In the platform backend, once an aggregate and entity are defined, eight types of files—including Event, Logic, Store, and Jpo—must be structured in prescribed forms. The facade layer also has the same mechanical format for command, fetch, and query, and the frontend stub is created by directly carrying over the facade contract. Since the form is completely defined by rules, there is nothing to decide. Originally, people created this code by running a dedicated generator in plugin form, which caused the several stoppages mentioned earlier.

We performed the first round of automation six weeks ago. Instead of having a person run the dedicated generator, we had the agent read the rule documents and write the files directly. We verified the generated result by comparing it byte for byte with the reference code, eliminating human intervention from that generation stage. However, once we entrusted rule-defined work to the agent, mistakes such as omitting markers or field mappings began to occur. Sometimes the code had to be regenerated during review, which wasted a great deal of tokens.

The second round of automation took place four weeks ago. We transferred the rules into four scripts using only the Python standard library. The entity and facade are now generated in a few seconds, without consuming tokens, according to the same rules people previously used with the dedicated generator. planner excludes code generated by these rules from coder's scope of work. From this point onward, in the normal flow, no person intervenes between interview and receiving the completion report.

What Works Well and What Does Not

What works well is that decisions are concentrated at the beginning of the work. In the past, we had to steer the agent or organize the next task at various points during execution. Now, we make the necessary decisions before starting. I am also satisfied that the process of turning failures into rules actually works, and that context size is managed as a cost. Verification results are confirmed through Hooks and a ledger rather than relying on the agent's self-report.

The main shortcoming is that the rule documents themselves have become too large. The run skill body is 33KB, and INCIDENTS is 37KB. We manage them with the principle of deleting as much as we add and with a capacity-measurement script, but their volume continues to grow. As the number of rules increases, so does the number of cases in which agents read them but fail to follow them. The orchestrator also remains a single point of failure. The rule of writing state to files only mitigates this problem; it does not solve it. Strict rules are burdensome for people as well. In a recent cycle that took 204 minutes, nearly half of the total time was spent waiting for the test-writer, which was idle. These problems need to be addressed through a continuous self-improvement loop.

Conclusion

This process also clarified the boundary of automation. Work that required a person to run a dedicated generator three or four times was first converted into rules, and work that required the LLM to interpret those rules was then moved into deterministic scripts. Problems in which agents crossed the boundaries of their roles are not left to prompts alone; they are prevented through a strict execution order and Hooks.

In the end, what mattered was not the number of agents or skills, but when a person intervened. Normal execution is entrusted to agents and scripts, while developers can focus their time on making decisions before the work and evaluating the results.

The remaining tasks are to actually reduce the volume of the rule documents, structurally reduce the number of builds at wave gates to save overall time, and automatically record trends between cycles so they can be used as material for improvement.

dnine

Site footer