AI-powered contract analysis assistant that helps individuals and small businesses understand legal documents through plain-language summaries, risk assessments, and conversational guidance.
| 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 |
git clone https://github.com/tezansahu/ai-garage.git
cd ai-garage/contract-clarity-agent
Windows (PowerShell):
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
macOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
# 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
# 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
streamlit run app.py
The app will open at http://localhost:8501
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?"
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?"
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
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
uploads/ directoryEnable verbose logging to see agent operations:
import logging
logging.basicConfig(level=logging.INFO)
Logs include:
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())
# Start fresh conversation
agent.reset_conversation()
# New thread on next message
response = await agent.chat("Hello", new_thread=True)
# Reinstall dependencies
uv pip install -e . --prerelease=allow --force-reinstall
AZURE_OPENAI_ENDPOINT format: https://your-resource.openai.azure.com/AZURE_OPENAI_API_KEY is validAZURE_OPENAI_CHAT_DEPLOYMENT_NAME matches your deployment2025-01-01-previewPDF Issues:
# Reinstall Docling
uv pip install docling --force-reinstall
Slow Processing:
FIRECRAWL_API_KEY is set in .envpython example.py
# Install dev dependencies
uv pip install black ruff pytest pytest-asyncio
# Format code
black .
# Lint
ruff check .
# Run tests (when available)
pytest
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