Day 11Productivity & FinanceRAGQdrantLegalTech

Multi-Agent Legal Squad — AI Agent for legal PDF clause risk triage

Mitigates risk by flagging clauses in long-form legal PDFs.

Impact

Mitigates risk by flagging clauses in long-form legal PDFs.

Mechanism

3-Agent PDF Risk Triage

DAY 11
Full README · Case Study

👨‍⚖️ AI Legal Agent Team

A beautiful, friendly app that reads your legal PDFs and lets a team of smart AI helpers analyze them for you.

🚀 Quick Start • 🛠️ Detailed Setup • 🧯 Help


A Streamlit application that simulates a full-service legal team using multiple AI agents to analyze legal documents and provide comprehensive legal insights. Each agent represents a different legal specialist role, from research and contract analysis to strategic planning, working together to provide thorough legal analysis and recommendations.

🗂️ Table of Contents


Features

  • Specialized Legal AI Agent Team

    • Legal Researcher: Equipped with DuckDuckGo search tool to find and cite relevant legal cases and precedents. Provides detailed research summaries with sources and references specific sections from uploaded documents.

    • Contract Analyst: Specializes in thorough contract review, identifying key terms, obligations, and potential issues. References specific clauses from documents for detailed analysis.

    • Legal Strategist: Focuses on developing comprehensive legal strategies, providing actionable recommendations while considering both risks and opportunities.

    • Team Lead: Coordinates analysis between team members, ensures comprehensive responses, properly sourced recommendations, and references to specific document parts. Acts as an Agent Team coordinator for all three agents.

  • Document Analysis Types

    • Contract Review - Done by Contract Analyst
    • Legal Research - Done by Legal Researcher
    • Risk Assessment - Done by Legal Strategist, Contract Analyst
    • Compliance Check - Done by Legal Strategist, Legal Researcher, Contract Analyst
    • Custom Queries - Done by Agent Team - Legal Researcher, Legal Strategist, Contract Analyst

How to Run

  1. Setup Environment

    bash
    # Clone the repository
    git clone "repo link"
    cd advanced_ai_agents/multi_agent_apps/agent_teams/ai_legal_agent_team
    
    # Install dependencies
    pip install -r requirements.txt
    
  2. Configure API Keys

  3. Run the Application

    bash
    streamlit run legal_agent_team.py
    
  4. Use the Interface

    • Enter API credentials
    • Upload a legal document (PDF)
    • Select analysis type
    • Add custom queries if needed
    • View analysis results

🚀 Super-Simple Setup (So easy a 5‑year‑old can follow!)

  • 🧰 What you need

    • A computer with internet
    • Python 3.10+
    • An OpenAI key and a Qdrant account (don’t worry, steps below!)
  • 🎁 Get the tools

  • 📦 Install

    bash
    pip install -r requirements.txt
    
  • 🔐 Put your secrets in a magic box (.env) Create a file named .env in the project folder and add:

    ini
    OPENAI_API_KEY=your_openai_api_key_here
    QDRANT_URL=https://YOUR-CLUSTER-URL.qdrant.io
    QDRANT_API_KEY=your_qdrant_api_key_here
    
  • ▶️ Run the app

    bash
    streamlit run legal_agent_team.py
    
  • 🖱️ Click & Go

    • Paste keys if not auto-filled
    • Upload a PDF
    • Pick an analysis
    • Press Analyze → ✨ Magic!

🎯 What this app does (Like story time!)

  • 📄 You give it a PDF (a contract or legal doc)
  • 🧠 The app reads it and remembers the important bits
  • 🤖 Three helpful AI friends look at it:
    • 🕵️ Legal Researcher: finds references and cases
    • 🧾 Contract Analyst: spots key terms and issues
    • 🧭 Legal Strategist: gives smart next steps
  • 🧩 A Team Lead combines all answers into one helpful result

🧪 Supported Models & Services

  • 🔊 Chat model: gpt-4o (via OpenAI)
  • 🧩 Embeddings: text-embedding-3-small (via OpenAI)
  • 🧠 Vector database: Qdrant Cloud
  • 🔎 Web search: DuckDuckGo (no key needed)

Tip: Using a local stack? See local_ai_legal_agent_team/local_legal_agent.py (Ollama + local Qdrant).


🛠️ Detailed Setup (Grown‑ups section)

  1. Create accounts/keys
  • OpenAI → create a project and API key
  • Qdrant Cloud → create a cluster, copy HTTPS URL + API key
  1. Configure .env
  • Put OPENAI_API_KEY, QDRANT_URL, QDRANT_API_KEY
  • The app auto-loads them on start via python-dotenv
  1. Install Python deps
bash
pip install -r requirements.txt
  1. Launch
bash
streamlit run legal_agent_team.py

🧭 How it works (Under the hood)

  1. You upload a PDF → it’s turned into chunks
  2. 📚 Chunks get embeddings (OpenAI) → stored in Qdrant
  3. 🔎 When you ask, agents search the knowledge base
  4. 🧩 Team Lead merges answers → you get a clean report

🗃️ Repository Structure

text
ai_legal_agent_team/
├─ legal_agent_team.py                 # Main Streamlit app (OpenAI + Qdrant Cloud)
├─ local_ai_legal_agent_team/
│  ├─ local_legal_agent.py            # Local app (Ollama + local Qdrant)
│  └─ requirements.txt
├─ requirements.txt                    # Python dependencies
├─ README.md                           # You are here 📘
└─ .gitignore                          # Keeps secrets and junk out of git

🧰 Advanced: Local (No OpenAI) Setup

Run fully local with Ollama + local Qdrant (click to expand)

  1. Install and start Qdrant locally (Docker)
bash
docker run -p 6333:6333 -p 6334:6334 qdrant/qdrant
  1. Install Ollama and pull models
bash
https://ollama.com/download
ollama pull llama3.1:8b
ollama pull openhermes
  1. Install deps for local app and run
bash
pip install -r local_ai_legal_agent_team/requirements.txt
streamlit run local_ai_legal_agent_team/local_legal_agent.py

🧯 Troubleshooting

  • “ddgs not installed” → run: pip install -r requirements.txt
  • “Failed to connect to Qdrant” → check QDRANT_URL & QDRANT_API_KEY
  • “OpenAI key invalid” → verify billing and key value in .env
  • Blank results → ensure your PDF has selectable text (not just images)

❓ FAQ

  • Can I use it without OpenAI?
    • Yes, try the local app in local_ai_legal_agent_team/ (Ollama + local Qdrant)
  • What files are supported?
    • PDFs for now
  • Is there a cost?
    • OpenAI and Qdrant usage may incur costs

🌟 Make it yours

  • Change model: edit OpenAIChat(id="gpt-4o")
  • Change embedding: edit text-embedding-3-small
  • Add new agents or tools using agno

❤️ Credits

  • Built with Streamlit, Agno, OpenAI, Qdrant, DuckDuckGo

🤝 Contributing

  • Fork this repo
  • Create a feature branch: git checkout -b feat/amazing-idea
  • Commit changes: git commit -m "feat: add amazing idea"
  • Push: git push origin feat/amazing-idea
  • Open a Pull Request 🚀

📜 License

This project is open-source. Add your preferred license in a LICENSE file.


⭐ Star this repo

If this helped you, please star the repo — it motivates continued improvements!


Explore more agents

30 open-source systems · full registry

Browse All 30 Agents