An enterprise-grade, asynchronous, stateful multi-agent contract audit and redline engine built on LangGraph, FastAPI, Qdrant Vector RAG, PyMuPDF, and OOXML Native Tracked Changes.
-
Stateful Multi-Agent Graph (LangGraph):
- Centralized strongly-typed state schema (
ContractState) flowing acrossParser,Audit Agent,Redline Agent,Gatekeeper Node, andOOXML Word Generator.
- Centralized strongly-typed state schema (
-
True MS Word OOXML Tracked Changes (
w:ins,w:del,w:comment):- Injects low-level OpenXML nodes and pre-registers relationship targets in
word/_rels/document.xml.relsand[Content_Types].xml. - Generates native Word tracked changes and margin sidebar comments authored by AI Legal Auditor with native Accept/Reject functionality.
- Injects low-level OpenXML nodes and pre-registers relationship targets in
-
Persistent Human-in-the-Loop Checkpointing (
AsyncSqliteSaverin WAL Mode):- State checkpoints stored on disk in SQLite (
contract_checkpoint.db) configured withPRAGMA journal_mode=WAL;. - Freezes execution on
CRITICALorHIGHrisk clauses until explicit human sign-off via the dashboard or/approveAPI endpoint.
- State checkpoints stored on disk in SQLite (
-
Throttled Batch Engine (
asyncio.Semaphore+ Exception Isolation):- Processes 50+ contract clauses concurrently with rate-limiting (
asyncio.Semaphore(10)) and single-clause fault isolation (return_exceptions=True), reducing document turnaround time from minutes to seconds.
- Processes 50+ contract clauses concurrently with rate-limiting (
-
Layout-Aware PDF Clause Parsing (
PyMuPDF / fitz):- Preserves parent section headers (e.g.
Section 14.2(b)(ii) [Limitation of Liability]) to eliminate context loss during RAG retrieval.
- Preserves parent section headers (e.g.
pip install -r requirements.txtCreate a .env file or export your API key:
export GEMINI_API_KEY="your-google-gemini-api-key"
export LLM_PROVIDER="google" # or "openai"(Note: If no API key is set, the system seamlessly runs in local RAG heuristic mode).
python main.pyOpen your browser at http://localhost:8000 to access the interactive web dashboard.
POST /api/audit/upload: Upload PDF or Docx vendor contract to initiate multi-agent audit thread.GET /api/audit/{thread_id}/state: Fetch live state, audit findings, flagged risk clauses, and proposed redlines.POST /api/audit/{thread_id}/approve: Submit human review sign-off or custom overrides to un-pause workflow.GET /api/audit/{thread_id}/download: Download generated native Microsoft Word.docxredline document.GET /api/audit/playbook/rules: Retrieve internal risk playbook rules from Qdrant vector store.