Commanding the chaos: how AI agents handle enterprise incidents

Oladimeji Samuel Sowole
Data Scientist, Andela
Jul 24, 2026
7 min
Commanding the chaos: how AI agents handle enterprise incidents

At 2:17 a.m., an alert fires. API latency has tripled. Customer transactions are timing out. A Kubernetes node has degraded. A deployment went out twenty minutes earlier. Slack channels begin filling with messages. Someone opens Grafana. Another engineer starts digging through logs while yet another tries to determine whether the issue is infrastructure, networking, or application-related.

If this scenario sounds familiar, it’s because incident response remains one of the most expensive and stressful activities in enterprise engineering.

Monitoring tool sprawl is not the issue; organizations rarely lack dashboards, logs, or ticketing systems. The true vulnerability is coordination. During an active incident, engineers must manually aggregate fragmented data from multiple platforms, delaying the actual investigation and inflating resolution times.

This is where AI agents can provide meaningful value.

Rather than acting as chatbots, AI agents can function as operations command agents: systems that coordinate information across observability platforms, cloud infrastructure, deployment pipelines, and incident management tools to help engineering teams respond more effectively.

In this tutorial, we will build a simplified Operations Command Agent that can:

  • Collect signals from monitoring systems
  • Retrieve relevant operational knowledge
  • Correlate incident information
  • Generate incident summaries
  • Recommend runbooks and escalation paths

Most importantly, we will design it in a way that reflects production realities rather than demo-friendly shortcuts.

Why incident response is an ideal AI agent use case

Many AI agent examples focus on customer support or content generation. While useful, these areas are already heavily explored.

Incident management presents a different challenge. During an outage, engineers often need to answer questions such as:

  • What changed recently?
  • Which services are affected?
  • Have we seen this issue before?
  • Which team owns the failing component?
  • What runbook should we execute?

The information exists, but it is distributed across systems. An Operations Command Agent acts as a coordinator rather than a decision-maker. It gathers context, surfaces relevant information, and assists human engineers without replacing their judgment.

Architecture overview

Our simplified architecture consists of:

Alert

  ↓

Operations Command Agent

  ↓

Telemetry Retrieval Layer

  ↓

Knowledge Base

  ↓

LLM Reasoning Layer

  ↓

Runbook Recommendations

  ↓

Human Engineer

The agent becomes a coordination layer between operational systems and engineering teams.

Step 1: Install dependencies

We begin with a lightweight stack.

```Bash
pip install \
  langchain \
  langchain-openai \
  langchain-community \
  fastapi \
  httpx \
  faiss-cpu \
  pydantic \
  tiktoken
```

These packages provide:

  • LLM integration
  • Retrieval capabilities
  • API services
  • Knowledge indexing
  • Data validation

Step 2: Configure the language model

Production systems should avoid hardcoded credentials and should always include timeout and retry policies.

```Python
import os
from langchain_openai import ChatOpenAI
api_key = os.environ.get("OPENAI_API_KEY")
if not api_key:
    raise ValueError("OPENAI_API_KEY must be configured")
llm = ChatOpenAI(
    model="gpt-4o-mini",
    temperature=0,
    api_key=api_key,
    timeout=30.0,
    max_retries=2
)
```

Notice that we use a low temperature setting because operational systems prioritize consistency over creativity. We also configure the model with an API key from the environment, a request timeout, and a limited retry policy to improve resilience against transient network or service failures in production.

Step 3: Create an operational knowledge base

Incident response often depends on historical knowledge.

We can store:

  • Runbooks
  • Postmortems
  • Escalation procedures
  • Service ownership information
```Python
from langchain_core.documents import Document
from langchain_community.vectorstores import FAISS
from langchain_openai import OpenAIEmbeddings
documents = [
    Document(
        page_content="""
        High API latency can occur when database connections
        exceed configured limits.
        """,
        metadata={"source": "database_runbook"}
    ),
    Document(
        page_content="""
        Kubernetes node failures should trigger
        node replacement procedures.
        """,
        metadata={"source": "cluster_runbook"}
    )
]
embeddings = OpenAIEmbeddings()
index = FAISS.from_documents(
    documents,
    embeddings
)
```

This indexed knowledge base becomes the agent's operational memory, allowing it to retrieve relevant runbooks and historical guidance during incident investigations while using the current LangChain package structure (langchain-core and langchain-community).

Step 4: Simulate monitoring signals

In production, data would come from:

  • Grafana
  • Prometheus
  • Datadog
  • New Relic
  • CloudWatch

For simplicity, we simulate telemetry.

```Python
def get_incident_signals():
    return {
        "service": "payments-api",
        "latency_ms": 4200,
        "error_rate": 12.7,
        "deployment_age_minutes": 20,
        "cluster_status": "degraded"
    }
```

The goal is not to replace observability tools but to aggregate their findings.

Step 5: Retrieve relevant operational knowledge

When an incident occurs, the agent should retrieve relevant documentation.

```Python
def retrieve_context(query):
    results = index.similarity_search(
        query,
        k=3
    )
    return "\n".join(
        doc.page_content
        for doc in results
    )
```

This gives the agent access to institutional knowledge that would otherwise require manual searching.

Step 6: Generate an incident summary

Now we combine telemetry and retrieved knowledge.

```Python
def summarize_incident(signals):
    context = retrieve_context(
        f"{signals['service']} latency"
    )
    prompt = f"""
    Incident Signals:
    {signals}
    Relevant Knowledge:
    {context}
    Create a concise incident summary.
    """
    response = llm.invoke(prompt)
    return response.content
```

The output may look something like:

Payments API is experiencing elevated latency

and increased error rates shortly after a recent

Deployment. Database connection exhaustion and 

cluster degradation should be investigated.

This saves engineers valuable triage time.

Step 7: Recommend operational actions

The next step is recommendation generation.

```Python
def recommend_actions(summary):
    prompt = f"""
    Based on the incident summary below,
    recommend operational actions.
    Summary:
    {summary}
    """
    response = llm.invoke(prompt)
    return response.content
```

Example output:

  1. Verify recent deployment changes.
  2. Check database connection pool utilization.
  3. Review Kubernetes node health.
  4. Execute cluster recovery runbook.
  5. Notify the platform engineering team.

Notice that the agent recommends actions rather than executing them autonomously,

Step 8: Add structured validation

Production systems should validate outputs before presenting them to engineers.

```Python
from pydantic import BaseModel
class IncidentResponse(BaseModel):
    summary: str
    recommendations: str
```
Then validate results:
```Python
def validate_response(summary, actions):
    response = IncidentResponse(
        summary=summary,
        recommendations=actions 
    )
    return response.model_dump()
```

This validation step prevents malformed outputs from propagating through operational workflows and converts the validated response into a standard Python dictionary using Pydantic v2's recommended model_dump() method for downstream processing.

Step 9: Build the operations command agent

Now we assemble everything.

```Python
import logging
logger = logging.getLogger(__name__)
def operations_command_agent():
    try:
        signals = get_incident_signals()
        summary = summarize_incident(
            signals
        )
        recommendations = recommend_actions(
            summary
        )
        return validate_response(
            summary,
            recommendations
        )
    except Exception as e:
        logger.exception(
            "Operations Command Agent failed during incident orchestration."
        )
        # Fail safely by returning an actionable fallback response.
        return {
            "summary": "The Operations Command Agent encountered an error while retrieving incident context.",
            "recommendations": (
                "Escalate to the on-call engineer immediately and continue "
                "the investigation using standard operational runbooks."
            ),
            "error": str(e)
        }
```

This orchestration layer ties together telemetry collection, retrieval, reasoning, and response validation. More importantly, it is designed to degrade gracefully; if the language model, retrieval layer, or another dependency fails, the agent still returns an actionable response instead of terminating the incident workflow.

Running:

```Python
result = operations_command_agent()
print(result)
```

Produces a structured incident briefing.

Why Human Engineers Remain Essential

One of the biggest misconceptions about AI agents is that they should replace operators.

An AI agent may recommend:

  • rolling back a deployment
  • restarting a service
  • scaling infrastructure

But only engineers understand:

  • business impact
  • operational risk
  • compliance implications 
  • organizational context

The most effective systems combine AI-assisted coordination with human decision-making.

Engineering Lessons for Real Operations Teams

Organizations exploring operational AI agents should keep several lessons in mind.

Start with retrieval, not autonomy

Many teams jump directly to autonomous actions. A safer approach is to do the following before allowing automation:

  • gather information
  • summarize findings
  • recommend actions

Trust requires transparency

Engineers need to know:

  • where the information came from
  • which runbooks were referenced
  • why recommendations were generated

Source attribution is critical.

Deterministic workflows beat unbounded agents

Open-ended agent loops can create:

  • runaway costs
  • inconsistent recommendations
  • operational confusion

Structured workflows are easier to debug and trust.

Observability applies to AI systems, too

Operational agents themselves need:

  • logs
  • traces
  • metrics
  • cost monitoring

Otherwise, debugging the agent becomes harder than debugging the original incident.

The most valuable AI agents in enterprise are not necessarily the ones that generate the most text. They are the ones that reduce coordination overhead, surface relevant information, and help teams make better decisions under pressure.

An Operations Command Agent represents a practical example of this philosophy. Connecting telemetry, operational knowledge, and structured reasoning, it helps engineering teams move faster during incidents without removing human oversight.

As organizations continue adopting AI-native workflows, we are likely to see more agents acting as coordinators rather than autonomous operators, bridging systems, teams, and information flows to improve reliability at scale.

The future of enterprise AI may not be a chatbot answering questions. It may be an operational partner helping engineers resolve the next critical incident before customers ever notice there was a problem.

Oladimeji Samuel Sowole
Data Scientist, Andela
No items found.
No items found.
No items found.

Recent articles