Skip to main content

An AI-driven DevOps Copilot and CLI Client for managing bare-metal servers securely

Project description

DevOps Copilot ๐Ÿš€

An autonomous, self-learning AI DevOps Assistant & CLI Client that manages bare-metal servers with Memory-First Architecture, Experiential Learning (ExpeL), Semantic Guardrails, and Real-Time SSH Tunneling.


๐Ÿ’ก About The Project

Managing infrastructure via traditional CLI tools or basic AI wrappers often leads to dangerous mistakes, repetitive debugging dead-ends, and fragmented server logs. DevOps Copilot redefines server management by combining a Memory-First Agent Architecture with Closed-Loop Experiential Learning (ExpeL) directly in your terminal.

Unlike standard AI chat wrappers that forget previous troubleshooting sessions, DevOps Copilot builds a permanent, structured ChromaDB Vector Knowledge Base of your infrastructure:

  • ๐Ÿง  Memory-First Architecture: A multi-store memory system (SemanticStore, LessonStore, EpisodicStore, UserFactStore, ProceduralStore) that reads context before every agent turn and writes extracted facts after each interaction โ€” ensuring the agent remembers your servers, preferences, and past incidents across sessions.
  • ๐Ÿ” LangGraph StateGraph Agent: Fully stateful agent built on LangGraph with dedicated nodes for memory retrieval (read_memory), reasoning (agent), tool execution (tools), self-correction (evaluator), and memory persistence (write_memory).
  • ๐Ÿง  Zero-Click Experiential Learning (ExpeL & Reflexion): Every time an incident or bug is diagnosed and resolved, the agent distills the entire session into a structured Postmortem (Problem, Real Cause, What didn't work, What worked). Before tackling new errors, relevant past lessons are automatically retrieved and injected into the agent's contextโ€”ensuring it never repeats a dead end.
  • ๐Ÿ” LangSmith Observability: Full tracing of every graph node, tool call, memory read/write, human-in-the-loop interrupt, and self-correction retry โ€” all via environment variables with zero code changes.
  • ๐Ÿ›ก๏ธ Semantic Security Guardrails: Local vector search intercepts and blocks catastrophic shell commands (e.g., rm -rf /, mkfs) before they ever touch your servers.
  • ๐Ÿง‘โ€๐Ÿ’ป Human-in-the-Loop (HITL) Approvals: State-modifying actions dynamically prompt for explicit admin confirmation ([y/N]) inside the terminal using LangGraph's native interrupt mechanism.
  • โšก Real-Time Async Execution Tunnel: Streams LLM reasoning, SSH stdout, and stderr line-by-line via resilient WebSockets with automatic reconnection and exponential backoff.
  • ๐Ÿ”’ Zero-Trust Credential Encryption: Passwords and SSH private keys are encrypted at rest using AES-256 (Fernet).

๐Ÿ›๏ธ System Architecture

+-----------------------------------------------------------------------------------+
|                                 DevOps Copilot CLI                                |
|  (Typer Async Client + Real-Time WebSocket Tunnel + [y/N] Terminal Approval)      |
+-----------------------------------------------------------------------------------+
                                   |           ^
                   REST Auth/CRUD  |           | WebSocket Stream (stdout/stderr)
                                   v           |
+-----------------------------------------------------------------------------------+
|                              FastAPI Backend Server                               |
|                                                                                   |
|  +------------------------+   +-----------------------+   +--------------------+  |
|  |     Auth Module        |   |    Servers Module     |   | Guardrails Module  |  |
|  |  (JWT & AES Fernet)    |   |  (AsyncSSH Execution) |   | (Vector Blacklist) |  |
|  +------------------------+   +-----------------------+   +--------------------+  |
|                                                                                   |
|  +-----------------------------------------------------------------------------+  |
|  |                     LangGraph StateGraph Agent                               |  |
|  |                                                                              |  |
|  |  read_memory โ”€โ”€> agent โ”€โ”€> tools โ”€โ”€> evaluator โ”€โ”€> agent โ”€โ”€> write_memory    |  |
|  |       โ”‚                      โ”‚           โ”‚                        โ”‚           |  |
|  |       โ”‚            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ”‚ (self-correction ร—3)   โ”‚           |  |
|  |       โ–ผ            โ–ผ                                              โ–ผ           |  |
|  |  MemoryManager   SSH / Knowledge                          ExtractionPipeline  |  |
|  |  (read_context)  Guardrails / HITL                       ConsolidationPipeline|  |
|  |                                                          EpisodicSummarizer   |  |
|  +-----------------------------------------------------------------------------+  |
|                                       โ”‚                                           |
|                                       โ–ผ                                           |
|  +-----------------------------------------------------------------------------+  |
|  |                      ChromaDB Multi-Store Knowledge Base                     |  |
|  |                                                                              |  |
|  |  command_history โ”‚ server_logs โ”‚ server_configs โ”‚ lessons_learned            |  |
|  |  episodic_summaries โ”‚ user_facts โ”‚ procedural_tools                          |  |
|  +-----------------------------------------------------------------------------+  |
|                                                                                   |
|  +-----------------------------------+                                            |
|  |   LangSmith Tracing (Optional)    |                                            |
|  |   Full graph & tool observability |                                            |
|  +-----------------------------------+                                            |
+-----------------------------------------------------------------------------------+

The LangGraph Agent Flow

  1. read_memory โ€” Retrieves episodic summaries, lessons learned, user facts, and knowledge from ChromaDB before the agent reasons.
  2. agent โ€” LLM reasoning node (OpenRouter) with all tools bound. Decides next action or generates final response.
  3. tools โ€” Executes tools (execute_ssh_command, search_knowledge, fetch_server_logs, etc.) via ainvoke().
  4. evaluator โ€” Inspects tool results. Routes back to agent for self-correction on failures (up to 3 retries). Skips non-retryable infrastructure errors (SSH timeouts, auth failures).
  5. write_memory โ€” Background extraction of facts, preferences, and episodic summaries via non-streaming LLM.

The Closed-Loop Experiential Learning (ExpeL) Flow

  1. Observe & Act: Agent connects via AsyncSSH, runs non-destructive diagnostics or approved actions, and indexes outputs into command_history and server_logs.
  2. Judge & Extract: When an incident is resolved, the postmortem endpoint triggers an automated LLM extraction (Problem, Real Cause, What didn't work, What worked) stored in lessons_learned.
  3. Zero-Click Injection: On any future chat turn, read_memory queries lessons_learned and injects proven solutions directly into the agent's system prompt context.

Key Features

  • Memory-First Agent Architecture: Multi-store retrieval (SemanticStore, LessonStore, EpisodicStore, UserFactStore) on every turn with automatic fact extraction, consolidation, and episodic summarization after each interaction.
  • LangGraph StateGraph: Fully stateful agent with dedicated nodes for memory I/O, tool execution, and self-correction โ€” replacing the legacy agent loop.
  • Experiential Learning (ExpeL / Reflexion Postmortems): Distills complex debugging sessions into structured Lessons Learned cards indexed into ChromaDB with zero-click context injection.
  • Self-Correction (Evaluator Node): Automatic detection of tool execution failures (e.g. non-zero exit codes) in LangGraph, routing execution back to the agent with error details for self-healing (up to 3 retry attempts). Terminal infrastructure errors (SSH refused, auth failure) bypass retry.
  • Negative Feedback Reflexion: Submitting negative feedback (thumbs-down) on AI responses triggers a background LLM Reflexion pipeline to analyze the failure, extract a lesson, and store it in ChromaDB's LessonStore.
  • LangSmith Observability: Full tracing of LangGraph execution, tool calls, memory nodes, and interrupts โ€” enabled via environment variables with zero code changes.
  • Lean RAG Knowledge Base: Automatically chunks and indexes executed SSH command outputs, logs, and server configs into separate ChromaDB collections (7 stores total).
  • Semantic Guardrails: Uses local vector search to intercept and block dangerous terminal commands.
  • Human-in-the-Loop (HITL): Enforces admin approval ([y/N]) via LangGraph's native interrupt mechanism for state-modifying actions.
  • Auto Schema Migration: Automatically detects and adds new database columns on startup without manual migration scripts.
  • CLI Connection Resilience: Automatically reconnects to the WebSocket server using exponential backoff if the network drops.
  • Real-Time Streaming: Streams LLM thoughts and active SSH stdout/stderr line-by-line using WebSockets with 30s execution timeouts.
  • Encrypted Credentials: Securely encrypts passwords and SSH private keys using Fernet (AES-256).
  • Server & Session CRUD & Feedback: Full REST API support for managing server connections, deleting sessions, and submitting user satisfaction ratings.
  • Flexible AI Models: Powered by OpenRouter (supports Llama 3, Gemini, GPT, etc.).

๐Ÿ“ฆ Quick Start (Backend Server)

1. Configure Settings

Copy the env file and populate keys:

cp .env.example .env

Make sure to add your OPENROUTER_API_KEY and a custom base64 ENCRYPTION_KEY in .env.

2. Enable LangSmith Tracing (Optional)

Get your API key from smith.langchain.com and add to .env:

LANGSMITH_TRACING=true
LANGSMITH_API_KEY=lsv2_pt_...
LANGSMITH_PROJECT=devops-copilot

For EU data residency, set LANGSMITH_ENDPOINT=https://eu.api.smith.langchain.com

3. Run with Docker Compose

docker compose up -d --build

The server will boot on port 8000. Database tables, schema migrations, and security blacklist vectors are automatically seeded on startup.


๐Ÿ’ป Quick Start (CLI Client)

1. Install Globally

Install the package in editable mode from your local repository root:

uv pip install -e .

2. Authenticate

Configure the server URL and log in to get your JWT access token:

devops-copilot login

3. Interactive Chat & Auto-Postmortems

Start the real-time DevOps chat session:

devops-copilot chat

Ask the agent to check stats or run actions. Approve state-modifying commands directly in the prompt.

Extract and index a structured Experiential Lesson Learned from any completed troubleshooting session:

devops-copilot lesson <session_id>

๐Ÿ—๏ธ Project Structure

app/
โ”œโ”€โ”€ core/
โ”‚   โ”œโ”€โ”€ config.py            # Pydantic settings (env vars)
โ”‚   โ”œโ”€โ”€ database/            # Async SQLite engine + auto-migration
โ”‚   โ”œโ”€โ”€ llm.py               # LLM factories (streaming & non-streaming)
โ”‚   โ””โ”€โ”€ security.py          # Fernet AES-256 encryption
โ”œโ”€โ”€ modules/
โ”‚   โ”œโ”€โ”€ auth/                # JWT authentication
โ”‚   โ”œโ”€โ”€ servers/             # Server CRUD + SSH credentials
โ”‚   โ”œโ”€โ”€ guardrails/          # Semantic command blacklist
โ”‚   โ”œโ”€โ”€ knowledge/           # ChromaDB indexing service
โ”‚   โ”œโ”€โ”€ chat/
โ”‚   โ”‚   โ”œโ”€โ”€ agent.py         # LangGraph StateGraph definition
โ”‚   โ”‚   โ”œโ”€โ”€ router.py        # WebSocket handler + REST endpoints
โ”‚   โ”‚   โ”œโ”€โ”€ models.py        # ChatSession, ChatMessage, AgentAction
โ”‚   โ”‚   โ””โ”€โ”€ schema.py        # Pydantic request/response schemas
โ”‚   โ””โ”€โ”€ memory/
โ”‚       โ”œโ”€โ”€ manager.py        # MemoryManager (read_context / write_after_turn)
โ”‚       โ”œโ”€โ”€ stores.py         # 7 ChromaDB collection wrappers
โ”‚       โ”œโ”€โ”€ extraction.py     # LLM fact extraction pipeline
โ”‚       โ”œโ”€โ”€ consolidation.py  # Deduplication before persistence
โ”‚       โ”œโ”€โ”€ summarizer.py     # Episodic session summarizer
โ”‚       โ”œโ”€โ”€ reflexion.py      # Negative feedback analysis pipeline
โ”‚       โ””โ”€โ”€ types.py          # AgentState, ExtractedFact, MemoryContext
โ””โ”€โ”€ cli/                      # Typer CLI client

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

devops_copilot-0.1.4.tar.gz (44.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

devops_copilot-0.1.4-py3-none-any.whl (51.0 kB view details)

Uploaded Python 3

File details

Details for the file devops_copilot-0.1.4.tar.gz.

File metadata

  • Download URL: devops_copilot-0.1.4.tar.gz
  • Upload date:
  • Size: 44.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for devops_copilot-0.1.4.tar.gz
Algorithm Hash digest
SHA256 8b1130ce11702c613500de8c48e2170b012fa23880213c8d04eaef65ab92e596
MD5 7967434869f2cb5cdb8aad2cb48499b1
BLAKE2b-256 5b4be72dc99af71f1eaad121a5d1ffb9ae53a62bf29e67960a2c87d404ab1b1f

See more details on using hashes here.

File details

Details for the file devops_copilot-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: devops_copilot-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 51.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for devops_copilot-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 54858837073936473ea8f30a55a5039ea2883d247e13dae082211e544a9e7e42
MD5 800404c8d355716b0e688d190da4782f
BLAKE2b-256 32a1d2ef0c5966cdda9a827076b13c571f456377fda8dbd5ad12f284e62ad567

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page