About

How Atman-RDTII works.

A from-scratch, multi-agent, zero-hallucination legal-AI audit system. Every claim below is checked by property-based tests.

Three nested loops

  1. Macro · Pub/Sub bus. Four agents subscribe to AgentEvent kinds. Agent A discovers + parses gazettes, Agent B maps to RDTII via ReAct + Few-Shot, Agent C runs a red-team reverse-grounding pass, Agent D synthesizes the report and arbitrates expert instructions.
  2. Mid · Co-Pilot REPL. Mirrors the Claude-Code call chain: PromptInput → handlePromptSubmit → executeUserInput → onQuery → query() → queryLoop(). queryGuard ensures no two engines ever run concurrently (P-3).
  3. Micro · 33-step queryLoop. Streaming tool execution, autocompact / microcompact / contextCollapse compaction chain, unkillable error recovery with bounded retries (P-14), strict tool_use ↔ tool_result pairing (P-4), guaranteed termination (P-5).

Tech stack

Front-end
Next.js 14 · TypeScript 5 strict · Tailwind · Framer Motion · pdf.js · D3 force
Edge runtime
Cloudflare Pages · Workers · Pages Functions WebSocket
Storage
D1 (CHECK-enforced P-1/P-8/P-13) · KV · R2
Async
Cloudflare Queues + DLQ · Durable Objects
Vectors
Vectorize × 3 (taxonomy · clauses · fewshot-live)
LLM
DeepSeek Chat (streaming SSE) via self-architected gateway
Tests
vitest + fast-check · 51 files / 223 tests · 15/15 properties

15 verified properties

Each row is enforced by at least one fast-check property test. CI fails the PR if any invariant is violated.

  • P-1Every approved Mapping has ≥ 1 bbox citation.
  • P-2OCR preserves chapter/article/clause hierarchy & monotonic byteSpan.
  • P-3queryGuard never permits two concurrent loops.
  • P-4Every tool_use has a paired tool_result (synthetic on abort).
  • P-5queryLoop terminates ≤ maxTurns.
  • P-6autocompact contracts token count below threshold.
  • P-7Bidirectional highlight within 16 ms.
  • P-8DPO tuples are well-formed (chosen ≠ rejected, all non-empty).
  • P-9reverseGround.passed ⟺ no violations.
  • P-10partitionToolCalls separates concurrent-safe vs serial.
  • P-11Few-Shot upsert queryable in < 1 s.
  • P-12Every event is causally linked & replayable.
  • P-13FSM transitions monotonic (modulo two explicit back-edges).
  • P-14Recovery cascade bounded.
  • P-15D1 evidence ↔ R2 tree.json bbox stay consistent.