-
Notifications
You must be signed in to change notification settings - Fork 5
Architecture
Herve Hildenbrand edited this page Apr 8, 2026
·
2 revisions
BGP Explorer is built as an AI-powered CLI that orchestrates multiple BGP data sources through Claude AI.
User → CLI (cli.py) → Agent (agent.py) → AI Backend (claude)
↓
Tools (ai/tools.py)
↓
┌─────────────┬───────────┴───────────┬─────────────┐
↓ ↓ ↓ ↓
bgp-radar RIPE Stat Globalping PeeringDB
[real-time] [state/history] [probing] [contacts]
↓
Monocle
[relationships]
The Click-based command-line interface handles:
- Argument parsing and validation
- Environment variable loading
- Session initialization
- Interactive chat loop
- Command processing (
/monitor,/thinking, etc.)
The orchestration layer that:
- Manages conversation state
- Routes messages to the AI backend
- Executes tool calls from AI responses
- Formats output for display
- Handles streaming responses
The Claude integration that:
- Registers available tools
- Sends messages with extended thinking enabled
- Parses tool calls from responses
- Manages thinking budget and token limits
The MCP server (mcp_server.py) exposes 8 composite tools, the standalone BGPTools class provides individual tools:
- Each tool is a method with docstrings that Claude reads
- Tools call the appropriate data source client
- Results are formatted for Claude to interpret
Individual clients for each data source:
| File | Client | Purpose |
|---|---|---|
ripe_stat.py |
RipeStatClient |
RIPE Stat REST API |
bgp_radar.py |
BgpRadarClient |
bgp-radar subprocess |
globalping.py |
GlobalpingClient |
Globalping REST API |
peeringdb.py |
PeeringDBClient |
PeeringDB data (CAIDA dump) |
monocle.py |
MonocleClient |
Monocle CLI wrapper |
- User enters a question
- CLI passes message to Agent
- Agent sends to Claude with available tools
- Claude decides which tools to call
- Agent executes tool calls
- Results returned to Claude
- Claude synthesizes response
- Agent displays response to user
Agent receives tool_use from Claude
↓
Agent looks up tool in BGPTools
↓
Tool calls data source client
↓
Client makes API/subprocess call
↓
Response parsed and formatted
↓
Result returned to Claude
Represents a single BGP route observation:
@dataclass
class BGPRoute:
prefix: str # e.g., "8.8.8.0/24"
origin_asn: int # e.g., 15169
as_path: list[int] # e.g., [6939, 15169]
next_hop: str | None
collector: str # e.g., "rrc00"
peer_ip: str | None
peer_asn: int | None
timestamp: datetime
source: str # "ris_live", "ripe_stat", "bgpstream"
rpki_status: str | NoneRepresents a BGP anomaly event:
@dataclass
class BGPEvent:
type: EventType # hijack, leak, blackhole
severity: Severity # low, medium, high
affected_prefix: str
affected_asn: int | None
detected_at: datetime
details: dictsrc/bgp_explorer/
├── cli.py # Click CLI entrypoint
├── agent.py # AI agent orchestration
├── config.py # Pydantic settings
├── output.py # Output formatting
├── models/ # Data models
│ ├── route.py # BGPRoute dataclass
│ └── event.py # BGPEvent dataclass
├── cache/ # TTL cache implementation
│ └── cache.py # Async-safe caching
├── sources/ # Data source clients
│ ├── base.py # Abstract base class
│ ├── ripe_stat.py # RIPE Stat REST API
│ ├── bgp_radar.py # bgp-radar subprocess
│ ├── globalping.py # Globalping REST API
│ ├── peeringdb.py # PeeringDB data
│ └── monocle.py # Monocle CLI wrapper
├── analysis/ # Analysis utilities
│ ├── path_analysis.py # AS path analysis
│ └── as_analysis.py # ASN relationship analysis
└── ai/ # AI backends
├── base.py # Abstract base class
├── claude.py # Claude implementation
└── tools.py # Tool definitions
The cache/ module provides an async-safe TTL cache:
- Default TTL: 5 minutes
- Caches RIPE Stat API responses
- Reduces API calls for repeated queries
- Thread-safe for concurrent access
Claude's extended thinking feature is used for deeper analysis:
- Thinking budget configurable (1024-16000 tokens)
- Summaries shown to user before responses
- Allows Claude to reason through complex investigations
- Historical thinking blocks excluded from context to save tokens
The system degrades gracefully:
- If a tool fails, investigation continues with available data
- Missing optional dependencies are handled at runtime
- API errors are caught and reported clearly
- Timeouts prevent hanging on unresponsive services
- Data Sources - Details on each data source
- Tools Reference - Complete tool documentation
- Contributing - Development setup