Skip to content

Nickywine/contract-risk-system

Repository files navigation

AI Contract Risk System

AI-powered cross-border contract risk assessment system built with FastAPI.

Features

  • FastAPI backend with automatic OpenAPI documentation
  • Health check endpoints for monitoring
  • Docker-compatible deployment
  • Clean modular architecture
  • Environment-based configuration

Agentic Architecture

Our system employs a bounded, human-in-the-loop agentic architecture designed specifically for enterprise risk management. This approach fundamentally differs from generic AI agents by prioritizing control, explainability, and regulatory compliance.

Bounded Agents for Risk Management

Each agent operates within strictly defined boundaries:

  • Contract Risk Scout: Analyzes clause deviations against historical baselines using rule-based logic only
  • Client Intelligence Watcher: Monitors client risk signals with deterministic scoring algorithms
  • Risk Simulation Agent: Runs what-if scenarios with mathematical models, optional Monte Carlo analysis
  • Negotiation Strategy Agent: Generates template-based negotiation options with LLM assistance limited to language phrasing only
  • Learning & Calibration Agent: Proposes model adjustments based on historical outcomes, never auto-updates

Human Approval as a Safety Net

Every critical decision requires human approval:

  • Risk Thresholds: Expected loss > 25% triggers mandatory CFO escalation
  • Client Deterioration: Risk score increase > 15 points requires finance leadership review
  • Multiple High-Risk Flags: Three or more critical issues demand executive approval
  • Negotiation Actions: All recommendations require explicit human authorization before implementation

This governance framework ensures that AI augments human decision-making rather than replacing it.

Differentiation from Generic AI Agents

Traditional AI agents operate with broad autonomy and opaque reasoning. Our approach differs fundamentally:

Aspect Generic AI Agents Our Bounded Agents
Autonomy High autonomy, self-directed Strict task boundaries, no self-direction
Reasoning Black-box LLM reasoning Transparent rule-based logic
Decision Making Autonomous decisions Recommendations only, human approval required
Learning Continuous self-improvement Calibration proposals only, human-controlled updates
Audit Trail Limited or absent Complete immutable audit logging
Regulatory Compliance Variable Built-in compliance and governance

Trust Through Control, Not Capability

We increase trust by reducing uncontrolled behavior:

  • Deterministic Core: All critical risk calculations use transparent mathematical models
  • Explainable Decisions: Every recommendation includes clear reasoning and supporting evidence
  • Immutable Audit Trail: Complete logging of all agent executions for regulatory compliance
  • Governance Integration: Built-in escalation rules and approval workflows
  • Template-Based Actions: Negotiation and calibration use predefined templates, not generative AI

This architecture ensures that our system enhances human expertise while maintaining human control over critical risk decisions. The result is an AI system that enterprise risk leaders can trust, regulators can audit, and stakeholders can understand.

Project Structure

contract_risk_system/
├── app/
│   ├── api/              # API layer
│   │   └── v1/
│   │       ├── endpoints/    # API endpoints
│   │       └── api.py        # API router
│   ├── core/             # Core configuration
│   ├── services/         # Business logic
│   └── utils/            # Utility functions
├── main.py               # FastAPI application entry point
├── requirements.txt      # Python dependencies
├── Dockerfile           # Docker configuration
├── docker-compose.yml   # Docker Compose setup
└── .env.example         # Environment variables template

Quick Start

Local Development

  1. Install dependencies:

    pip install -r requirements.txt
  2. Run the application:

    python main.py
  3. Access the API:

Docker Deployment

  1. Build and run with Docker Compose:

    docker-compose up --build
  2. Access the API:

API Endpoints

Health Checks

  • GET /api/v1/health/health - Service health status
  • GET /api/v1/health/ping - Basic connectivity test

Root

  • GET / - Basic API information

Configuration

Copy .env.example to .env and modify as needed:

cp .env.example .env

Key environment variables:

  • HOST - Server host (default: 0.0.0.0)
  • PORT - Server port (default: 8000)
  • DEBUG - Debug mode (default: false)
  • LOG_LEVEL - Logging level (default: INFO)

Development

Adding New Endpoints

  1. Create endpoint file in app/api/v1/endpoints/
  2. Import and include router in app/api/v1/api.py
  3. Add business logic in app/services/
  4. Add utilities in app/utils/

Testing

# Install test dependencies
pip install pytest pytest-asyncio httpx

# Run tests
pytest

Deployment

Docker

# Build image
docker build -t contract-risk-system .

# Run container
docker run -p 8000:8000 contract-risk-system

Docker Compose

# Start services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down

Monitoring

The application includes built-in health checks:

  • Service status monitoring
  • Component health checks
  • Automatic health check endpoints

License

This project is licensed under the MIT License.

About

AI-powered contract risk assessment platform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors