GitOps for AI Agents Without a Separate Orchestration Layer
Git-based review can govern what agents may do, but runtime must enforce it.

Agents-as-code means defining AI agents in YAML configuration files stored in Git, with prompts, model settings, tool permissions, and budgets governed through pull requests. GitOps for AI agents without a separate orchestration layer uses versioned state, review gates, and reconciliation to govern those definitions. The boundary is execution. GitOps governs what an agent is allowed to do, while its runtime must enforce isolation, session credentials, spending limits, and audit logging.
Why GitOps already contains the primitives agents need
GitOps rests on four principles that map directly onto agent governance. Declarative desired state makes prompts and tool access reviewable. Versioned and immutable history in Git ties configuration to a commit, while pull-based reconciliation removes manual deployment steps. Continuous drift correction brings configuration back toward the state that was approved.
Microsoft’s GitOps reference describes the operational gap as drifting prompts, unreviewed tool changes, laptop deployments, and missing audit and rollback plans. In its architecture, agent definitions, configuration, and infrastructure are version-controlled source code. That makes containerizing an agent and pointing Argo CD or Flux at it a sound starting point. Ellipsis, a cloud agent platform that runs Claude Code and Codex on managed infrastructure from YAML definitions kept in your repo, is one concrete instance of the runtime side. A reconciler can apply approved state, but reviewers still need to see the distinct choices that shape agent behavior.
What agents add that a service deployment does not
An agent’s behavior emerges from its system prompt, model selection, effort setting, tool access, and non-deterministic LLM reasoning. Each configurable input can change what it decides to do. Bundling those inputs inside one opaque container hides their separate risks. In that form, a model swap can look like a memory-limit change in the deployment diff, even though one changes reasoning behavior and the other changes available resources. Review and rollback of the decision under scrutiny then operate on the whole package.
kagent separates these concerns into first-class Kubernetes resources. Its Agent definition contains the system prompt and tool declarations, while a separate Model Configuration resource describes the provider, model, temperature, and token limits. Tool Server resources give access to named tools without requiring access to the whole server. This gives permissions a reviewable boundary. Adding a tool becomes an explicit change to what the agent may call, while reverting a model configuration leaves the prompt and tool permissions untouched.
The same separation extends beyond those three resources. Microsoft’s reference distinguishes instruction files, tool definitions, model configuration, MCP server definitions, orchestration logic, safety settings, and infrastructure configuration. These artifacts affect behavior through different paths. Treating them independently lets a reviewer assess the actual change directly.
How do you define AI agents in YAML and keep them in Git?
An agents-as-code repository separates agent logic, prompts, model configuration, tool declarations, policies, and deployment manifests into distinct paths. The YAML lays out desired state that can be reviewed, with environment variables visible outside the deployment package. A model definition lists the provider, model, and parameters, and an agent definition names its prompt and the tools it may use. Each change gets a focused diff. The precise schema depends on the platform, with kagent providing Kubernetes resources and Microsoft Foundry Hosted Agent providing the managed runtime in Microsoft’s GitOps reference.
A simplified repository layout can begin with Microsoft’s structure. The /src directory has /src/agents, /src/tools, and /src/prompts, while infrastructure is in /infra and workflow automation is in /.github/workflows. Model configuration, named tool capabilities, and policy rules have their own paths outside the agent code. Separation is the principle, with flexibility in the directory tree. It allows reviewers to distinguish a prompt edit from a permission grant before examining either in detail.
The differences between dev, staging, and production belong in Kustomize overlays or Helm values files. The image is built once and promoted. A model change can then move through environments without the agent image being rebuilt. A separately tracked policy repository can hold allowed image registries, required provenance levels, banned resource kinds, and mandatory reviewers. The controller watches that repository with the agent repository, so governance rules also have a versioned approval history.
How the PR gate handles agent-generated commits without producing review fatigue
An agent opening dozens of PRs per day can exceed available review capacity and encourage rubber-stamping. A resource-limit reduction on a critical service illustrates the danger. It may look routine but could cause an outage. The response is to automate analytical validation and reserve human decisions for changes whose consequences warrant them.
Every agent-authored PR must pass schema validation, policy checks, cost estimation, dependency analysis, and a check of drift direction before human review. OPA, Conftest, or Kyverno rules can reject hardcoded secrets, unsigned images, and dangerous RBAC changes. Risk classification then distinguishes comment updates and non-critical tweaks from changes to resource requests or replica counts. Secrets, database connection strings, security policies, production IAM, and network policies require human approval regardless of authorship. Automation does not erase those approval boundaries.
Branch protection must make signed commits and status checks from the policy gate mandatory. Otherwise, direct pushes can bypass the review model entirely. The human role becomes decisional rather than a repeated exercise in checking YAML and policy compliance. This also applies when an agent proposes changes to the repository that governs its own deployment. Authorship cannot confer permission to approve or bypass the gate.
Why agent identity in Git is a different problem from service identity
Traditional CI/CD assumes a human authors the commit and a service account runs the pipeline. Agentic workflows reverse that relationship. The agent authors the change, and a human may or may not review it. An audit record must therefore identify both the agent and the person who authorized its session. A shared machine identity blurs who did what just when that becomes harder to track.
Prompt injection can enter through tool responses or retrieved documents, while repository push rights turn Git itself into a mutable attack target. The controller will faithfully reconcile approved repository state into clusters. Broad credentials can therefore connect compromised reasoning to infrastructure changes. An agent acting for a user must not automatically inherit that user’s full reach.
The governing principle is to treat each agent as an untrusted developer with scoped credentials. Each agent or workflow needs its own GitHub App, GitLab service account, or deploy key, with access limited to the paths and branches it needs. Read-only agents can run without supervision. Any commit path touching production manifests, IAM, or network policy requires an approver, regardless of automation confidence. That identity boundary complements the PR gate rather than replacing it.
What the reconciliation loop needs to log that standard GitOps tooling does not capture
Reconciliation logs describe what changed and when. Agent governance needs the chain of authorization and action behind that change. The record must identify the agent instance, its authorizing human, and the tool calls and arguments that produced the result. Attribution requires the link between the Git change and the session that created it.
That link extends into the sandbox. Relevant records include creation events with the image or template ID, every executed command, exit codes, stdout and stderr references, file mutations, network policy decisions, and teardown status. These records support reproduction and attribution of failed runs. They are not substitutes for reconciliation logs. They describe the execution that those logs do not capture.
Braintrust, LangSmith, Arize Phoenix, Helicone, Galileo, Maxim, and Datadog Agent Observability illustrate the common pattern of adding observability through SDK instrumentation or a proxy. The alternative is a runtime that makes the audit trail structural. Its session record includes agent_id, parent_identity, delegation_scope, tool_name, and a parameter hash as intrinsic execution data. The distinction is whether the record depends on instrumentation being present or belongs to the runtime’s operation.
How to handle cost as a first-class GitOps concern, not a monitoring afterthought
Agent workflows compound spending across reasoning steps, tool calls, MCP servers, subagents, retries, and refinements. A workflow therefore has a different cost structure from a single chat interaction. Correct operation can still produce uncontrolled expenditure. Without a hard session limit, repeated attempts can keep consuming resources even when continued spending is unlikely to complete the task. The account limit becomes the effective boundary.
Budget caps belong in the same YAML configuration as credential scopes. Both define the authority delegated to an agent. Complete cost governance requires hard limits per session, agent, developer, and time window, plus step-level token accounting, tool-call throttling, and escalation gates. Those gates pause execution so a human can approve spending before it goes beyond a threshold. Git records the approved policy, but the runtime must enforce it before the next tool call.
Monthly aggregates arrive too late to provide that control. They describe spending after it has occurred. Efficiency measures can reduce consumption within the approved budget, but they do not replace enforcement. Anthropic’s prompt caching cuts the cost of cached input, while cost-aware routing sends classification and extraction to smaller models and keeps frontier models for synthesis. Governed AGENTS.md files also belong in the repository as a structural per-run cost lever subject to review.
What agents do at each stage of the GitOps pipeline, not just at deploy time
Once these governance boundaries are in place, agents can participate throughout the pipeline. At PR review, they can check policy compliance, run security linting, and estimate cost. After merge, they can verify deployment, score canary health, and trigger rollback when quality metrics degrade. Runtime drift analysis can correlate anomalies with recent Git history. During incidents, agents can propose fix commits, generate runbooks, and attribute a failure to a specific commit or configuration change.
Staged model rollout makes this role concrete. The model configuration changes first in the dev overlay, the controller syncs it, and automated evaluations run. When evaluations pass, the model can move to staging and then production. If quality degrades, reverting the model resource restores the previous selection without changing unrelated agent configuration. The same Git history keeps a record of both the proposed upgrade and its reversal.
With this operating model, humans can leave the checking of each analytical step to automation. Their judgment stays at the decision boundary. Automated evaluation supplies evidence for promotion, while the risk-tiered gate preserves human approval for sensitive changes. Agents can thus operate parts of the delivery pipeline without acquiring unrestricted authority over it. Their proposed actions remain subject to the configuration, identity, and spending controls that govern the deployed agents themselves.
Where standard GitOps must stretch and what a managed layer handles instead
GitOps handles artifact versioning, PR gates, environment promotion, reconciliation, and rollback through Git revert. It does not create an execution boundary. A repository and reconciler cannot isolate an agent from its host, another team’s infrastructure, or sensitive data stores. For production workloads that handle proprietary code, the stated baseline is virtual machine isolation with a dedicated kernel for each agent workload. That protection must exist where the agent runs.
Credentials and budgets require the same separation of responsibilities. The runtime must mint short-lived credentials for the tools needed in a session and revoke them when it ends. Static credentials remain a structural risk even when their configuration is version-controlled. Session spending also needs enforcement before further execution. A complete audit trail must be intrinsic to the session.
A managed platform can supply these execution controls without becoming a competing source of desired state. Git remains authoritative for the agent definition, permitted tools, and approved budget. The platform governs where the agent runs, which credentials it holds during execution, and which actions are recorded. The two layers compose rather than compete. Running Claude Code or Codex on a laptop is a prototype, while checking its configuration into Git and executing it on governed managed infrastructure establishes the production boundary.


