Production-grade multi-agent system for intelligent portfolio analysis and retirement planning
Five AI agents. One orchestrated system. Real financial analysis at scale.
Built on AWS serverless with Terraform, powered by Azure OpenAI GPT-4o, and running vector search at 90% less cost. This isn't a prototypeโit's production infrastructure handling multi-tenant workloads with autonomous research, real-time insights, and zero server management.
- 5 specialized AI agents collaborating through SQS messaging
- Azure OpenAI GPT-4o powering intelligent analysis
- Parallel Lambda execution for 3x faster processing
- Autonomous research with Tavily API integration
- Each agent focused, independent, unified insights
- 100% Terraform-managed serverless AWS architecture
- S3 Vectors for 90% cost reduction vs traditional vector DBs
- Aurora Serverless v2, Lambda, App Runner, SageMaker embeddings
- CloudWatch observability + LangFuse agent tracing
- Zero servers, automatic scaling, pay-per-use
- Next.js 15 + React 19 with TypeScript and Framer Motion
- Clerk authentication with multi-tenant PostgreSQL isolation
- API Gateway with key-based security
- Real-time streaming responses and CloudFront CDN
- EventBridge automated research scheduling (every 2 hours)
- Compute: AWS Lambda (6 functions), App Runner (Researcher service)
- Database: Aurora Serverless v2 PostgreSQL
- AI/ML: Azure OpenAI GPT-4o, SageMaker Serverless (embeddings)
- Storage: S3 (vectors, static assets), ECR (Docker images)
- Orchestration: SQS, EventBridge Scheduler
- Frontend: CloudFront + S3, API Gateway
- Monitoring: CloudWatch, LangFuse (observability)
Schema Design:
- users: Clerk authentication with retirement goals and target allocations
- accounts: Investment accounts (401k, IRA, taxable) with cash positions
- positions: Holdings per account with quantity and valuation date
- instruments: Shared ETF/stock reference data with JSONB allocation metadata
- jobs: Async analysis tracking with dedicated JSONB fields per agent output (no merging logic needed)
- Language: Python 3.12 with
uvpackage management - LLM: Azure OpenAI GPT-4o (chat completions API)
- Agents Framework: OpenAI Agents SDK
- Embeddings: SageMaker Serverless (sentence-transformers)
- Web Search: Tavily API
- Observability: LangFuse for tracing
- Framework: Next.js 15 (React 19, TypeScript)
- Styling: Tailwind CSS
- Auth: Clerk
- Charts: Recharts
- Animations: Framer Motion
- IaC: Terraform (modular architecture)
- Cloud: AWS (Lambda, Aurora, S3, CloudFront, API Gateway, SQS, EventBridge)
- Containers: Docker, ECR
- Database: PostgreSQL (Aurora Serverless v2)
- Vector Storage: S3 Vectors
alex/
โโโ backend/ # Python agents and Lambda functions
โ โโโ planner/ # Orchestrator agent (coordinates all agents)
โ โโโ tagger/ # Instrument classification agent
โ โโโ reporter/ # Portfolio analysis and metrics
โ โโโ charter/ # Data visualization and charting
โ โโโ retirement/ # Retirement projections
โ โโโ researcher/ # Autonomous web research (App Runner)
โ โโโ ingest/ # Document processing and vector storage
โ โโโ database/ # Shared database library
โ โโโ api/ # FastAPI backend for frontend
โ
โโโ frontend/ # Next.js application
โ โโโ pages/ # Route components
โ โโโ components/ # React components
โ โโโ lib/ # API client and utilities
โ
โโโ terraform/ # Infrastructure as Code (modular)
โ โโโ 2_sagemaker/ # SageMaker embedding endpoint
โ โโโ 3_ingestion/ # S3 Vectors, ingest Lambda
โ โโโ 4_researcher/ # App Runner research service
โ โโโ 5_database/ # Aurora Serverless v2
โ โโโ 6_agents/ # Multi-agent Lambda deployment
โ โโโ 7_frontend/ # CloudFront, S3, API Gateway
โ โโโ 8_enterprise/ # Monitoring and dashboards
โ
โโโ scripts/ # Deployment automation
The entire AWS infrastructure is managed through Terraform modules, deployed in sequence:
- SageMaker โ Serverless embedding endpoint
- Ingestion โ S3 Vectors, document processing Lambda
- Researcher โ App Runner service with Tavily integration
- Database โ Aurora Serverless v2 cluster
- Agents โ Multi-agent Lambda functions + SQS orchestration
- Frontend โ CloudFront distribution, S3 hosting, API Gateway
- Enterprise โ CloudWatch dashboards and monitoring
Planner Agent (Orchestrator):
- Receives user requests via API Gateway
- Coordinates execution across specialized agents
- Manages state and context flow
- Returns unified responses
Specialized Agents:
- Tagger: Classifies financial instruments (stocks, bonds, ETFs)
- Reporter: Analyzes portfolio performance, risk metrics, allocations
- Charter: Generates interactive visualizations and charts
- Retirement: Projects retirement scenarios with Monte Carlo simulations
- Researcher: Conducts autonomous web research using Tavily API
โ Serverless Multi-Agent System: Deployed coordinated AI agents with sub-2s response times
โ Cost-Optimized Infrastructure: Reduced vector storage costs from $300/mo to $30/mo
โ Production-Grade Observability: Integrated LangFuse for complete agent tracing
โ Infrastructure as Code: 100% Terraform-managed, reproducible deployments
โ Real-Time Web Research: Automated market research with Tavily API integration
โ Full-Stack SaaS Platform: Clerk authentication, multi-tenant PostgreSQL, responsive UI
โ Autonomous Scheduling: EventBridge-triggered research updates every 2 hours
โ Enterprise Security: API Gateway authentication, user-level data isolation
- Architecting multi-Lambda orchestration with SQS
- Optimizing Aurora Serverless v2 for cost and performance
- Managing serverless cold starts and connection pooling
- Building reliable multi-agent systems with error handling
- Implementing observability with LangFuse tracing
- Prompt engineering for consistent financial analysis
- Modular Terraform architecture for complex systems
- Managing state and dependencies across 7 infrastructure layers
- Automated deployment pipelines with
uvand Docker
- Implementing S3 Vectors for cost-effective similarity search
- SageMaker Serverless endpoint optimization
- Chunking strategies for financial documents
- Next.js 15 App Router with server components
- Real-time streaming from Lambda via API Gateway
- Clerk authentication with multi-tenant isolation
- WebSocket Integration: Replace polling with real-time bidirectional communication
- Redis Caching: Cache research results and agent responses
- A/B Testing: Compare agent prompts and model performance
- GraphQL API: More flexible data fetching for frontend
- Portfolio Optimization: ML-powered asset allocation recommendations
- Risk Scoring: Real-time risk assessment dashboard
- Document Chat: Interactive Q&A with uploaded financial documents
- Mobile App: React Native companion app
- Multi-Region Deployment: Global availability with Route53
- Kubernetes Migration: EKS for advanced orchestration
- Prometheus/Grafana: Enhanced monitoring stack
- CI/CD Pipeline: GitHub Actions for automated testing and deployment
Harsh Patel
๐ง code.by.hp@gmail.com
๐ GitHub โข LinkedIn
A big thank you to Ed Donner for his excellent MLOps Track, which played a key role in shaping this project and my understanding of building production-grade, agentic AI systems.
๐ Course: Generative and Agentic AI in Production
๐ https://www.udemy.com/course/generative-and-agentic-ai-in-production/
โญ Star this repo if you found it insightful


