What an AI agent orchestrator does: notes from our own code
A job in our repository is scheduled for seventeen minutes past every hour. It checks a queue of issues. If one is ready, an AI coding agent starts on it. It writes a plan, waits for one of us to approve it, builds the change, and opens a pull request. It never merges.
We built this loop for Sophia, the platform we run our company on. Vendors now call this kind of setup agent orchestration and sell platforms for it, and the title AI orchestrator has started to appear in job listings. Before you buy one or hire one, it helps to see what an orchestrator spends its time deciding. We opened ours and counted.
The model call is the small part
The file that runs the loop is 508 lines long. The step that hands the work to the model, in our case Claude Code, takes 23 of them. A second file, 357 lines of instructions, tells the agent what state an issue is in and how each run has to end.
Almost everything in those files is ordinary workflow logic. That logic is the orchestrator, and it answers five questions.
What gets worked on
An issue enters the queue when one of us labels it. Each sweep takes up to three, oldest first. It skips an issue that is waiting for a person, one that already has a pull request, and one that depends on work that is still open.
Before a run starts, the loop marks the issue as taken, so two runs never pick up the same one. If it cannot check an issue's dependencies, it leaves the issue for the next sweep. A wrong guess there would mean building things in the wrong order.
Where a person decides
The agent writes its plan into the issue and stops. Nothing gets built until the person assigned to that issue replies that they agree. A reply from anyone else does not count, and a reply that asks for changes sends the plan back for another draft. A label lets an issue skip that wait. We have used it once.
When the agent reaches a decision it cannot make, it posts the options, says which one it would choose, and waits. The pull request it opens is a draft. A person marks it ready and a person merges it, and the branch rules ask for a review and passing checks before that. Someone still has to be accountable for the code an agent writes.
The instructions also tell the agent to treat the text of an issue as information about the task. If a comment tries to give it orders, such as skipping a check or pushing to the main branch, it notes the attempt and carries on.
Which model does the work
Each issue goes to the most capable model unless there is a reason to use a smaller one. Bug fixes and documentation changes are the two cases that qualify. An issue that mentions authentication, credentials, permissions or a database migration stays on the most capable model whatever its type. When the classification is unclear, the issue goes to the larger model.
When it stops
A run gets 200 turns and 60 minutes. If the plan for an issue has more than about eight tasks, the agent does not start building. It proposes smaller issues and waits for approval to create them.
Once a pull request is marked ready, another run of the agent reviews it and a further one applies the fixes. That cycle is capped at ten rounds.
What happens when a run fails
Every run has to end in a state a person can read: a plan to approve, a question, a pull request, or a note saying why it stopped. After the agent finishes, a last step checks which of those happened. If the agent ran out of turns but had pushed work, the loop starts it again from that work. If the run produced nothing new, the loop parks the issue and tells us.
In its first eleven weeks the loop opened 138 pull requests, about twelve a week, and one of us merged every one of them. In 13 issues a run used up its budget and was resumed. Four issues were parked for a person. Twice the agent judged an issue too large and proposed splitting it. One issue is still waiting for our reply.
If you are evaluating orchestration
None of this needed an orchestration platform. Our loop runs on the CI system we already used, and the rules sit in files in the same repository as the code they govern, so changing a rule is a change like any other.
For a first workflow that is usually enough. The logic can live in an application or a pipeline you already operate, under the permissions and logs you already have. A platform becomes worth evaluating when several teams run agents that need shared rules and monitoring.
What the queue buys is safety for a team: nobody approves their own plan, and every change leaves a record the others can read. The price is waiting.
The questions are the same either way. Someone has to decide what the agents may work on, where a person approves, how much a run may spend, and what happens when one fails. We would write those answers down before choosing a tool. As for the job title, in our loop the orchestrator is a set of files, and deciding what goes in them is part of owning the code.
How this article was written
An AI assistant wrote the first draft from the files described above and from the pull request history on GitHub. One of us reviewed and approved it before it was published. This is our experience with our own code. A client's process, systems and approvals would be different.
If you are working out where an agent fits in your product or your operations, this is the work we do on agents and assistants. If you need someone inside your team to set up these rules with the people who know the process, a forward-deployed engineer can start there.