DEV Community

Audrey Kadjar
Audrey Kadjar

Posted on • Edited on

Google Cloud Run Hackathon: Building Lexi — a Multi-Agent AI Legal Assistant for Individuals

It all started when I was reviewing an employment contract for a new job offer and found that I was struggling to understand the legal jargon.

I realized how difficult it can be for individuals to truly understand complex legal language. Legal documents are often dense, time-consuming, and intimidating to review. Most people struggle to grasp key clauses and identify potential risks, particularly in employment or freelance agreements.

That’s where Lexi comes in: a multi-agent AI legal assistant designed to make contract analysis clear, accessible, and easy to understand for individuals. Built for the Google Cloud Run Hackathon, Lexi focuses on delivering accurate, structured insights without overwhelming the user.

Lexi’s vision is to help people understand any legal document, anywhere in the world. For now, it’s trained specifically on employment contracts in English under German law, as part of this project’s scope.


⚙️ How It Works

  • You upload your employment, freelance, or NDA contract.
  • Lexi analyzes each clause using multiple AI agents.
  • On the frontend, Lexi streams the analysis in real time for a smooth, interactive experience.
  • It highlights potential risks, compares clauses to standard legal documents, and explains everything in plain, human-friendly language.

In short, Lexi makes legal document understanding faster, clearer, and even enjoyable.


🧱 System Architecture

                           ┌───────────────────────────────┐
                           │        Frontend (React)       │
                           │-------------------------------│
                           │ • Upload contract (PDF/Text)  │
                           │ • View clause analysis (live) │
                           │                               │
                           └──────────────┬────────────────┘
                                          │
                             JSON POST /contracts/analyze
                                          │
                                          ▼
                            ┌───────────────────────────────┐
                            │         FastAPI Backend       │
                            │        (Runs on Cloud Run)    │
                            │-------------------------------│
                            │ 1️⃣ Receives contract payload  │
                            │ 2️⃣ Extracts text (if PDF)     │
                            │ 3️⃣ Sends to CoreOrchestrator  │
                            │ 4️⃣ Streams structured JSON     │
                            │     chunks back to frontend   │
                            └──────────────┬────────────────┘
                                           │
                                           ▼
                     ┌────────────────────────────────────────────┐
                     │       Google ADK Agent System (Vertex AI)  │
                     │--------------------------------------------│
                     │ 🧭 CoreOrchestrator (LLM)                  │
                     │     ├─ ClauseExtractorAgent (LLM)          │
                     │     ├─ StandardClauseRetriever (Embed)     │
                     │     ├─ ClauseComparisonAgent (LLM)         │
                     │     └─ RiskAnalysisAgent (LLM)             │
                     │                                            │
                     └────────────────────────────────────────────┘
                                           │
                                           ▼
                           Streamed JSON → FastAPI → React
Enter fullscreen mode Exit fullscreen mode

🧩 Stack Overview

  • Frontend: React (Cloud Run)
  • Backend: FastAPI (Cloud Run)
  • Storage: Firestore (for embeddings)
  • LLMs: gemini-embedding-001, gemini-2.0-flash
  • OCR: In-memory PDF text extraction
  • Containerization: Docker
  • Deployment: Google Cloud Run

🤖 Multi-Agent System

Agent Role
RootOrchestratorAgent Coordinates all specialized agents
SequentialAgent Ensures ordered clause processing
ClauseExtractorAgent Extracts clauses from the contract
StandardClauseRetriever Retrieves reference clauses from Firestore embeddings
ComparisonAgent Detects deviations from standard clauses
RiskAnalysisAgent Explains potential issues in plain language

All agents collaborate through an orchestrator and shared state — creating a flexible and extensible system for document intelligence.

🧠 What I Learned

  • How to orchestrate multi-agent systems using Google ADK
  • How to integrate embeddings with Firestore for semantic retrieval
  • How to deploy AI workloads on Google Cloud Run efficiently
  • How to design real-time streaming UIs with FastAPI and React

🏆 Accomplishments

  • Combining Gemini models, Google ADK, Firestore to create an AI app that improves a process and solves a real-world problem.
  • Using Cloud Run to deploy services seamlessly

🚀 What’s Next

🔹 Expand to more document types (leases, NDAs, terms of service)
🔹 Add conversational Q&A (“Ask Lexi about clause 5”)
🔹 Support multiple languages for global accessibility
🔹 Explore secure authentication and saved session histories

You can explore the project’s code on the GitHub repo—feel free to share any feedback. Wishing the best of luck to everyone!

Top comments (0)