跪拜 Guibai
← All articles
Agent · AIGC · AI Programming

A DevOps Agent That Reviews PRs, Diagnoses Outages, and Writes Its Own Postmortems

By 怕浪猫 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Teams already run AI code review and incident-response experiments, but most stop at a chat window. This design wires the agent into the actual delivery pipeline — GitHub webhooks, CI runners, and systemctl — and adds a guardrail layer that blocks irreversible actions without human sign-off. The knowledge-base loop means every outage makes the next one shorter.

Summary

A full-stack DevOps agent built on GPT-4o and LangChain handles the repetitive triage that eats engineering time. It reads Git diffs and Python dependency graphs to post automated code reviews on pull requests. When an alert fires, it searches logs for error patterns, checks service health, and proposes a fix — but refuses destructive actions like restarts until a human confirms.

The agent integrates directly with GitHub via webhooks and Actions, so every opened or updated PR triggers a review without manual invocation. On the operations side, it wraps systemctl, grep, and log analysis into tools the LLM can call, then structures every resolved incident into a vector-searchable knowledge base.

A postmortem generator turns diagnosis and resolution data into a formal report with LLM-suggested prevention measures. The result is a closed loop: the agent reviews code, responds to production issues, and grows a searchable memory of past failures so future incidents resolve faster.

Takeaways
Git diff and file-reading tools give the agent enough context to review code without exceeding the LLM’s context window.
Python import analysis via AST parsing lets the agent reason about dependency changes, not just surface-level diffs.
Log search and error-pattern tools use grep and shell pipelines, keeping the agent fast without shipping logs to an external service.
Service restart is wrapped in a tool that requires explicit confirmation, preventing the agent from acting on destructive impulses.
GitHub webhook verification uses HMAC-SHA256 to ensure only legitimate events trigger the agent.
Every resolved incident is auto-structured into a typed Pydantic model and stored in a Chroma vector database for future similarity search.
A PostMortemGenerator class feeds incident data into the LLM to produce a formal report with 3–5 prevention measures.
Conclusions

Wiring an LLM agent directly to systemctl and shell pipelines is powerful but risky; the design’s insistence on a human-in-the-loop for restarts is the right call for production.

Using AST-based import analysis rather than regex gives the agent a structural understanding of Python code, which matters when a dependency change breaks a downstream module.

The knowledge-base loop — auto-creating structured incident records from diagnosis text — turns every outage into training data, making the agent more useful over time without manual curation.

GitHub Actions integration keeps the agent stateless and event-driven, avoiding the complexity of a long-running listener process while still reacting to every PR push.

Concepts & terms
GitHub Webhook
An HTTP callback that GitHub fires on repository events (push, PR open, etc.), delivering a JSON payload to a configured endpoint so external services can react in real time.
Chroma
An open-source vector database that stores embeddings and supports semantic similarity search, often used to give LLMs long-term memory over documents or incident records.
AST (Abstract Syntax Tree)
A tree representation of source code structure produced by a parser. Python’s `ast` module lets tools walk the tree to extract imports, function calls, and other structural information without fragile regex.
AgentExecutor
A LangChain runtime that manages the loop between an LLM agent and its tools, handling tool invocation, result parsing, and iteration up to a configurable maximum number of steps.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗