Skip to content

Contract Intelligence Platform combining layout-aware ingestion, NLI-based semantic diff, policy-grounded risk agents, and auditable multi-agent workflows — production-ready with tenant isolation, DLP, cost controls, and deterministic fallbacks.

License

Notifications You must be signed in to change notification settings

Fan-Luo/multi-agent-contract-platform

Repository files navigation

Multi Agent Contract Platform

Enterprise-grade Contract Comparison, Redlining & Legal Intelligence Platform.

What it includes

  • Clause-level semantic comparison (similarity + entailment/contradiction labels)
  • Legal risk detection (structured findings + buyer/seller bias + rationale)
  • DOCX redlining with tracked changes + in-document anchors (Word comments)
  • Production-ready architecture (API / Vector DB / LLM Routing / Agents / Workers)
  • Tenant isolation (DB + object store + vector filters)
  • Observability (structured logs, OpenTelemetry hooks) + Audit events
  • Modular model routing + per-tenant cost control + deterministic fallbacks

Quickstart (local)

1) Configure

cp .env.example .env
cp apps/api/.env.example apps/api/.env
cp apps/web/.env.example apps/web/.env

Set in apps/api/.env:

  • OPENAI_API_KEY=... (optional; platform will fallback where possible)
  • APP_ENV=dev
  • TENANT_DAILY_COST_BUDGET_USD=10

2) Run

docker compose up --build

3) Open


Website

The Next.js UI uses route-groups to separate the public website and the product UI:

  • Public website: apps/web/app/(marketing)/, /pricing, /security, /docs
  • Product UI: apps/web/app/(app) — dashboard, uploads, compare runs, findings, redlining, billing, audit

This keeps the product navigation shell consistent while allowing a clean, marketing-oriented landing site.


Real legal workflow

Step A — Upload and ingest (DOCX/PDF)

  1. In UI → Upload
  2. Choose a contract (DOCX recommended for redlining; PDF supported with OCR)
  3. Wait for ingestion (worker extracts text, chunks, clauses, embeddings)

You now have:

  • Original file in object storage
  • Extracted clauses in DB
  • Vector index in Qdrant

Step B — Clause-level comparison (semantic diff)

  1. UI → Compare
  2. Select Old and New versions
  3. Review:
  • similarity scores
  • entailment/contradiction labels (NLI)
  • change summaries per clause_type

API:

  • POST /v1/contracts/compare

Step C — Legal risk detection (multi-agent review)

  1. UI → Contract → Runs
  2. Trigger or review the latest agent run
  3. Output is explainable:
  • risk level
  • buyer/seller bias
  • findings + rationales

Backend:

  • Supervisor plans and budgets the run
  • Risk agent produces structured findings
  • Negotiation agent is optional (advice only)

Step D — DOCX redline for negotiation

  1. UI → Redline
  2. Select old/new DOCX contracts
  3. Download:
  • Redlined DOCX (Word Track Changes)
  • Clause Report JSON (audit-friendly)

Redlined DOCX includes Word comments as anchors:

  • a summary comment
  • per-changed clause_type comments with stable clause IDs

API:

  • POST /v1/redline/docx

Step E — Ask questions with evidence (RAG)

  1. UI → Contract → Ask
  2. Ask: “What is the termination notice period?”
  3. Get:
  • answer (grounded)
  • evidence snippets (explainable)

API:

  • POST /v1/qa/ask

Enterprise deployment

See:

  • docs/ENTERPRISE_DEPLOYMENT.md
  • docs/MODEL_STRATEGY.md

Key properties:

  • OIDC/JWKS authentication
  • tenant isolation end-to-end
  • tiered model routing (tier1/tier2/tier3) + per-tenant daily budgets
  • multi-agent workflows are declarative YAML under configs/workflows/

Model routing and cost control

  • model_tier1 and model_tier2 are configurable in apps/api/cip/settings.py
  • Daily tenant budget (USD): tenant_daily_cost_budget_usd
  • When budget is exceeded:
  • LLM calls are blocked
  • agents switch to deterministic/local fallbacks
  • outputs include warnings

Repo layout

  • apps/api: FastAPI + ingestion + agents + RAG + redlining
  • apps/web: Next.js UI
  • configs/workflows: declarative multi-agent workflows
  • docs: architecture, security, enterprise deployment, model strategy
  • infra/helm: Kubernetes templates (approved version)

Security and governance

  • Tenant isolation: DB + MinIO keys + Qdrant filters
  • Audit trail: append-only events
  • Observability: structured logs + OpenTelemetry hooks
  • Prompt registry: versioned prompts with stage mapping

License

This project uses the Business Source License 1.1 (BSL 1.1).

  • Change Date: 2029-10-01
  • Change License: Apache License, Version 2.0
  • Additional Use Grant: You may not use the Licensed Work to provide a commercial hosted or managed service to third parties.

See LICENSE for the full text.

Author: Fan Luo

About

Contract Intelligence Platform combining layout-aware ingestion, NLI-based semantic diff, policy-grounded risk agents, and auditable multi-agent workflows — production-ready with tenant isolation, DLP, cost controls, and deterministic fallbacks.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published