Inspiration
As freelancers ourselves, we've experienced the frustration of:
- Clients refusing to pay for completed work
- Signing contracts with hidden unfair clauses
- Not understanding legal terms like "indemnification" or "force majeure"
- Losing money because we didn't know how to negotiate better terms
Hiring a lawyer costs $300-500/hour - money most freelancers don't have for routine issues. We built FreeLegal AI to democratize legal help for the 1.57 billion freelancers worldwide who deserve fair treatment but can't afford traditional legal services.
What it does
FreeLegal AI provides instant legal assistance through 4 specialized AI agents, each powered by Claude 3.5 Sonnet v2 via AWS Bedrock AgentCore:
⚡ Action Agent
- Purpose: Immediate help for urgent legal issues
- Example: "My client won't pay $5000" → Receives step-by-step action plan with country-specific legal options, demand letter templates, and timeline
🔍 Analysis Agent
- Purpose: Contract review and red flag detection
- Example: Upload a PDF contract → Identifies unfair payment terms (90-day payment vs industry standard Net-30), missing clauses, liability risks, and provides recommended changes
💡 Explanation Agent
- Purpose: Translates legal jargon into plain English
- Example: "What does indemnification mean?" → Receives simple explanation with real-world examples, risks, and how to protect yourself
🤝 Negotiation Agent
- Purpose: Tactical advice for contract negotiations
- Example: "How to push back on IP transfer?" → Receives negotiation scripts, counter-proposals, and professional talking points
Key Features:
- 📄 Contract Upload: PDF/TXT upload with automatic text extraction using AWS Textract
- 💬 Context-Aware Conversations: Agents maintain session memory across messages
- 🌍 Localized Advice: Country-specific legal guidance (e.g., Egyptian Economic Courts, US small claims)
- 🎯 Role-Based Intelligence: Each agent specializes in one domain for expert responses
- ⚡ 10-Second Responses: Fast enough for urgent situations
How we built it
Architecture
User Browser → CloudFront (CDN) → S3 (Static Website) ↓ API Gateway → Lambda (Orchestrator) → Bedrock AgentCore → Claude 3.5 Sonnet v2
Frontend (HTML/CSS/JavaScript)
- 4 specialized chat interfaces (one per agent)
- Responsive design with real-time upload feedback
Backend (AWS Lambda - Python 3.12)
orchestrator_lambda_proxy.py: Routes requests to appropriate agent- Prepends role-specific instructions to differentiate agent behavior:
- Action: "Provide immediate action plans with timeline..."
- Analysis: "Review contracts for red flags, compare to industry standards..."
- Explanation: "Explain legal terms in 8th-grade English with examples..."
- Negotiation: "Provide tactical negotiation advice with scripts..."
AI Layer (AWS Bedrock AgentCore)
- Model: Claude 3.5 Sonnet v2 (
us.anthropic.claude-3-5-sonnet-20241022-v2:0) - AgentCore Runtime:
freelancer_action_agent-Q83Rk73nkD - Memory: Session-based conversation history (
freelancer_action_agent_mem-Fh4JVHDpfJ) - Deployment: Used
agentcore launchCLI for agent deployment
Infrastructure
- S3 Bucket: Static website hosting (
freelancer-legal-assistant-frontend-897722703585) - CloudFront: Global CDN distribution (
EU3P3ID6QAQ5R) - API Gateway: REST API endpoint (
https://inr0anapu2.execute-api.us-east-1.amazonaws.com) - Region: us-east-1
Challenges we ran into
1. Agent Response Quality
Problem: Initially, all 4 agents gave identical generic responses regardless of their role.
Cause: Single AgentCore agent couldn't distinguish between different agent types from system prompt alone.
Solution: Built orchestration layer in Lambda that prepends role-specific instructions to each request. This allows one agent to behave as 4 specialized agents.
2. Session Memory & Context
Problem: Agents forgot previous messages in conversation, requiring users to repeat information.
Solution:
- AgentCore's default memory feature stores conversation history
- Generated unique session IDs per chat:
action-1729697123-abc123 - Passed same session ID throughout conversation
- Memory persists until page refresh
3. Cost Optimization
Problem: Initially planned 4 separate AgentCore agents = 4x cost.
Solution: Single agent + Lambda role routing = $1/month vs $4/month (75% savings)
What we learned
AWS Bedrock AgentCore
- How to deploy agents using
agentcore launchCLI - Session-based memory configuration for conversation history
- Model selection (Claude 3.5 Sonnet v2 optimal for legal reasoning)
- Agent ARN/alias management for production deployment
Lambda + Bedrock Integration
bedrock-runtime.invoke_agent()event stream handling- IAM permissions:
bedrock:InvokeAgentvsbedrock-runtime:InvokeAgent - Parsing streaming responses from AgentCore
- Error handling for timeout, throttling, and model errors
Prompt Engineering for Legal AI
- Role-based instructions must be very specific (generic = generic output)
- Country/jurisdiction must be explicit in prompts
- Format instructions (use bullets, bold, sections) improve readability
- Examples in prompts increase output quality 10x
Frontend-Backend Integration
- CORS configuration for cross-origin API calls
- Session ID generation and management
- Real-time feedback for async operations (file upload, API calls)
- Error states and user feedback patterns
Cost Optimization
- Bedrock pricing: $3 per 1M input tokens, $15 per 1M output tokens
- AgentCore: ~$1/month per agent for memory + runtime
- CloudFront: Cache-Control headers reduce origin requests 90%
- Lambda: 512MB memory optimal for Bedrock API calls (faster = cheaper)
What's next for FreeLegal AI
Phase 1: Core Improvements (1 month)
- [ ] Deploy 4 separate AgentCore agents (instead of orchestrated routing)
- [ ] Add user authentication (AWS Cognito)
- [ ] Store conversation history in DynamoDB
- [ ] A/B test Claude 3 Opus vs Sonnet for legal accuracy
Phase 2: Advanced Features (3 months)
- [ ] Contract Generation: Generate custom contracts from user requirements
- [ ] Voice Input: Web Speech API for hands-free use
- [ ] Multi-Language: Arabic, Spanish, French translations
- [ ] Email Integration: Send demand letters directly from the app
- [ ] Contract Templates: Library of freelancer-friendly contract templates
- [ ] Payment Calculator: Estimate small claims court costs, collection agency fees
Phase 3: Enterprise & Monetization (6 months)
- [ ] Lawyer Network: Connect users with vetted lawyers for complex cases
- [ ] Team Features: Shared contracts, collaborative editing
- [ ] Admin Dashboard: Usage analytics, A/B testing results
- [ ] API Access: Let other freelance platforms integrate FreeLegal
- [ ] Premium Tier: $29/month for unlimited conversations + priority support
- [ ] White-Label: License to freelance platforms (Upwork, Fiverr, etc.)
Phase 4: Global Expansion (12 months)
- [ ] 200+ Countries: Localized legal guidance for all jurisdictions
- [ ] Industry-Specific: Agents for designers, developers, writers, consultants
- [ ] Mobile Apps: iOS/Android native apps
- [ ] Slack/Discord Bots: Integrate into team communication tools
- [ ] Document Scanner: Mobile OCR for contract scanning
- [ ] Legal AI Training: Fine-tune custom model on freelance contracts
Dream Feature: Preventive Legal OS
Build a complete "legal operating system" for freelancers:
- Auto-generate contracts based on project details
- Real-time contract negotiation (AI suggests edits as you type)
- Payment protection (hold funds in escrow until work approved)
- Automated invoicing with late payment reminders
- Legal insurance integration
- Dispute resolution arbitration
Vision: Make legal protection accessible, affordable, and automatic for every freelancer worldwide.
Built With
- agentcore
- api-gateway
- bedrock
- boto3
- cloudfront
- cloudwatch
- css3
- html5
- iam
- javascript
- lambda
- markdown
- python
- s3

Log in or sign up for Devpost to join the conversation.