Introduction
The OpsHub Agent System is a production-grade AI orchestration platform that powers intelligent automation across investment operations. Built on LangGraph and FastAPI with GPT-4 reasoning, it delivers 10 specialized domain agents with 62+ enterprise tools, enabling natural language interactions with complex financial workflows. This guide explains how the agent system works under the hood—from the LangGraph state machines that power agent reasoning to the AG-UI protocol that enables real-time bidirectional communication between frontend and backend.Core Concepts
Multi-Agent Orchestration
OpsHub uses a domain-specialized multi-agent architecture rather than a single general-purpose chatbot. Each agent is an expert in a specific domain with:- Scoped database access - Limited to relevant schemas and tables
- Specialized tool suite - Domain-specific automation capabilities
- Optimized prompts - Fine-tuned for investment operations terminology
- Role-based permissions - Aligned with organizational access controls
| Agent ID | Domain | Key Capabilities |
|---|---|---|
app | OpsHub Orchestrator | Workspace context, task delegation, validation status |
dashboard | Dashboard Architect | RG94-compliant dashboards, NAV variance tracking |
workbook | Workbook Engineer | Spreadsheet automation, validation logic, formula translation |
analytics | Investment Analytics Strategist | Performance attribution, scenario analysis, variance investigation |
workflow | Workflow Director | Process automation, NAV certification, breach escalation |
integration | Integration Specialist | Data connectivity, custodian integration, sync pipelines |
data-quality | Data Quality Analyst | Exception handling, profiling, reconciliation |
fund-accountant | Fund Accountant Assistant | Break investigation, NAV operations, certification |
portfolio-manager | Portfolio Manager Copilot | Performance insights, exposure analysis, action planning |
compliance | Compliance Sentinel | RG94 mapping, audit evidence, regulatory controls |
risk-analyst | Risk Analyst Copilot | VaR calculations, stress testing, limit monitoring |
- Generic training data lacking domain expertise
- Context windows insufficient for entire knowledge bases
- Difficulty maintaining focus across diverse tasks
- Domain specialization - Each agent masters a narrow domain
- Scoped context - Only relevant data and tools in context
- Superior accuracy - 30-40% better than general-purpose chatbots
- Scalability - Add new specialists without retraining existing agents
State Management & Checkpointing
The agent system maintains persistent conversational state across sessions using LangGraph’s checkpointing mechanism:- Session Continuity - Conversations persist across page reloads
- Multi-Device Access - Resume conversations from any device
- Error Recovery - Retry failed operations without losing context
- Audit Trail - Complete history of agent interactions
- Time Travel Debugging - Replay conversations from any checkpoint
agent.sessions- Session metadata and configurationagent.messages- Full conversation history with tool callsagent.drafts- User-approved/pending agent proposalsagent.insights- Real-time recommendations and alertsagent.tool_calls- Detailed tool execution audit trail
Tool Execution Framework
Agents interact with the OpsHub platform through a comprehensive tool suite (62+ tools) organized by category: Core Automation Tools:- Spreadsheet Tools (5) - Cell manipulation, formula generation, range operations
- Natural Language Query (2) - Convert English to SQL queries
- Database Operations (4) - Schema inspection, query execution, data summaries
- Draft Management (1) - Capture agent suggestions for user review
- Breach Prediction (2) - ML-powered forecasting and risk scoring
- Anomaly Detection (2) - Real-time outlier detection in holdings/transactions
- Auto-Reconciliation (2) - Automated break analysis and resolution
- Self-Healing Workflows (2) - Automatic error recovery
- Approval Management (3) - Auto-approval rules, workflow orchestration
- Compliance Checks (6) - ASIC RG94 verification, audit evidence
- Explainability & HITL (3) - Decision explanations, confidence scoring
- Report Generation (3) - Automated regulatory and operational reports
- Workflow Generation (3) - AI-generated workflow definitions
- Scheduling Optimization (3) - Intelligent task scheduling
- Smart Suggestions (5) - Context-aware automation recommendations
- Agent Delegation (3) - Multi-agent task decomposition
- Memory & Context (4) - User preference learning, case history recall
- Document Extraction (2) - Structured data extraction from PDFs
- Analytics & Performance (4) - Cross-agent performance analytics
- Automatic
tenant_idinjection into database queries - Row-level security (RLS) policy enforcement
- Audit logging to
audit.audit_log - Quota tracking and enforcement
Natural Language Processing
The agent system uses GPT-4o (OpenAI) for natural language understanding with: Optimized Prompting:- Domain-specific system prompts for each agent
- Investment operations terminology and abbreviations
- ASIC RG94 compliance context
- Example few-shot prompts for complex tasks
- Automatic workspace context detection from current page
- Relevant catalog items (dashboards, workflows, datasets)
- Recent conversation history (last 20 messages)
- User preferences and memory (learned patterns)
- Token-by-token streaming via Server-Sent Events (SSE)
- Real-time tool execution updates
- Progressive artifact rendering
- Optimistic UI updates
Architecture Overview
High-Level System Architecture
Component Responsibilities: Frontend (Next.js 15)- React UI components for chat, artifacts, context
- AG-UI client for real-time bidirectional state sync
- Zustand stores for optimistic updates and local state
- Server-Sent Events (SSE) for streaming responses
- Next.js API routes proxy requests to backend
- Supabase authentication and JWT validation
- Environment variable protection (no CORS exposure)
- LangGraph workflow orchestration
- GPT-4o reasoning and tool selection
- Tool execution with tenant isolation
- State checkpointing to Supabase
- 14 specialized business schemas
- Agent state persistence tables
- Row-level security (RLS) policies
- Real-time subscriptions for live updates
LangGraph Workflow Engine
OpsHub uses LangGraph (LangChain’s graph-based orchestration framework) for durable agent workflows:- Start - User message enters workflow at agent node
- Agent Node - GPT-4o analyzes message and decides:
- Generate text response (go to END)
- Execute tools (go to Tool Node)
- Tool Node - Execute requested tools in parallel
- Loop - Return results to agent node for next turn
- End - Stream final response to user
- Durable Execution - Survives crashes, continues from checkpoints
- Event Sourcing - Complete audit trail of all state transitions
- Retry Policies - Automatic error recovery with exponential backoff
- Human-in-Loop - Approval gates for high-risk actions
- Observability - LangSmith tracing for debugging
Technology Stack
LangGraph Workflow Engine
Purpose: Orchestrate multi-turn agent conversations with state persistence Key Features:- State Machines - Define agent workflows as directed graphs
- Checkpointing - Persist state at each node transition
- Conditional Routing - Dynamic workflow paths based on LLM decisions
- Tool Execution - Parallel tool calls with result aggregation
- Error Handling - Retry policies and fallback strategies
FastAPI Backend
Purpose: High-performance Python API server for agent endpoints Key Endpoints:POST /agent/stream- AG-UI protocol streaming endpoint (primary)POST /api/chat- Simple chat API (alternative)POST /api/agents- Multi-agent orchestrationGET /api/agents- List available agentsPOST /api/agents/set-active- Switch active agentGET /health- Service health monitoring
- JWT authentication via Supabase
- Tenant context injection
- Request/response logging
- Rate limiting (optional Redis)
- CORS configuration
Supabase Integration
Database Schemas (14 total): Core Business Schemas:investment- Portfolios, securities, holdings, transactionsvalidation- ASIC RG94 compliance rules and resultsrisk- Risk metrics and VaR calculationscompliance- Regulatory checks and audit evidenceperformance- Attribution and TWR calculationsmarket_data- Time-series price data (TimescaleDB)workflow- Daily pricing workflows (Temporal)audit- Audit logs (partitioned by quarter)
iam- Teams, users, roles, permissionsagent- Sessions, messages, drafts, insights, tool_callsintegration- Data sources, sync jobs, field mappingsvault- Secure credential storagedistribution- Report deliverables and recipientsanalytics- Advanced analytics and reporting
- 62%+ of tables have RLS enabled
- IAM role-based access control
- Team-scoped data visibility
- Automatic tenant isolation
GPT-4 Reasoning
Model:gpt-4o (OpenAI)
Configuration:
- Temperature: 0.0 (deterministic responses)
- Max Tokens: 4096 per response
- Streaming: Token-by-token via SSE
- Function Calling: Native tool schema support
Data Flow
Request/Response Flow
Step-by-Step Breakdown:-
User Input
- User types message in chat interface
- Frontend captures workspace context (active workbook, sheet, dashboard)
- Context includes page surface, selected cells, catalog items
-
Frontend Processing
- AG-UI client prepares
RunAgentInputwith messages and context - Zustand stores handle optimistic UI updates
- SSE connection established for streaming
- AG-UI client prepares
-
API Proxy
- Next.js API route validates Supabase JWT
- Adds authentication headers (Bearer token)
- Proxies request to FastAPI backend
-
Backend Orchestration
- FastAPI receives request, validates tenant
- Loads agent configuration and system prompt
- Invokes LangGraph workflow with current state
-
Agent Reasoning
- LangGraph agent node sends prompt to GPT-4o
- Model analyzes message and workspace context
- Decides to execute tools or generate text response
-
Tool Execution
- Tool node receives tool call requests
- Injects tenant context into each tool
- Executes tools in parallel where possible
- Returns results to agent node
-
Response Streaming
- Agent generates response tokens
- Streamed via SSE to frontend
- Artifacts extracted and rendered separately
- Insights and drafts displayed in real-time
-
State Persistence
- LangGraph saves checkpoint to Supabase
- Messages, drafts, insights written to agent tables
- Audit log entry created for compliance
State Synchronization Flow
The AG-UI protocol enables bidirectional state synchronization between frontend and backend: State Sync Features:- Workspace Awareness - Agents see current page, workbook, dashboard
- Real-Time Updates - UI responds instantly to agent actions
- Multi-Agent Coordination - Delegation chains tracked with full context
- Draft System - AI proposals require explicit user approval
- Offline Resilience - State cached locally, syncs when online
- Audit Trail - Every state change logged for compliance
Security & Permissions
Authentication Flow
Authentication Helpers:Row-Level Security (RLS)
PostgreSQL RLS policies enforce fine-grained access control: Example: Portfolio Access Policy| Role | Scope | Permissions |
|---|---|---|
ADMIN | GLOBAL | Full system access |
FUND_MANAGER | ORGANIZATION | Manages funds and strategies |
PORTFOLIO_MANAGER | TEAM | Manages portfolios |
OPERATIONS_LEAD | ORGANIZATION | Operational activities |
COMPLIANCE_OFFICER | ORGANIZATION | Compliance and audits |
VIEWER | TEAM | Read-only access |
Tenant Isolation
Every agent tool execution is wrapped with tenant context:Performance Considerations
Response Time Optimization
Target Latencies:- Initial response: < 2 seconds
- Tool execution: < 5 seconds
- Stream first token: < 500ms
- Database queries: < 100ms
- Parallel Tool Execution - LangGraph executes independent tools concurrently
- Database Indexing - All foreign keys and frequently queried columns indexed
- Materialized Views - Pre-aggregated data for dashboard queries
- Query Caching - Redis cache for read-heavy endpoints
- Connection Pooling - Persistent database connections (Supabase Supavisor)
Scalability
Horizontal Scaling:- FastAPI backend deployed on Fly.io with auto-scaling
- Multiple worker instances handle concurrent requests
- Stateless design (all state in Supabase)
- Supabase Pro plan: 8GB RAM, 4 vCPU
- Connection pool: 100 concurrent connections
- TimescaleDB optimizations for time-series data
- Infrastructure: ~$65/month (Fly.io + Supabase)
- OpenAI API: ~$0.01-0.03 per conversation
- Total: Less than $100/month for 1,000 conversations
Monitoring
Health Checks:- Agent response times (p50, p95, p99)
- Tool execution success rates
- Database query performance
- Token usage and costs
- Error rates by agent/tool
Learn More
Deeper Dives
- Agent Integration Patterns - Learn about CopilotKit, AG-UI, SSE streaming, and workspace sync patterns
- Backend Fact Sheet - Complete technical architecture and tool suite documentation
- Architecture Decision Record - Why we chose LangGraph + Python over TypeScript alternatives
- Database Schema - Explore the 14 business schemas and agent state tables
Related Topics
- User Guides - Step-by-step tutorials for building with agents
- API Reference - Complete agent API documentation
- Tool Development - Create custom tools for your agents
- Deployment - Production deployment guide for Fly.io
Summary
The OpsHub Agent System delivers intelligent automation for investment operations through:- Multi-Agent Orchestration - 10 specialized domain experts
- LangGraph Workflows - Durable execution with checkpointing
- Comprehensive Tool Suite - 62+ enterprise automation tools
- Real-Time Bidirectional Sync - AG-UI protocol integration
- GPT-4 Reasoning - Natural language understanding
- Enterprise Security - RLS policies, tenant isolation, audit trails
- Production-Ready - Less than $100/month infrastructure, auto-scaling
| Decision | Rationale |
|---|---|
| LangGraph over TypeScript | Battle-tested Python ecosystem, superior state management |
| FastAPI backend | High performance, async support, OpenAPI documentation |
| Supabase PostgreSQL | Real-time subscriptions, RLS policies, TimescaleDB extensions |
| AG-UI protocol | Framework-agnostic bidirectional state sync |
| GPT-4o model | Best balance of performance, cost, and reasoning capability |
- Explore the Agent Integration Patterns guide
- Review the Backend Fact Sheet for complete tool documentation
- Build your first agent integration using the API Reference