When Your Agent Fleet Grows Past Five the GitOps Discipline You Already Know Scales It
GitOps discipline can govern a growing fleet of AI agents.

Agents-as-code means defining AI coding agents in YAML configuration files stored in Git, so changes to their behavior go through normal pull request review. The definition specifies tools, credential scope, network rules, behavior, and budgets. Once a fleet grows past five agents, the GitOps discipline already used for infrastructure provides the governing model, combining versioned definitions with policy-gated execution and attributable change history.
Why a fleet of agents breaks the tools and habits that worked for a few
Running one or two AI coding agents is an experiment. Running five or more becomes an operational problem. At small scale, one developer can own the configuration, credentials can live in a shared secret, and inference spend can remain a rounding error on the cloud bill. Past a handful, those arrangements produce shared service accounts, silently diverging configurations, and sessions whose cost can exceed a month of normal API spend.
Autonomy makes that informality harder to contain. Agents read repositories, run tests, interpret failures, and iterate across multi-file changes before a developer reviews the first diff. Their execution loop combines context gathering, planning, code generation, execution, and iteration, so a bad state can persist beyond one failed response across retries. Each retry can accumulate more context and compound spending. The operational unit is thus the whole session, which can include more than one suggestion.
The four failure modes that appear predictably when an agent fleet grows
Config drift means agent behavior diverges without an explicit decision to change it. Definitions differ between environments or teammates, leaving no canonical account of what an agent should do. One developer may notice a change in one agent. Across a fleet, what one developer remembers cannot show which configuration was intended.
Credential sprawl means agents accumulate permissions that outlive their tasks. Broad access is easier to grant than precisely scoped access, especially when sessions share an account. Configuration directories also become a persistence target. Startup commands planted in hidden config directories have been used to steal plaintext API keys from agent configuration files, so keys that were easy to store locally became a way to gain access.
Cost surprise means inference spending grows non-linearly as context accumulates across retries. How long a session runs and how many exchanges it repeats change how much context is processed, so counting agents or estimating the price of a single task misses how spend compounds.
Unattributable changes mean a production defect cannot be connected to a specific agent session, trigger, and configuration without prior instrumentation. An agent can write code and call a deployment API outside the Git workflow. The human commit trail is then absent. These failures are distinct, but each exposes a gap between intended authority and actual execution.
Why these four failure modes are exactly what GitOps was designed to prevent
GitOps is a structural match for these failures. Config drift maps directly to declarative configuration in version control. An agents.yaml file establishes the canonical definition in the same way Terraform configuration establishes infrastructure intent. A behavior change becomes a file change that can be reviewed before merge, rather than an undocumented adjustment on a developer’s machine.
Credential sprawl maps to least-privilege enforcement through scoped, ephemeral credentials. The deployment agent, log-reading agent, and pull-request-opening agent each get their own identity, just as services get different IAM roles. Policy-gated pipelines provide the corresponding mechanism for cost surprise, with a session stopped when its budget policy fails rather than merely reported after spending has occurred.
Unattributable changes map to auditable change history. Infrastructure governance connects a change to a commit, reviewer, and merge event. Agent governance extends that requirement to tool calls, diffs, and recorded reasoning steps attributable to a person or trigger. Git history alone cannot capture a running agent’s actions. The structural match becomes operational only when the versioned policy is enforced during execution and the resulting actions enter an audit trail.
How to store AI agent definitions in Git for normal code review
An agent definition belongs in the repository as a first-class artifact. In the one-YAML-file model, it specifies tools, credential scope, network rules, and behavior configuration, giving the agent a consistent definition at startup. That is configuration rather than bespoke orchestration code. It makes changes to operating policy reviewable without requiring reviewers to reconstruct intent from an implementation.
In Microsoft Foundry’s reference architecture, agent.yaml or prompt definition files go in a standard source-controlled repository. The repository also contains tool configurations, including MCP servers and REST API connectors, and Infrastructure as Code templates. This concrete repository pattern leaves open whether every agent capability can be declared without a programming language. The relevant distinction is whether the agent’s operating definition is a versioned artifact that participates in ordinary review.
That artifact must also be protected from the agent. An agent able to modify its own permission configuration can expand its own authority. Protected paths therefore include .github/, sandbox configuration, lockfiles, and CODEOWNERS, as well as the agent definitions themselves. Pull request review then governs changes to tool permissions, budget limits, and model selection. The review mechanism already exists for code and infrastructure, so the new requirement is to bring agent behavior within its scope.
Sandboxed execution as the runtime enforcement of least privilege
A repository definition states policy but cannot enforce it alone. Runtime isolation supplies the missing boundary. The central model separates the brain from the hands, with the model client outside the sandbox holding the model API key, while the shell, test runner, file edits, and package manager run inside a locked-down container or VM. The execution environment has no host secrets and only restricted network access.
That separation makes least privilege concrete at execution time. The repository can be mounted read-only with one writable output directory, while network access remains offline or passes through an allowlist proxy. Patches are checked mechanically before review, and writes run in a separate job that requires human approval. These controls constrain what execution can do, rather than relying on instructions asking the model to avoid dangerous actions.
Credentials complete the boundary by expiring with the session. Fresh, scoped credentials are minted for each session and revoked on completion, removing the persistent shared account available to a later compromise. NVIDIA’s OpenShell provides a concrete example of kernel-level isolation governed by declarative YAML security policies. The propose/dispose pattern places triggers, inputs, tool permissions, sandbox boundaries, and approval gates in repository configuration, with a variable or feature flag checked by every agent workflow. The specification travels with the repository.
Enforcing budget ceilings inside the session, not after the bill arrives
A staging agent runs short sessions against constrained test cases, while a production agent encounters messier inputs and longer exchanges. Context accumulates as the session proceeds. That gap comes from how the sessions run, so even a carefully estimated task budget needs to be enforced while the session runs.
Staged degradation responds to that gap without immediately terminating useful work. At an initial threshold, routine planning moves from a higher-capability model to a fallback model. At a later threshold, context compression summarizes prior steps and caps new prompt size. At a further threshold, non-essential tools are gated, but required reads are still available.
The hard limit is the point beyond which the session must stop. YAML-driven per-agent budgets define daily limits, per-task limits, alert thresholds, and a pause-and-alert policy on breach. Keeping these policies with the agent definition subjects budget changes to the same pull request review as changes to tool access. Cost policy thereby becomes part of the approved operating configuration, rather than a separate estimate that the runtime is free to exceed. Alerts explain the breach, but the pause prevents further uncontrolled spending.
Full observability of every tool call and diff as the audit trail that makes change attributable
Request rate, latency, and span counts describe system activity, but they do not explain which tool an agent selected, what arguments it supplied, what came back, or how the next recorded reasoning step changed. Attribution requires that semantic sequence. Without it, a resulting diff may be visible while the actions that produced it remain disconnected from their trigger and configuration.
OpenTelemetry has three signals for the agent loop. Traces show the reasoning loop, metrics record how tokens and costs add up, and log events form the audit trail. SDK instrumentation gives the deepest single-session traces, while gateway capture offers broad coverage with less instrumentation work. The interchange format connects both to existing observability tooling. A separate monitoring stack is not required merely because the actor is an agent.
Comprehensive attribution does not require indiscriminate payload retention. In compliance-sensitive environments, default-on production logging should be metadata-only, with tool input and output logging allowed selectively. Redaction transforms belong in both the SDK and the collector, providing defense in depth at the data layer. With those controls, tool calls, diffs, and token usage can be linked to a person or trigger without assuming that every payload belongs in the audit data. The record then supports governance rather than creating an uncontrolled store of sensitive execution details.
The two deployment paths that must coexist, and how GitOps governs both
Prompt-to-deploy lets agents quickly create preview environments and iterate in them. Git-push-to-deploy uses Terraform-defined infrastructure, pull request review, merge, and Git history for production changes. Neither path can simply replace the other. Production gates would impede the experimental loop, while experimental deployment rights would remove safeguards from production.
Qovery’s two-path model illustrates how the distinction works in practice. Preview environments can auto-deploy from a prompt or pull request, anyone can create them, and they auto-destroy on merge. Staging requires team lead approval, while production deployment is Git merge only, with Terraform-defined infrastructure and a full audit trail. Both paths use the same RBAC, audit logging, and cost controls. The policy boundary permits an agent to deploy a preview without granting it production deployment rights.
This is propose/dispose applied across deployment environments. The agent proposes a change through the fast path, while policy decides whether it belongs in preview, staging, or production. That decision does not depend on what the agent requests or promises. Giving agents production rights simply to avoid friction collapses the distinction and removes the approval gate together with the expected audit trail.
What applying this discipline looks like incrementally, starting from wherever a team is today
Move each agent’s definition into a YAML file so that behavioral changes become visible as diffs. Then add the configuration files to CODEOWNERS and require review before merge, protecting the paths that govern permissions and execution. These existing repository controls establish an approved definition before runtime enforcement is attached to it.
The next step is to replace shared service accounts with scoped credentials minted for each session and revoked on completion. This narrows the authority available during execution. Session-level budgets can then enter the same YAML configuration, turning a spending-limit change into a pull request. The runtime must enforce those limits, because a reviewed number in a file does not itself stop inference spending.
Finally, instrument the agent loop with the OpenTelemetry stack already in place. Traces, metrics, and log events make the governed execution attributable, including its tool use, changes, and accumulated cost. A team that starts with observability while leaving shared credentials intact is documenting an over-privileged agent. Agents are ready to run in production when the approved definition, runtime authority, spending policy, and audit record all describe the same system.


