Agentic GitOps: AI Agents That Review, Approve, and Merge Your Infrastructure PRs
GitOps already treats Git as the source of truth for infrastructure. The next step is agents that review the diff against policy, run impact analysis, and merge low-risk changes autonomously — here is where that is heading in 2026.
GitOps solved "how does infrastructure state get applied" by making Git the source of truth and a controller (ArgoCD, Flux) the enforcer. It never solved "who decides whether a change is safe to apply" — that is still a human clicking approve, usually with less context than the CI pipeline already has. Agentic GitOps is that decision moving into the pipeline itself.
What Changes vs Today's GitOps
Today:
Engineer opens PR → CI runs plan/diff → human reads plan output →
human approves → merge → controller syncs
Agentic:
Engineer opens PR → CI runs plan/diff → agent reads plan +
policy + blast radius + recent incident history →
agent approves/denies/escalates → merge (if approved) → controller syncs
The mechanical sync step (ArgoCD/Flux applying what's in Git) does not change. What changes is the approval gate — instead of a human reading a Terraform plan or a Kustomize diff and pattern-matching against "does this look risky," an agent does that read with more context than most humans bother to pull up.
The Review Agent
import anthropic
import json
client = anthropic.Anthropic()
REVIEW_PROMPT = """You are reviewing an infrastructure change for auto-merge eligibility.
PR: {title}
Files changed: {files_changed}
Terraform plan output:
{plan_output}
Recent incident history for affected resources (last 30 days):
{incident_history}
Current blast radius: {affected_resource_count} resources, environments: {environments}
Decide: AUTO_APPROVE, REQUIRE_HUMAN_REVIEW, or REJECT
Auto-approve only if ALL of these hold:
- Change is additive or a well-understood pattern (tag update, scaling within
existing bounds, non-breaking version bump)
- No resource in the plan has had an incident in the last 30 days
- Blast radius is a single environment, not production + staging simultaneously
- No IAM policy or security group change is broadening access
Respond with ONLY valid JSON:
{{"decision": "...", "reasoning": "...", "risk_factors": ["..."]}}"""
def review_infra_pr(pr_data: dict) -> dict:
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=500,
messages=[{"role": "user", "content": REVIEW_PROMPT.format(**pr_data)}]
)
text = response.content[0].text.strip()
if text.startswith("```"):
text = text.split("```")[1].replace("json", "", 1).strip()
return json.loads(text)Why This Is Harder Than It Looks
The failure mode is not "agent approves something obviously bad" — a well-prompted model rarely does that. The failure mode is confident approval of a change that is subtly wrong because the agent trusted a plan output that looked clean but had a side effect the plan diff didn't surface (a Lambda alias flip, a DNS TTL change with downstream caching implications). This is why the guardrails matter more than the review logic itself.
Guardrails That Make This Safe to Run
AUTO_MERGE_SCOPE = {
# Only these resource types are eligible for auto-merge, ever
"allowed_resource_types": [
"aws_autoscaling_policy", "kubernetes_horizontal_pod_autoscaler",
"aws_cloudwatch_metric_alarm",
],
# These always require a human, no matter what the agent decides
"always_human": [
"aws_iam_policy", "aws_security_group_rule", "aws_kms_key",
"aws_route53_record", "aws_db_instance",
],
"max_resources_per_auto_merge": 5,
"environments_eligible": ["staging", "dev"], # never prod, initially
}
def enforce_scope(pr_data: dict, agent_decision: dict) -> dict:
"""Hard-coded rules that override the agent — never trust the LLM alone for the gate."""
changed_types = extract_resource_types(pr_data["plan_output"])
if any(t in AUTO_MERGE_SCOPE["always_human"] for t in changed_types):
return {"decision": "REQUIRE_HUMAN_REVIEW", "reasoning": "Touches an always-human resource type"}
if pr_data["environments"] not in (["staging"], ["dev"]):
return {"decision": "REQUIRE_HUMAN_REVIEW", "reasoning": "Production is not in auto-merge scope"}
if pr_data["affected_resource_count"] > AUTO_MERGE_SCOPE["max_resources_per_auto_merge"]:
return {"decision": "REQUIRE_HUMAN_REVIEW", "reasoning": "Blast radius exceeds auto-merge limit"}
return agent_decision # Only defer to the agent once the hard rules passThe scope list is the actual safety mechanism. The LLM review is a smarter filter within that scope, not the thing defining the scope.
Where This Is Realistic in 2026
- Realistic today: auto-merging scaling policy tweaks, alarm threshold adjustments, and tag/label updates in non-prod — low blast radius, easily reversible, well-understood patterns.
- Not realistic yet: auto-merging IAM changes, network topology changes, or anything touching production databases. The cost of a wrong auto-approve there is too high relative to the time saved.
- The actual win: not removing humans from infra review, but removing humans from the 80% of PRs that are genuinely low-risk, so the review bandwidth that's left goes to the 20% that actually need judgment.
# ArgoCD ApplicationSet annotation pattern for agent-reviewed changes
metadata:
annotations:
devopsboys.com/reviewed-by: "agentic-gitops-v1"
devopsboys.com/review-decision: "auto-approved"
devopsboys.com/review-scope: "staging-autoscaling"Track every auto-approved change with this kind of annotation — you want a clean audit trail showing exactly which merges were agent-approved and under what scope, especially in the first months of running this in production.
More GitOps and AI vision? Read our GitOps will replace ClickOps entirely and Agentic DevOps: autonomous infrastructure management.
Today I Fixed
Short real fixes from production — posted daily
Stay ahead of the curve
Get the latest DevOps, Kubernetes, AWS, and AI/ML guides delivered straight to your inbox. No spam — just practical engineering content.
Related Articles
Agentic DevOps: How AI Agents Will Autonomously Manage Infrastructure in 2026
AI agents that detect incidents, diagnose root causes, execute remediation, and write postmortems without human intervention are already running in production. Here is what agentic DevOps looks like and where it is heading.
Agentic Platform Engineering: AI Agents as the Self-Service Layer in 2026
Internal developer portals promised self-service infrastructure through forms and templates. The next iteration replaces the form with a conversational agent that understands intent, applies platform guardrails, and provisions correctly — closing the gap between what developers ask for and what golden paths actually need.
How to Use AI Agents to Automate Terraform Infrastructure Changes in 2026
AI agents can now plan, review, and apply Terraform changes from natural language. Here's how agentic AI is transforming infrastructure-as-code workflows.