ai-garage

Contract Clarity Agent

AI-powered contract analysis assistant that helps individuals and small businesses understand legal documents through plain-language summaries, risk assessments, and conversational guidance.

Python 3.13+ Microsoft Agent Framework

✨ Features

πŸ—οΈ Tech Stack

Component Technology
AI Framework Microsoft Agent Framework
LLM GPT-4o-mini (Azure AI Foundry)
Frontend Streamlit
Document Processing Docling 2.0+
Web Scraping Firecrawl
Package Management UV
Python Version 3.13

πŸ“‹ Prerequisites

πŸš€ Quick Start

1. Clone Repository

git clone https://github.com/tezansahu/ai-garage.git
cd ai-garage/contract-clarity-agent

2. Install UV

Windows (PowerShell):

powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

macOS/Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh

3. Setup Environment

# Create virtual environment
uv venv

# Activate virtual environment
# Windows PowerShell:
.venv\Scripts\Activate.ps1
# Windows CMD:
.venv\Scripts\activate.bat
# macOS/Linux:
source .venv/bin/activate

# Install dependencies
uv pip install -e . --prerelease=allow

4. Configure Environment Variables

# Copy example environment file
cp .env.example .env

# Edit .env with your credentials

Required variables in .env:

# Azure AI Foundry Configuration
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_OPENAI_API_KEY=your-api-key-here
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME=gpt-4o
AZURE_OPENAI_API_VERSION=2025-01-01-preview

# Optional: Firecrawl for web content extraction
FIRECRAWL_API_KEY=your-firecrawl-api-key-here

5. Run the Application

streamlit run app.py

The app will open at http://localhost:8501

πŸ’‘ Usage

Document Analysis Workflow

  1. Upload Document: Click sidebar β€œBrowse files” β†’ Select PDF/DOCX/image
  2. Analyze: Click β€œπŸ” Analyze Document”
  3. Review Results:
    • Executive summary
    • Document type identification
    • Risk-flagged clauses (πŸ”΄ HIGH, 🟑 MEDIUM, 🟒 POSITIVE)
    • Key terms and definitions
    • Actionable recommendations
  4. Ask Questions: Use chat to ask follow-up questions about specific clauses

General Chat Mode

New Chat / Reset

πŸ“– Example Use Cases

Employment Agreement Analysis

1. Upload employment contract
2. Agent identifies:
   βœ“ IP assignment clauses
   βœ“ Non-compete restrictions  
   βœ“ Termination terms
   βœ“ Severance provisions
3. Ask: "Can I do freelance work on the side?"
4. Ask: "Is this non-compete enforceable in California?"

Vendor Contract Review

1. Upload vendor agreement
2. Agent flags:
   ⚠️  Auto-renewal clauses
   ⚠️  Payment terms and penalties
   ⚠️  Liability limitations
3. Ask: "What happens if I want to cancel early?"
4. Ask: "Are these payment terms negotiable?"

URL-Based Analysis

1. Chat: "Analyze the contract at https://example.com/terms"
2. Agent extracts web content via Firecrawl
3. Provides same detailed analysis
4. Answer follow-up questions

πŸ—‚οΈ Project Structure

contract-clarity-agent/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ agent.py                    # Main agent with Microsoft Agent Framework
β”‚   └── document_processor.py       # Docling + Firecrawl processors
β”œβ”€β”€ references/
β”‚   └── contract_clarity_prd.md     # Product requirements
β”œβ”€β”€ app.py                          # Streamlit UI
β”œβ”€β”€ example.py                      # Programmatic usage examples
β”œβ”€β”€ pyproject.toml                  # UV project configuration
β”œβ”€β”€ .env.example                    # Environment template
β”œβ”€β”€ .gitignore
β”œβ”€β”€ README.md                       # This file
└──CONTRIBUTING.md                 # Contribution guidelines

🎯 Risk Assessment Criteria

πŸ”΄ HIGH RISK

🟑 MEDIUM RISK

🟒 POSITIVE/STANDARD

πŸ”’ Privacy & Security

File Handling

Data Retention

Security

πŸ”§ Advanced Features

Logging & Debugging

Enable verbose logging to see agent operations:

import logging
logging.basicConfig(level=logging.INFO)

Logs include:

Programmatic Usage

from src.agent import ContractClarityAgent
import asyncio

async def main():
    # Initialize agent
    agent = ContractClarityAgent()
    
    # Analyze document
    result = await agent.analyze_document("contract.pdf")
    print(result["analysis"])
    
    # Ask follow-up
    response = await agent.ask_question("What are the payment terms?")
    print(response)
    
    # General chat
    response = await agent.chat("Explain indemnification")
    print(response)

asyncio.run(main())

Thread Management

# Start fresh conversation
agent.reset_conversation()

# New thread on next message
response = await agent.chat("Hello", new_thread=True)

πŸ› Troubleshooting

Import Errors

# Reinstall dependencies
uv pip install -e . --prerelease=allow --force-reinstall

Azure Authentication Issues

Document Processing Errors

PDF Issues:

# Reinstall Docling
uv pip install docling --force-reinstall

Slow Processing:

Firecrawl Errors

πŸ§ͺ Development

Running Examples

python example.py

Code Quality

# Install dev dependencies
uv pip install black ruff pytest pytest-asyncio

# Format code
black .

# Lint
ruff check .

# Run tests (when available)
pytest

⚠️ Limitations

πŸ“š Documentation

🀝 Contributing

See CONTRIBUTING.md for guidelines on:


⚠️ Legal Disclaimer: This tool provides informational analysis only and does not constitute legal advice. For specific legal guidance, consult a licensed attorney. Analysis is based on general patterns and may not reflect jurisdiction-specific requirements or recent legal changes.

Built with ❀️ using Microsoft Agent Framework