Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stateful Multi-Agent Contract Auditor & Redline Engine ⚖️🤖

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.


Key Features

  1. Stateful Multi-Agent Graph (LangGraph):

    • Centralized strongly-typed state schema (ContractState) flowing across Parser, Audit Agent, Redline Agent, Gatekeeper Node, and OOXML Word Generator.
  2. 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.rels and [Content_Types].xml.
    • Generates native Word tracked changes and margin sidebar comments authored by AI Legal Auditor with native Accept/Reject functionality.
  3. Persistent Human-in-the-Loop Checkpointing (AsyncSqliteSaver in WAL Mode):

    • State checkpoints stored on disk in SQLite (contract_checkpoint.db) configured with PRAGMA journal_mode=WAL;.
    • Freezes execution on CRITICAL or HIGH risk clauses until explicit human sign-off via the dashboard or /approve API endpoint.
  4. 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.
  5. 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.

Quick Start

1. Installation

pip install -r requirements.txt

2. Environment Variables (Optional for LLM API)

Create 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).

3. Run Application

python main.py

Open your browser at http://localhost:8000 to access the interactive web dashboard.


API Endpoints

  • 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 .docx redline document.
  • GET /api/audit/playbook/rules: Retrieve internal risk playbook rules from Qdrant vector store.

About

Stateful Multi-Agent Contract Auditor & Redline Engine built with LangGraph, FastAPI, Qdrant Hybrid RAG, PyMuPDF, and Native MS Word OOXML Tracked Changes.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages