How sifir-gun/contract-decision-graph works
Contract Decision Graph analyzes supplier-contract text and returns GO, GO_RESERVES, NO_GO, or ESCALADE with a justification and sealed audit record. The user workflow runs from the web interface through the contract service and LangGraph engine: validate input, extract and verify clauses, assess four domains, apply deterministic rules, route uncertainty to human review, explain, then seal. Corpus retrieval and local embeddings support assessment; PostgreSQL stores audit and resumable graph state. Major capabilities are taken from the README; unsampled subsystem internals and some adapter wiring are not asserted.
Main entry points: orchestrator.py Graph orchestrator · decision_gate.py Decision gate · app.py Web interface · engine.py Graph engine
Components 31
User entry
- Web interface
src/cdg/adapters/web/app.py - Contract service
src/cdg/application/service.py
Decision workflow
- Graph engine
src/cdg/adapters/langgraph/engine.py - Graph orchestrator
src/cdg/adapters/langgraph/orchestrator.py - Validate input
src/cdg/application/nodes/validate_input.py - Extract clauses
src/cdg/application/nodes/extract_clauses.py - Verify extraction
src/cdg/application/nodes/verify_extraction.py - Domain analysts
src/cdg/application/nodes/analyst.py - Decision gate
src/cdg/application/nodes/decision_gate.py - Human review
src/cdg/application/nodes/reject.py - Explanation
src/cdg/application/nodes/explain.py - Audit sealing
src/cdg/application/nodes/audit_seal.py
Assessment and corpus
- CRAG retrieval
src/cdg/application/crag.py - Corpus ingestion
src/cdg/application/ingestion.py - Corpus model
src/cdg/domain/corpus.py - Retriever port
src/cdg/ports/retriever.py - Postgres RAG store
src/cdg/adapters/postgres/rag_store.py - Local embeddings
src/cdg/adapters/fastembed.py - LLM port
src/cdg/ports/llm.py
Rules and audit
- Domain rules
src/cdg/domain/rules - Decision models
src/cdg/domain/models.py - Decision config
src/cdg/domain/config.py - Audit functions
src/cdg/domain/audit.py
Runtime adapters
- Mistral adapter
src/cdg/adapters/llm/mistral.py - Anthropic adapter
src/cdg/adapters/llm/anthropic.py - Audit store adapter
src/cdg/adapters/postgres/audit_store.py - Graph checkpointer
src/cdg/adapters/langgraph/checkpointer.py - OIDC identity
src/cdg/adapters/oidc.py
Other components
- Analyst
- Human reviewer
- PostgreSQL
Connections 32
- Analyst → Web interface: submits contract
README.md - Web interface → Contract service: calls actions
src/cdg/adapters/web/app.py - Contract service → Graph engine: runs analysis
src/cdg/application/service.py - Graph engine → Graph orchestrator: opens graph
src/cdg/adapters/langgraph/engine.py - Graph orchestrator → Validate input: routes to
README.md - Graph orchestrator → Extract clauses: routes to
README.md - Graph orchestrator → Verify extraction: routes to
README.md - Graph orchestrator → Domain analysts: routes to
README.md - Graph orchestrator → Decision gate: routes to
README.md - Graph orchestrator → Human review: routes to
README.md - Graph orchestrator → Explanation: routes to
README.md - Graph orchestrator → Audit sealing: routes to
README.md - Domain analysts → CRAG retrieval: assesses passages
README.md - CRAG retrieval → Retriever port: searches corpus
src/cdg/application/crag.py - Retriever port → Postgres RAG store: implemented by
src/cdg/adapters/postgres/rag_store.py - Postgres RAG store → Local embeddings: embeds queries
src/cdg/adapters/postgres/rag_store.py - Corpus ingestion → Corpus model: builds chunks
src/cdg/application/ingestion.py - CRAG retrieval → LLM port: judges passages
src/cdg/application/crag.py - LLM port → Mistral adapter: implemented by
src/cdg/adapters/llm/mistral.py - LLM port → Anthropic adapter: alternative adapter
- Domain analysts → Domain rules: applies rules
README.md - Decision gate → Domain rules: determines verdict
README.md - Domain rules → Decision models: uses decision types
src/cdg/domain/rules/_common.py - Decision gate → Human reviewer: interrupts for review
README.md - Human review → Explanation: continues to
README.md - Audit sealing → Audit functions: seals decision
README.md - Audit functions → Audit store adapter: persists record
- Audit store adapter → PostgreSQL: writes audit log
- Graph checkpointer → PostgreSQL: stores checkpoints
src/cdg/adapters/langgraph/checkpointer.py - Web interface → OIDC identity: verifies identity
src/cdg/adapters/web/app.py - Graph engine → Graph checkpointer: resumes threads
src/cdg/adapters/langgraph/engine.py - Decision gate → Decision config: uses thresholds