A lightweight, "Human-in-the-Loop" AI agent that translates natural language into network configuration and show commands. Built with LangGraph, Nornir, and Chainlit.
The easiest way to run the agent is using Docker. This ensures a consistent environment.
git clone https://github.com/yourusername/network-agent.git
cd network-agentCreate your secrets and inventory files.
.env (Secrets):
GROQ_API_KEY=gsk_your_api_key_herehosts.yaml (Inventory):
---
sw1:
hostname: 192.168.1.10
groups: [cisco]
sw2:
hostname: 192.168.1.11
groups: [cisco]groups.yaml (Platform Definitions):
---
cisco:
platform: cisco_ios
username: admin
password: admin
arista:
platform: arista_eos
username: admin
password: admindocker compose up --buildAccess the Web UI at http://localhost:8000
The project follows a flattened, KISS architecture leveraging Nornir for parallel execution:
| Component | File | Purpose |
|---|---|---|
| Brain | agent/ |
LangGraph workflow, prompts, and decision routing. |
| Hands | tools/ |
Split into show.py (Read) and config.py (Write). |
| Engine | utils/devices.py |
Nornir initialization and task execution engine. |
| UI | app.py |
Chainlit Web Interface. |
| CLI | main.py |
Terminal entry point. |
- Parallel Execution:
- Uses Nornir to execute read-only commands (
show version) on hundreds of devices simultaneously.
- Uses Nornir to execute read-only commands (
- Safety First:
- Sequential Configs: Configuration changes are handled sequentially with a Human-in-the-Loop approval step for every batch.
- The Agent cannot execute changes without your explicit "Yes".
- Smart Input Sanitization:
- Automatically cleans up LLM outputs (e.g., stripping markdown code blocks from config sets) before sending to devices.
- Structured Output:
- Uses TextFSM (via
ntc-templates) to parse raw CLI output into structured JSON data for the LLM.
- Uses TextFSM (via
If you prefer running without Docker:
-
Install Dependencies:
# Using uv (Recommended) uv sync # Or standard pip pip install -r requirements.txt
-
Run Web UI:
chainlit run app.py -w
-
Run CLI:
python main.py "Show ip int brief on sw1"
agent.nodes: Defines the graph state and interaction logic.utils.devices: Lazy-loads Nornir and injects secrets from environment variables.tools.show: Wrapsnornir_netmiko.netmiko_send_command.tools.config: Wrapsnornir_netmiko.netmiko_send_config.
- Fork the repo
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request