Overview
Vigil’s tool-calling work runs in one TypeScript agent loop, split
across two files: services/agent/core/loop.ts (the Harness interface
and commitTurn) and services/agent/core/stream.ts (streamTurn; the
budget lives in budget.ts and the prompt-injection scan in
security.ts, both wired in by the loop). The FastAPI backend enqueues agent runs,
the loop calls LLM providers through the Bifrost gateway, and tools are
dispatched through the backend tool registry and the MCP registry for
connected integrations. Python provides one-shot completions, not a second
loop — see “One loop, and where it is” below.
MCP is part of the current architecture, not a predecessor to it: startup constructs an empty MCP registry and MCP tools connect lazily when an agent actually needs them (eager connection is preserved only outside DEV_MODE unless overridden), with registration following connection; chat reaches their tools through the integration-door tools described under Tool Categories. No desktop application is required; the web UI is the client.
Architecture Diagram
┌─────────────┐
│ Browser │
│ (Web UI) │
└──────┬──────┘
│ HTTPS
↓
┌─────────────────────┐
│ FastAPI Backend │
│ (Python, 6987) │
│ ├── API Endpoints │
│ └── Agent-run │
│ queueing │
└──────┬──────────────┘
│ enqueued runs
↓
┌─────────────────────┐
│ TypeScript Agent │
│ Loop │
│ services/agent/ │
│ core/stream.ts │
└──────┬──────────────┘
│ via Bifrost gateway
↓
┌─────────────────────┐
│ LLM Providers │
│ (default model: │
│ claude-sonnet-4-6)│
└──────┬──────────────┘
│ tool calls dispatched by the loop
↓
┌─────────────────────┐
│ Backend Tools │
│ ├── Security │
│ │ Detections │
│ ├── Findings & │
│ │ Cases │
│ ├── Approvals │
│ ├── ATT&CK │
│ ├── Threat Intel │
│ ├── Memory │
│ └── Skills │
│ + MCP registry │
│ (integrations) │
└──────┬──────────────┘
│
↓
┌─────────────────────┐
│ Data Layer │
│ ├── PostgreSQL │
│ └── Detection │
│ Rules (synced │
│ into Postgres) │
└─────────────────────┘
Stack Components
Frontend
- React/TypeScript
- Vite dev server
- Port: 6988
Backend
- FastAPI (Python 3.12)
- LLM traffic via the Bifrost gateway
- Backend tools
- Port: 6987
Database
- PostgreSQL 16
- Findings, cases, embeddings
- Port: 5432
Detection Rules
- Rules in Sigma, Splunk, Elastic and KQL formats, plus rules from Kibana’s detection engine, Splunk saved searches and the Wazuh manager
- Answers come from the rules as
core/detections/inventorysyncs them into Postgres — not from an in-memory index of the cloned repositories alone
Tool Categories
Tool schemas are defined in core/llm/tool_schemas.py. See the
Backend Tools Guide for detailed documentation.
1. Security Detection Tools
Access to the detection rule database:
analyze_coverage- Coverage by MITRE techniquesearch_detections- Keyword search across ruleslink_detection_rule- Link a detection ruleidentify_gaps- Gap analysisget_coverage_stats- Statisticsdetection_metrics- Detection metricsget_detection_count- Counts by sourcelint_detections- Lint detection rulescheck_detection_candidate- Check a candidate detectionsave_detection_rule- Save a detection ruledetection_rule_exception- Manage per-copy rule exceptionsreconstruct_run- Reconstruct a run
2. Finding & Case Tools
SOC investigation workflow:
list_findings- Query findingssearch_findings- Keyword search across findingsget_findings_stats- Finding statisticsget_finding- Get specific findingdismiss_finding- Dismiss a findinglist_cases- Query casesread_case_shell- Read a case shellcreate_case- Create new caseadd_finding_to_case- Associate findingsupdate_case- Update case status and metadatarestrict_case- Restrict case accesschange_case_readers- Change who can read a caseadd_resolution_step- Document resolution stepslist_completed_hunts- List completed huntslist_learning_episodes- List learning episodesexport_learning_episodes- Export learning episodesreplay_hunt- Replay a hunt
3. MITRE ATT&CK Tools
Technique mapping and visualization:
get_technique_rollup- Technique statistics
4. Approval Tools
Autonomous response workflow:
list_pending_approvals- Pending actionsget_approval_action- Action detailsapprove_action- Approve actionreject_action- Reject actionget_approval_stats- Statistics
5. Threat Intel Tools
lookup_indicators- Look up observables in the threat-indicator databasepropose_feed_hunts- Propose hunts for recently fed, unhunted indicators
6. Memory Tools
recall_entity- Recall what past investigations saw and concluded about an entitycheck_hunt_coverage- Check whether a hunt already covers a report or entity
7. Skill Tools
read_skill- Read a skill from the skill library
Integration Tools
Two further tools sit outside the categories above and form chat’s door to the connected MCP integrations:
find_integration_tools- Search the tools of connected integrations by keywordcall_integration_tool- Run one tool thatfind_integration_toolsreturned
Request Flow
Example: Detection Coverage Query
1. User: "What's our coverage for T1059.001?"
↓
2. Web UI → POST /api/claude/chat/stream
↓
3. Work that needs tools is enqueued as an agent run
↓
4. The TypeScript agent loop drives the run, calling the LLM
via the Bifrost gateway
↓
5. The loop dispatches the tool call: analyze_coverage,
via the agent layer / tool registry
(core/agents/tool_registry.py)
↓
6. Detection answers come from the rules synced into
Postgres by core/detections/inventory
↓
7. Example output (illustrative only):
{ "T1059.001": { count: 234, by_source: {...} } }
↓
8. The loop synthesizes a response
↓
9. Web UI displays the streamed result
Access and Enrichment Flows
Vigil’s own MCP surface, and OAuth on it
The flow above is Vigil calling tools. Vigil also serves its
own MCP server (tools/mcp/vigil.py) to outside callers at /mcp,
served by the backend (services/api/mcp_surface.py). The surface
is stateless — every request is authenticated and bound to its
principal on its own — and it is off by default: closed answers
404, unauthenticated answers 401. Callers authenticate with a
personal API token, or with OAuth: Vigil runs an authorization
server at the host root (discovery at
/.well-known/oauth-authorization-server, plus /register,
/authorize, /token, /revoke — at the root even under
VIGIL_CONTEXT_PATH), with a console consent page, and accepts the
resulting OAuth bearer tokens alongside vgl_api_ tokens. OAuth
has its own switch (vigil_mcp_oauth_enabled,
core/config.py:229; core/auth/oauth_server.py,
core/integrations/mcp/surface.py). See
MCP OAuth.
Ask Vigil dock runs
The Ask Vigil dock (clients/web/src/shell/Chat.tsx) is a run
entry point, not only a chat box: /hunt <hypothesis> enqueues the
threat-hunt workflow and /investigate <finding or context> the
incident-response workflow. The run is placed on a case (opened, or
the open case holding the alert), the dock follows that case, and
the Case page renders the run live — current step, items waiting
on a person, and a Keep-going control for a hunt stopped at a
limit.
Insider leads
The daemon also starts hunts without a person asking. A finding is
an insider lead when its data_source is in the lead list’s
sources or its title matches one of its rule names; the list is one
SystemConfig row (workflows.insider_leads —
core/workflows/insider_lead.py) holding sources, rule names,
readers and teams, edited from the threat-hunt workflow’s panel.
The daemon’s trigger (services/daemon/orchestrator.py) starts a
hunt on the account the finding names, on a restricted case
readable only by the starter and the list’s readers/teams
(core/workflows/start_case.py). No row, an unreadable row, or no
matchers means the trigger is off.
Entity facts
Triage enriches a finding’s user/host entities before reasoning:
one projection per source in core/integrations/entity_facts.py
(Entra and Okta for users, Falcon for hosts) fetches identity and
EDR facts, held 24 hours by default so repeat findings reuse them.
At run start the agent layer reads them via read_entity_facts
(core/agents/tool_registry.py); the same held rows are exposed
read-only at Settings › Entity facts, GET /api/v1/entity-facts
and get_entity_facts on /mcp, all under findings.read. Facts
inform the triage prompt only — no gate, ceiling or verdict
branches on them.
Configuration
LLM provider credentials (Anthropic / OpenAI / Ollama / Vertex / OpenRouter) are configured in
the web UI under Settings → AI models and stored in the
encrypted secret store at ~/.vigil/secrets.enc. The backend pushes them
to Bifrost over its admin API in the same request. See
CONFIGURATION.md and STATE.md for the
full split between bootstrap config and secrets.
Environment Variables (.env)
Bootstrap-only — nothing sensitive belongs here.
# Detection Rules
SIGMA_PATHS="${HOME}/security-detections/sigma/rules"
SPLUNK_PATHS="${HOME}/security-detections/security_content/detections"
ELASTIC_PATHS="${HOME}/security-detections/detection-rules/rules"
KQL_PATHS="${HOME}/security-detections/Hunting-Queries-Detection-Rules"
# LLM gateway (Bifrost) — provider keys are NOT set here.
# Host-run default; "bifrost" as a hostname resolves only
# inside the compose network, which injects its own value.
BIFROST_URL="http://localhost:8080"
The Python backend does not read a DATABASE_URL setting — that is the
TypeScript agent’s knob. Python sessions go through DatabaseConfig, which
uses POSTGRESQL_CONNECTION_STRING read from the encrypted secret store, or
the POSTGRES_* settings.
One loop, and where it is
There is exactly one tool-calling loop in Vigil, and it is TypeScript:
services/agent/core/loop.ts defines the Harness interface and
commitTurn, and services/agent/core/stream.ts exports streamTurn.
Together they own the budget (in budget.ts), the approval gate, the
prompt-injection scan (in security.ts) and the turn cap, so anything that reasons with tools gets
all four by construction rather than by remembering to.
Python holds no loop. ClaudeService.chat() is a one-shot completion for
callers that want a single answer and no tools:
from core.llm.harness.claude import ClaudeService
answer = ClaudeService().chat(message="...", system_prompt="...")
Most one-shot callers now go through core/llm/oneshot.py rather than
constructing ClaudeService directly.
Work that needs tools is enqueued as a run and the worker drives it:
from core.agents.queue import build_start_job, enqueue_run, new_run_id
run_id = new_run_id()
await enqueue_run(build_start_job(run_id, "investigate", request, enqueued_by="api"))
Five loops preceded this — claude_service, agent_runner, workflows_service,
orchestrator and openai_agent_service — with three tool dispatchers and four
transports between them. scripts/check_one_loop.py runs in CI and fails when a
second one appears, because each addition looked reasonable on its own and review
did not catch the fifth.
Deployment
Development
# Terminal 1: Database
cd infra/docker && docker compose up -d postgres
# Terminal 2: Backend
source venv/bin/activate
uvicorn services.api.main:app --host 127.0.0.1 --port 6987 --reload
# Terminal 3: Frontend
cd clients/web && npm run dev
Production (Docker)
cd infra/docker
docker compose up -d
The compose file at infra/docker/docker-compose.yml defines more than the
database and API, including:
- PostgreSQL
- Redis
- Backend API
- Agent, worker and daemon services (the daemon’s compose service is
soc-daemon) - Medic (
medic,medic-dockerproxy,medic-gateway) - MCP runner
- Bifrost gateway
Performance
- Database: PostgreSQL with connection pooling enabled
- Claude API: Rate limited by the provider, via the Bifrost gateway
No verified latency, resource-usage or concurrent-user figures are published for this stack; earlier tables of such figures had no counterpart in the code and have been removed.
Monitoring
Health Endpoints
# Backend health
curl http://localhost:6987/api/health
# Database connectivity
curl http://localhost:6987/api/storage/status
Logs
# Backend logs (stdout when running uvicorn directly, or Docker logs)
docker logs deeptempo-postgres # PostgreSQL logs
docker logs -f <backend-container> # Backend API logs
Security
API Key Management
- Preferred store: the Fernet-encrypted file at
~/.vigil/secrets.enc - Fallbacks, in priority order: environment variables, the repo-root
.env(read-only), and the state-dir.envfile - Keyring access is off by default (it triggers macOS keychain prompts) and is used only when explicitly enabled
- Provider keys configured in the web UI are pushed to Bifrost over its admin API (see Configuration above)
Tool Permissions
- Gated write/dangerous operations exist (e.g. Cloudflare enforcement,
detection-rule writes, case mutation, a
shellgrant); they are not ungated — response actions require approval - Approval required for response actions
- Rate limiting on API endpoints
- Authentication required (configurable)
How Tool Access Works
Backend tools and MCP integrations are both current parts of the architecture; neither replaces the other:
Web UI → FastAPI Backend → agent-run queue → TypeScript agent loop
↓
Backend tools (tool registry) + MCP registry
↓
Services
- Backend tools are defined in
core/llm/tool_schemas.pyand dispatched through the agent layer /core/agents/tool_registry.py. - Connected MCP servers are registered in the MCP registry; chat reaches
their tools through
find_integration_toolsandcall_integration_tool. - LLM traffic goes through the Bifrost gateway, not a direct backend-to-provider tool loop.
Troubleshooting
“No tools loaded”
# Tools are the registry's, not an LLM client's. Startup populates it.
from core.integrations.mcp.registry import MCPRegistry, safe_tool_names
print(safe_tool_names(MCPRegistry()))
An empty list means no MCP server connected this boot: the disk cache is a warm-start artifact and a server that failed to connect is deliberately not registered, so a model cannot claim a capability it has no session for.
“Detection rules not found”
# Check repositories
ls -la ~/security-detections/
# Should show: sigma/, security_content/, detection-rules/, Hunting-Queries-Detection-Rules/
# Clone if missing
./scripts/setup_detection_repos.sh
“Database connection failed”
# Check PostgreSQL
docker ps | grep postgres
# Check connection string
echo $POSTGRESQL_CONNECTION_STRING
Development
Adding New Tools
- Define tool schema in
core/llm/tool_schemas.py:
{
"name": "my_new_tool",
"description": "What the tool does",
"input_schema": {
"type": "object",
"properties": {
"param1": {"type": "string", "description": "..."}
},
"required": ["param1"]
}
}
-
Implement and dispatch the tool in the agent layer — dispatch lives in the TypeScript agent layer (
services/agent/core/) and incore/agents/tool_registry.py. Python’sClaudeServiceis a one-shot completion with no tools and no loop, so there is no tool-routing step to add there. -
For MCP tools, add them in
tools/mcp/vigil.pyso they are served through the MCP registry. -
Test with the test suite below.
Running Tests
# Test suite (tests/ contains live/, medic_compose/ and medic_eval/)
pytest tests/
Documentation
- Backend Tools Guide - Detailed tool documentation
- Detection Engineering - Detection rule usage
- Integrations - Backend tool integration overview
- API Reference - FastAPI documentation
Support
For issues or questions:
- GitHub Issues: https://github.com/Vigil-SOC/vigil/issues
- Label:
backend-tools - Include: Backend logs, tool name, error message