Intelligent incident response — an autonomous AIOps agent framework that automates IT operations using a Plan–Execute–Replan loop and LangGraph. The agent does more than answer questions: it behaves as a digital SRE that can diagnose and troubleshoot failures with structured reasoning and tool use.
End-to-end stack (bottom to top): knowledge sources and a vector database feed the core layer (document load/index, retrieval, chat model, prompts, tools, MCP). Agent-style applications (conversational chat, AIOps diagnosis, RAG-backed knowledge use) sit on that core and are exposed through the API layer.
Typical HTTP entrypoints in this repo include POST /chat, POST /chat_stream, POST /upload (and POST /index_directory for batch indexing), and POST /aiops for the diagnostic workflow.
Unlike a linear RAG-only pipeline, this project uses a stateful cyclic graph.
- Strategic planning — The
Plannerturns vague alerts into an ordered list of executable steps (a structured plan rather than a single free-form reply). - Autonomous execution — The
Executorinvokes local tools and MCP (Model Context Protocol) clients to reach live signals (logs, metrics, traces) where your stack exposes them. - Self-correction — The
Replannerevaluates outcomes. If a step fails or the observation does not match expectations, the graph can replan instead of stopping at the first error.
Plan–Execute–Replan flow (Planner → Executor → tools → Replanner → evaluate → loop or END):
- Vector store — Milvus backs semantic search over SOPs, runbooks, and post-mortems.
- Ingestion — Documents under the upload area are split and indexed; typical sources include
.mdand.txtoperational manuals.
RAG overview: ingestion (chunk → embed → store) and query-time retrieval (embed question → search vector store → augment the LLM):
The product exposes two complementary surfaces: an alert-driven AIOps workflow (Plan–Execute–Replan, see above) and a conversational RAG agent for interactive Q&A. This section focuses on the chat agent and how it is observed over the wire.
- Purpose — A tool-augmented chat agent (
RagAgentService) answers questions in context: it can retrieve indexed knowledge, call MCP-backed capabilities, and hold a multi-turn dialogue per client session. - Runtime — Built with LangChain
create_agent, ChatQwen, and a LangGraphMemorySavercheckpointer. The model decides when to call tools; answers are grounded byretrieve_knowledge(Milvus) and extended by MCP tools loaded at startup, plus utilities such asget_current_time. - Session semantics — The client supplies a
session_id; it is mapped to LangGraph’sthread_id, so each session has isolated checkpointed state. Helpers expose session history and clear-session behavior on top of the same checkpointer. - Delivery modes —
POST /chatreturns one JSON payload with the full reply.POST /chat_streamstreams SSE so the UI can render token-level output and structured event types (e.g. content, done, error; the API layer can also forward tool_call / search_results-style events when present in the stream).
- Chat — SSE gives low-latency feedback for long answers and keeps the channel open for structured events alongside raw text.
- AIOps —
POST /aiopsuses SSE to push diagnostic lifecycle updates (e.g. status, plan, step completion, final summary), analogous in spirit to chat streaming but tied to the diagnostic graph rather than free-form dialogue.
High-level flow: user input and RAG retrieval (vector store) feed prompt construction; the LLM runs in a ReAct loop—reason, optionally invoke tools (local + MCP), feed tool results back into the model, and exit when no further tool calls are needed, then return the final message.
Service wiring (FastAPI session → agent → checkpointer → tools → Milvus):
flowchart LR
Client[Client · session_id]
API[FastAPI · /chat · /chat_stream]
Agent[create_agent + ChatQwen]
CP[(MemorySaver · thread_id)]
Tools[retrieve_knowledge · MCP · get_current_time]
DB[(Milvus)]
Client --> API --> Agent
Agent --> CP
Agent --> Tools
Tools --> DB
| Area | Technology |
|---|---|
| LLM orchestration | LangGraph, LangChain |
| LLM | Qwen (via Alibaba Cloud DashScope / langchain-qwq) |
| Vector store | Milvus |
| API | FastAPI, SSE-Starlette |
| Tooling protocol | MCP (Model Context Protocol) |
| Logging | Loguru |
├── app/
│ ├── agent/
│ │ ├── aiops/ # LangGraph nodes: planner, executor, replanner, state
│ │ └── mcp_client.py # MCP integration
│ ├── services/ # Orchestration, RAG agent, embeddings, indexing pipeline
│ ├── api/ # REST and SSE endpoints
│ ├── core/ # Shared infrastructure (e.g. Milvus client)
│ ├── models/ # Pydantic request/response models
│ ├── vector_index_service.py # Manual / directory indexing entrypoints
│ ├── vector_search_service.py
│ └── rag_agent_service.py
├── uploads/ # Ops manuals and docs for RAG ingestion
└── main.py # Application entrypoint (if present in your deployment)
Adjust paths if your fork moves services under a different package layout.
- Python 3.10+
- Docker (recommended for Milvus standalone)
-
Clone the repository
git clone https://github.com/your-username/aiops-pilot.git cd aiops-pilot -
Environment
Create a
.envfile (names may vary; align withapp.configin your tree):DASHSCOPE_API_KEY=your_key_here MILVUS_HOST=localhost MILVUS_PORT=19530
-
Install dependencies and run
pip install -r requirements.txt python main.py
If you use Uvicorn directly, point it at your FastAPI application module as defined in your project.
- Trigger — An alert arrives: High CPU usage on DB-01.
- Retrieve — The agent queries the vector index for runbooks matching “high CPU database”.
- Plan — The planner emits steps such as: inspect top processes → inspect slow queries → inspect connection pool.
- Execute — The executor runs tools (e.g. log or metrics queries via MCP or local adapters).
- Replan — If new evidence appears (e.g. deadlock), the replanner updates the plan (e.g. targeted process or session actions).
- Report — A concise root-cause and remediation summary is produced for operators.
These choices are intentional trade-offs, not accidental defaults.
Search is configured with L2 on the embedding vectors. For dense embeddings trained with cosine-style geometry, L2 on normalized vectors is closely related to angular distance; Milvus optimizes ANN search for common metric types including L2. The scores returned are distances — lower is more similar — which keeps ranking semantics straightforward for debugging and for thresholding in ops workflows.
The planner’s plan is modeled as a typed schema (e.g. a list of steps) rather than unconstrained prose. That yields:
- Deterministic downstream behavior — The executor consumes a list of steps, not a blob of text that must be reparsed.
- Validation at the boundary — Invalid or empty plans fail fast instead of corrupting the graph state.
- Easier testing — You can assert on structured plans in unit and integration tests.
Together, fixed retrieval metrics and structured planning outputs make the agent easier to reason about in production than a fully free-form “vibe-only” chain.
Distributed under the MIT License. See the LICENSE file in the repository for full text.



