We are building a site reliability agent that ingests full server logs and configuration files in a single request to identify root causes. By using a Mixture-of-Experts (MoE) model with a one-million-token context window, we eliminate fragmented chunking and retrieve precise answers across long documents. This is for engineers who debug production incidents and need certainty, not synthesized guesses.
What you'll need
- Python 3.10 or newer
- The OpenAI SDK:
pip install openai - An Oxlo.ai API key from https://portal.oxlo.ai
- A sample log file, or use the synthetic data we provide below
Step 1: Configure the Oxlo.ai client
MoE models do not activate every parameter for each token. Instead, a router network dispatches tokens to specialized expert sub-networks, which keeps inference costs manageable despite massive parameter counts. Oxlo.ai hosts several open-source MoE models, including DeepSeek V4 Flash, which offers a one-million-token context window and efficient sparse activation. Because Oxlo.ai charges a flat rate per request rather than per token, you can pack hundreds of thousands of tokens into one call without scaling costs. See https://oxlo.ai/pricing for current plan details.
from openai import OpenAI
import os
client = OpenAI(
base_url="https://api.oxlo.ai/v1",
api_key=os.environ.get("OXLO_API_KEY", "YOUR_OXLO_API_KEY")
)
Step 2: Prepare the long-context payload
In production you might stream logs from S3 or Datadog. For this tutorial we concatenate synthetic application logs and an Nginx configuration into one text block. The function below returns a single string that we will pass directly into the model context.
APPLICATION_LOGS = """2024-05-20T14:32:10Z ERROR connection pool exhausted
2024-05-20T14:32:11Z WARN retry 1/3 failed for upstream app:8080
2024-05-20T14:32:12Z ERROR upstream prematurely closed connection
2024-05-20T14:32:13Z WARN retry 2/3 failed for upstream app:8080
2024-05-20T14:32:14Z ERROR upstream prematurely closed connection
2024-05-20T14:32:15Z WARN retry 3/3 failed for upstream app:8080
2024-05-20T14:32:16Z ERROR no live upstreams while connecting to upstream
2024-05-20T14:32:17Z CRIT worker process 21491 exited on signal 9
2024-05-20T14:32:18Z ERROR *1024 connect() failed (111: Connection refused)
"""
NGINX_CONFIG = """worker_processes auto;
events {
worker_connections 1024;
}
http {
upstream app {
server 10.0.0.5:8080;
keepalive_timeout 65;
}
server {
listen 80;
location / {
proxy_pass http://app;
}
}
}
"""
def build_context(logs: str, config: str) -> str:
return f"[APPLICATION LOGS]\n{logs}\n\n[NGINX CONFIGURATION]\n{config}"
Step 3: Define the agent's system prompt
The system prompt tells the model to behave as a senior SRE, cite evidence, and stay concise. We do not need few-shot examples because the MoE architecture already specializes sub-networks for reasoning and structured extraction.
SYSTEM_PROMPT = """You are a senior site reliability engineer analyzing production incidents.
You have been given the full application logs and server configuration for a single service.
Follow these rules exactly:
1. Identify the root cause of any errors.
2. Cite specific log lines or config directives using timestamps or line references.
3. Recommend exactly one concrete fix.
4. Respond in this format:
- Root Cause:
- Evidence:
- Fix: """
Step 4: Write the diagnostic function
This function assembles the user message and calls DeepSeek V4 Flash through the Oxlo.ai endpoint. Notice that the entire log payload and the question travel in one request, which is where Oxlo.ai's flat per-request pricing becomes a cost advantage over token-based providers for long-context workloads.
def diagnose(logs: str, config: str, question: str) -> str:
context = build_context(logs, config)
user_message = f"{context}\n\nQuestion: {question}"
response = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_message},
],
)
return response.choices[0].message.content
Step 5: Execute and format the output
Running the script sends the full context to the MoE model. The router inside DeepSeek V4 Flash directs reasoning tokens to its specialized experts, producing a focused diagnostic without activating the full parameter footprint on every single layer.
if __name__ == "__main__":
question = (
"Why are users seeing 502 errors between 14:32 and 14:35 UTC?"
)
result = diagnose(APPLICATION_LOGS, NGINX_CONFIG, question)
print(result)
Run it
Save the script as diagnose.py, set your key, and run it.
export OXLO_API_KEY="oxlo_your_key_here"
python diagnose.py
Example output:
- Root Cause: The Nginx worker_connections limit of 1024 is exhausted because the upstream application connection pool is leaking sockets during retries, causing the worker to crash and return 502s.
- Evidence: Log timestamp 2024-05-20T14:32:10Z "ERROR connection pool exhausted"; config directive "worker_connections 1024" and absence of max_fails or keepalive pooling in the upstream block.
- Fix: Increase worker_connections to 4096, add max_fails=3 fail_timeout=30s to the upstream server directive, and verify the application releases connections after retries.
Next steps
Replace the static strings with a file watcher that pipes /var/log entries directly into the context builder. If you need deeper chain-of-thought reasoning across multiple services, swap the model to deepseek-r1-671b or glm-5 on Oxlo.ai, both of which use MoE architectures optimized for long-horizon agentic tasks.
Top comments (0)