Skip to Content
कवच

Architecture

Components, the round loop, events and configuration.

1. System overview

Plain-text version (for the README image if Mermaid doesn't render):

[Dashboard] ⇄ SSE ⇄ [Kavach API: Orchestrator + Scoring + Event bus]
                         │            │                 │
                   Lyzr agents   DiwaliMart target   Band room
                   (7 brains)    (local or Agent37)   (7 agent identities + you)

2. Components

ComponentPathResponsibility
Target servicebackend/kavach/target/DiwaliMart agent, 4 mock tools, guard engine, tool log. Stateless per request (DB reset each call). Deployable alone (Agent37 script included, not deployed).
Modelsbackend/kavach/models.pyAll pydantic models: TargetConfig, GuardPolicy, ToolCallRecord, Attack, AttackResult, Finding, agent I/O models, Event.
Brainsbackend/kavach/brains/Brain protocol + LyzrBrain, DirectBrain, FakeBrain. JSON extraction + validation + 1 repair retry.
Agentsbackend/kavach/agents/Thin functions per agent, grouped by squad (red.py, blue.py, referee.py): build the payload, call the brain, validate, apply fallbacks.
Scoringbackend/kavach/scoring/detectors.py, benign.py, metrics.py. Pure functions, heavily unit-tested.
Orchestratorbackend/kavach/orchestrator/run.py (round loop), audit.py (patch acceptance), events.py (event bus), replay.py.
Bandbackend/kavach/band/client.py (REST: create room, add participants, send message, post event, get me), room.py (one room per run; each agent posts as itself with mentions; every post is mirrored as an agent.message event; never blocks the run).
APIbackend/kavach/api/app.pyREST + SSE for the dashboard; serves the report.
Reportbackend/kavach/report/markdown.pyBuilds report.md from the run state + Referee narrative.
Dashboardapps/dashboard/Single page, dark mode: round rail, KPI strip, room, arena (tool calls), trend chart, patch diff.
Siteapps/web/Landing page and docs (Next.js + Fumadocs). Docs pages are generated from docs/*.md.
Scriptsscripts/probe_v1.py (is v1 breakable?), band_setup.py (resolve handles, test post), deploy_target_agent37.sh, build_brand.py.

3. Round sequence

After the last round: Referee.final_report → report.md → run.completed → final Band message mentioning the room owner.

4. Data & state

  • A run is an in-memory RunState (configs by version, per-round results, metrics, findings, events).
  • Every event is appended to runs/{run_id}.jsonl (envelope in docs/API_CONTRACTS.md). Replay = read the JSONL and re-emit with the original relative timing.
  • One run at a time is enough for the hackathon (a global lock; return 409 if a run is active).
  • runs/demo_run.jsonl (a known-good recording) is committed for replay mode. Other run files are gitignored.

5. Tech stack

LayerChoiceWhy
BackendPython 3.11+, uv, FastAPI, sse-starlette, httpx, pydantic v2, pydantic-settingsBand's Python SDK requires 3.11+ and uv; async-friendly.
LLM callslitellm (target + direct brain); httpx for LyzrAny tool-calling model; one interface.
BandREST (httpx) using the documented Agent API. Optional band-sdk for stretch C1.Simple, no extra processes.
Testspytest, pytest-asyncio, respx (HTTP mocking)Offline CI with FakeBrain.
Lintruff (lint + format)Fast.
FrontendVite + React 19 + TypeScript (strict) + Tailwind + Recharts + diff (jsdiff)Quick to build, looks good dark.
Deploy targetOptional: an Agent37 instance (agent37-base), uvicorn on port 8000 inside the sandbox. The script is included, but the target has not been deployed there; recorded runs used a local target.Sponsor use + isolation story.

6. Configuration (env)

See .env.example for the full list. Key flags:

VarDefaultMeaning
BRAIN_PROVIDERlyzrlyzr / direct / fake
BAND_ENABLEDtruePost to Band or not (the dashboard works either way)
TARGET_URLhttp://localhost:8001Or https://<instanceId>-8000.agent37.app
TARGET_EXTRA_HEADERS{}JSON; for Agent37 use {"X-Agent37-Key": "..."}
ROUNDS3Rounds per run
ATTACKS_PER_AGENT3Attacks per Red attacker per round (6 per round)
MAX_PATCH_ATTEMPTS3Auditor loop cap
UTILITY_THRESHOLD0.9Patch acceptance
MAX_CONCURRENCY6Orchestrator calls to the target in flight at once
TARGET_CONCURRENCY2Model calls in flight inside the target (raise it on a paid model tier)
ATTACK_LIBRARYstandardstandard (4 + 4 attacks per round) or hard (5 + 5, escalating levels)

7. Failure handling

FailureBehaviour
Brain timeout/invalid JSON twiceRed → attack library fallback; Monitor/Auditor/Referee → templated message from the code data; Patcher → the attempt counts as a veto with reason patcher_failed.
Target call failsRetry once; then count the attack as error (excluded from the breach-rate denominator, shown in the UI).
Band call failsLog a warning and emit band.error. Never stop the run.
Lyzr down mid-demoRestart with BRAIN_PROVIDER=direct, or use replay mode.

8. Security notes

  • Secrets only in .env and agent_config.yaml (both gitignored). The Agent37 key stays server-side.
  • The target's tools are pure functions over an in-memory dict. No network, filesystem writes or subprocesses.
  • All attack messages are aimed only at the local/sandboxed DiwaliMart target.
  • CORS: allow only the dashboard origin.

On this page