ββββ ββββββββββββββββββ βββ βββββββββββ βββββ ββββββββββββββββββββββ βββββββββββ ββββββ βββββββββ βββββββββββ βββββββββ ββββββββββββββββ ββββββββββββ ββββββββββ βββ βββββββββββββββββ βββ βββββββ ββββββββ βββ ββββββββββββββββ βββ βββββ ββββββββ
From production crash to merged PR while you sleep.
View Demo Β· Report Bug Β· Request Feature Β· Architecture Deep Dive
It's 2:47 AM. Your production application just crashed. Here's what happens next:
| Step | Who Does It | Time Cost |
|---|---|---|
| Alert fires, engineer gets paged | PagerDuty | ~5 min |
| Engineer wakes up, logs into Datadog/Sentry | Human | ~15 min |
| Reads the stack trace, understands context | Human | ~20 min |
| Clones repo, searches through hundreds of files | Human | ~30 min |
| Writes a fix, runs tests, submits PR | Human | ~60 min |
| PR reviewed and merged | Human | ~30 min |
| Total MTTR | Everything above | β‘ 2-3 hours |
This costs companies millions in downtime not because engineers are slow, but because the entire process is manually sequential.
Observability tools (Datadog, Sentry) detect the fire. AI assistants (Copilot, ChatGPT) write code if you spoon-feed them the exact context. Neither can autonomously bridge the gap.
The missing link is Autonomous Execution.
Nerve is an active, multi-agent AI pipeline that mimics a senior Site Reliability Engineer.
You wake up to this Slack message:
π€ nerve-bot 2:49 AM
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π΄ Bug Detected in production/billing.py β
β β
β Root cause: ZeroDivisionError on line 142 β
β Confidence: 94% β
β β
β β
Fix written & tested (3 iterations) β
β π Pull Request #847 is ready for your review β
β β
β [ View PR ] [ View Agent Trace ] [ Dismiss ] β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Instead of 3 hours you approve a PR in 3 minutes.
[ Production Crash ]
β
β 1. Webhook (Error Stack Trace + Context)
βΌ
βββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββ
β FastAPI Gateway βββββββββββΊβ Next.js Dashboard (UI) β
β (Webhook Ingest) β β Real-time agent thought stream β
βββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββ
β β²
β 2. Push Job + 202 Accepted β
βΌ β 7. SSE Stream
βββββββββββββββββββββββ β
β Redis Task Queue β β
βββββββββββββββββββββββ β
β β
β 3. Worker pulls job β
βΌ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Python Worker (ARQ) β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β LangGraph Agent Loop β β
β β β β
β β [INVESTIGATE] β [HYPOTHESIZE] β [WRITE FIX] β β
β β β² β β β β
β β β βΌ βΌ β β
β β βββββββββ [RUN TESTS] βββ [SANDBOX] β β
β β β β β
β β βΌ (pass) β β
β β [CREATE PR] β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β β 4. Semantic search + save state
βΌ βΌ
ββββββββββββββββββββββββββββββββββ ββββββββββββββββββββ
β PostgreSQL (Neon) β β Groq / Gemini β
β ββββββββββββ ββββββββββββββ β β (LLM Reasoning) β
β β Events β β pgvector β β ββββββββββββββββββββ
β β PRs β β Codebase β β
β β Logs β β Embeddings β β
β ββββββββββββ ββββββββββββββ β
ββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββ
Webhook βββΊ β INGEST ERROR β
ββββββββββ¬ββββββββββ
β
ββββββββββΌββββββββββ
β VECTOR SEARCH β βββ pgvector similarity search
β (Find broken fn) β over entire codebase
ββββββββββ¬ββββββββββ
β
ββββββββββΌββββββββββ
β LLM REASONING β βββ Groq Llama 3.3 70B
β (Form hypothesis)β or Gemini Flash
ββββββββββ¬ββββββββββ
β
ββββββββββΌββββββββββ
β WRITE PATCH β βββ Code generation
ββββββββββ¬ββββββββββ
β
ββββββββββΌββββββββββ
β SANDBOX TESTS β βββ Docker container
β (Run test suite) β (isolated, no network)
ββββββββββ¬ββββββββββ
β
ββββββββββββββββΌβββββββββββββββ
β FAIL β β PASS
β β β
ββββββββββΌβββββ β βββββββββββΌβββββββββββ
β REFLECT & β β β VALIDATE SUITE β βββ Full test suite
β RETRY (n) β β β (All modules pass) β (not just local)
ββββββββββ¬βββββ β βββββββββββ¬βββββββββββ
β β β
ββββββββββββββββ βββββββββββΌβββββββββββ
β CREATE PR β βββ GitHub App API
β + Notify Slack β
ββββββββββββββββββββββ
| Technology | Role | Why This Choice |
|---|---|---|
| Python 3.12 | Primary language | Native home of the ML/AI ecosystem |
| FastAPI | API Gateway & Webhook Ingest | Async I/O (asyncio) doesn't block while LLMs think |
| LangGraph | AI Agent Orchestration | Cyclic state machines for reflect-and-retry loops. Standard LangChain is linear; bugs aren't. |
| ARQ | Background Task Worker | Async-native (built on asyncio), lightweight, perfect for our FastAPI stack |
| GitHub App (PyGithub) | PR Creation & Repo Access | Fine-grained permissions per repo without OAuth token sprawl |
| Technology | Role | Why This Choice |
|---|---|---|
| PostgreSQL (Neon) | Primary Database | ACID compliance for audit trails. Every action the AI takes is logged. |
| pgvector | Vector Similarity Search | Extends PostgreSQL with <=> cosine distance operator. No extra infra vectors live alongside relational data. |
| Redis | Task Queue | Decouples HTTP requests from 45-second AI jobs. FastAPI returns 202 Accepted instantly. |
| Technology | Role | Why This Choice |
|---|---|---|
| Groq API (Llama 3.3 70B) | Primary LLM | LPU hardware delivers ~750 tokens/sec critical for fast agent loops |
| Google Gemini Flash | Fallback / Large context | 1M token context window for huge codebases |
OpenAI text-embedding-3-small |
Embedding Generation | State-of-the-art code embeddings for vector search accuracy |
| LangSmith | Agent Observability | Trace every reasoning step, token usage, and retry loop for debugging |
| Technology | Role | Why This Choice |
|---|---|---|
| Docker (sandboxed containers) | Test Execution | AI-generated code runs in isolated containers with no network access and memory caps never on the host |
| Technology | Role | Why This Choice |
|---|---|---|
| Next.js 15 | Dashboard | App Router, React Server Components, built-in API routes |
| Tailwind CSS | Styling | Rapid UI development, consistent design tokens |
| Server-Sent Events (SSE) | Real-time Agent Stream | Unidirectional stream of agent "thoughts" to the UI simpler than WebSockets for this use case |
Let's trace a real bug: ZeroDivisionError in billing.py
Step 1 INGESTION
βββ Sentry detects crash, sends JSON webhook to /api/v1/ingest
βββ FastAPI validates payload with Pydantic
βββ Saves Event record to PostgreSQL [status: PENDING]
βββ Drops job into Redis queue
βββ Returns HTTP 202 Accepted to Sentry β instant, no blocking
Step 2 WORKER WAKEUP
βββ ARQ worker sees new job in Redis
βββ Instantiates the LangGraph agent with the error context
Step 3 VECTOR SEARCH
βββ Error message β embedding vector (1536 dimensions)
βββ pgvector query: SELECT chunk, file_path
β ORDER BY embedding <=> $1 LIMIT 10
βββ Returns: ["billing.py:L135-160", "payment_utils.py:L42-80"]
Step 4 AGENT REASONING LOOP
Iteration 1:
βββ LLM reads the top 3 code chunks
βββ Identifies: `total / discount` with no zero-check on line 142
βββ Writes patch: adds `if discount == 0: raise ValueError(...)`
βββ Generates unit test
βββ Runs test in Docker container
βββ Result: β FAIL test asserts wrong exception type
Iteration 2:
βββ LLM reads failure output
βββ Revises patch and test
βββ Runs test in Docker container
βββ Result: β
PASS
Full Suite Validation:
βββ Runs ALL project tests in sandbox β β
47/47 pass
Step 5 COMPLETION
βββ Updates PostgreSQL record [status: COMPLETED]
βββ Calls GitHub App API β Opens Pull Request #847
βββ Posts Slack notification with PR link
βββ SSE stream pushes final state to Next.js dashboard
We build strictly left to right no AI until the infrastructure is solid.
Phase 1 Phase 2 Phase 3 Phase 4 Phase 5
βββββββββ βββββββββ βββββββββ βββββββββ βββββββββ
The Desk & The Rail The Memory The Chef The Waiter
The Pantry
FastAPI βββΊ Redis βββΊ pgvector βββΊ LangGraph βββΊ Next.js
PostgreSQL ARQ Worker Indexer Agent Dashboard
Webhooks Task Queue Embeddings Groq/Gemini SSE Stream
Chunker GitHub PR Real-time UI
- FastAPI project scaffold with Pydantic settings
- PostgreSQL schema:
events,pull_requests,agent_logs -
POST /api/v1/ingestreceives webhook, validates, saves to DB -
GET /api/v1/eventslists all ingested errors - Alembic migrations
- Docker Compose for local dev (FastAPI + Postgres)
- Redis service added to Docker Compose
- ARQ worker setup with job definitions
- FastAPI enqueues job and returns
202 Acceptedimmediately - Worker picks up job, updates event status to
PROCESSING - End-to-end test: Webhook β Queue β Worker β DB status update
-
indexer/service: clones repo, chunks by function/class boundaries - Embedding pipeline: OpenAI
text-embedding-3-small - pgvector schema:
code_chunkstable withVECTOR(1536)column - Vector search endpoint:
POST /api/v1/search - GitHub push webhook β triggers re-indexing on new commits
- LangGraph state machine with nodes:
investigate,hypothesize,patch,test,validate,submit - Docker sandbox service for isolated test execution
- Retry loop: max 5 iterations before escalating to human
- GitHub App integration for PR creation
- LangSmith tracing on all agent runs
- Full agent integration test with a dummy buggy repo
- Next.js app with App Router
- SSE endpoint in FastAPI:
GET /api/v1/events/{id}/stream - Incident list page with status badges
- Live agent trace viewer (watch the agent think, step by step)
- PR approval / dismiss controls
- Slack webhook notification on completion
- Python 3.12+
- Node.js 20+
- Docker & Docker Compose
- A Groq API Key (free tier available)
- A Neon or Supabase PostgreSQL instance
- A GitHub App with
Contents: Read & WriteandPull Requests: Writepermissions
1. Clone the repository
git clone https://github.com/abdullahxdev/nerve.git
cd nerve2. Set up environment variables
cp .env.example .envEdit .env with your credentials:
# Database
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/nerve
# Redis
REDIS_URL=redis://localhost:6379
# LLM
GROQ_API_KEY=gsk_...
GEMINI_API_KEY=...
OPENAI_API_KEY=sk-... # for embeddings
# GitHub App
GITHUB_APP_ID=...
GITHUB_APP_PRIVATE_KEY_PATH=./github-app.pem
GITHUB_WEBHOOK_SECRET=...
# Observability
LANGCHAIN_API_KEY=... # LangSmith
LANGCHAIN_TRACING_V2=true3. Start infrastructure services
docker compose up -d postgres redis4. Install Python dependencies
cd backend
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt5. Run database migrations
alembic upgrade head6. Start the FastAPI backend
uvicorn app.main:app --reload --port 80007. Start the ARQ worker
arq app.worker.WorkerSettings8. Start the Next.js frontend
cd frontend
npm install
npm run devVisit http://localhost:3000 for the dashboard and http://localhost:8000/docs for the API.
nerve/
βββ backend/
β βββ app/
β β βββ api/
β β β βββ v1/
β β β βββ ingest.py # Webhook ingestion routes
β β β βββ events.py # Event listing & detail routes
β β β βββ stream.py # SSE streaming endpoint
β β βββ agent/
β β β βββ graph.py # LangGraph state machine definition
β β β βββ nodes/
β β β β βββ investigate.py # Vector search node
β β β β βββ patch.py # Code generation node
β β β β βββ test.py # Sandbox test execution node
β β β β βββ submit.py # GitHub PR creation node
β β β βββ state.py # AgentState TypedDict
β β βββ db/
β β β βββ models.py # SQLAlchemy models
β β β βββ session.py # Async DB session
β β βββ indexer/
β β β βββ chunker.py # Code chunking by function boundary
β β β βββ embedder.py # Embedding generation + pgvector upsert
β β βββ worker.py # ARQ worker settings & job definitions
β β βββ main.py # FastAPI application entry point
β βββ alembic/ # Database migrations
β βββ tests/
β βββ requirements.txt
βββ frontend/
β βββ app/
β β βββ page.tsx # Incident dashboard
β β βββ incidents/[id]/page.tsx # Live agent trace viewer
β β βββ layout.tsx
β βββ components/
β βββ package.json
βββ docker-compose.yml
βββ .env.example
βββ README.md
POST /api/v1/ingest
Content-Type: application/json
X-Nerve-Signature: sha256=...
{
"source": "sentry",
"error_type": "ZeroDivisionError",
"message": "division by zero",
"stack_trace": "File billing.py, line 142...",
"repository": "org/repo",
"environment": "production",
"metadata": {}
}Response:
{
"event_id": "evt_01J2X...",
"status": "queued",
"stream_url": "/api/v1/events/evt_01J2X.../stream"
}GET /api/v1/events/{event_id}/stream
Accept: text/event-streamEvents emitted:
event: agent_step
data: {"node": "investigate", "message": "Searching codebase for ZeroDivisionError context...", "timestamp": "..."}
event: agent_step
data: {"node": "patch", "message": "Writing fix for billing.py:142...", "timestamp": "..."}
event: complete
data: {"pr_url": "https://github.com/org/repo/pull/847", "iterations": 2}
Important: Running AI-generated code requires serious isolation. We never execute AI output on the host system.
- Sandboxed Execution: All AI-generated code and tests run inside Docker containers with:
- No network access (
--network none) - Memory capped at 512MB (
--memory 512m) - CPU limited (
--cpus 0.5) - Read-only filesystem (except
/tmp) - Auto-removed after execution (
--rm)
- No network access (
- Webhook Verification: All incoming webhooks are verified via HMAC-SHA256 signature
- GitHub App (not OAuth): Fine-grained repo permissions, no user token required
- Audit Trail: Every agent action, LLM call, and code execution is logged to PostgreSQL with timestamps
Contributions are what make open source great. Any contribution you make is greatly appreciated.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please follow Conventional Commits for commit messages.
Distributed under the MIT License. See LICENSE for more information.
Built with obsession by Muhammad Abdullah
"The best on-call engineer is the one that's already awake."
β Star this repo if you find it interesting