Skip to content

nathan-a-king/mastra-agent-poc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Financial Services Multi-Agent POC

TypeScript Mastra License

A production-ready proof of concept demonstrating multi-agent AI orchestration for financial services using the Mastra framework.

๐ŸŒŸ Overview

This project showcases 2025's "Year of the Agent" paradigm shift from generative AI to agentic AI - systems that don't just generate content but autonomously execute complex tasks. Built for a hypothetical financial services company, this POC demonstrates how multiple specialized AI agents can work together to provide comprehensive financial advisory services.

Key Features

โœจ Multi-Agent Orchestration - Specialized agents coordinated under an orchestrator model ๐Ÿ›ก๏ธ Compliance-First Architecture - Built-in regulatory compliance and safety checks ๐Ÿ”ง Production-Ready Framework - Uses Mastra, a TypeScript agent framework from the Gatsby team ๐ŸŽฏ Domain Expertise - Specialized agents for portfolio analysis, risk assessment, market research, and compliance ๐Ÿ”„ Flexible Workflows - Both hierarchical and workflow-based agent coordination patterns ๐Ÿ“Š Comprehensive Tools - 15+ specialized financial analysis tools ๐Ÿ”’ Safety & Governance - Human-in-the-loop, audit trails, and explainable AI

๐Ÿ—๏ธ Architecture

Multi-Agent System

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    Financial Advisor Agent                       โ”‚
โ”‚                      (Orchestrator)                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚            โ”‚            โ”‚            โ”‚
               โ–ผ            โ–ผ            โ–ผ            โ–ผ
      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
      โ”‚ Portfolio  โ”‚ โ”‚    Risk    โ”‚ โ”‚   Market   โ”‚ โ”‚ Compliance โ”‚
      โ”‚  Analyst   โ”‚ โ”‚ Assessment โ”‚ โ”‚  Research  โ”‚ โ”‚   Agent    โ”‚
      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Specialized Agents

  1. Portfolio Analyst Agent ๐Ÿ“Š

    • Portfolio composition analysis
    • Asset allocation recommendations
    • Performance metrics (Sharpe ratio, alpha, beta)
    • Diversification scoring
    • Rebalancing suggestions
  2. Risk Assessment Agent โš ๏ธ

    • Risk metric calculation (VaR, CVaR, volatility)
    • Risk profile compatibility assessment
    • Stress testing scenarios
    • Risk mitigation strategies
  3. Market Research Agent ๐Ÿ“ˆ

    • Market trend analysis
    • Sector performance evaluation
    • Economic indicator monitoring
    • Sentiment analysis
  4. Compliance Agent โœ…

    • Regulatory compliance checking (SEC, FINRA)
    • Investment suitability assessment
    • KYC/AML verification
    • Compliance reporting
  5. Financial Advisor Agent ๐ŸŽ“

    • Orchestrates all specialized agents
    • Client request interpretation
    • Response synthesis
    • Human escalation

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18+ and npm
  • Anthropic API key (Claude)
  • Optional: OpenAI API key for multi-provider support

Installation

# Clone the repository
git clone <repository-url>
cd mastra-agent-poc

# Install dependencies
npm install

# Set up environment variables
cp .env.example .env
# Edit .env and add your ANTHROPIC_API_KEY

Configuration

Edit .env file:

ANTHROPIC_API_KEY=your_anthropic_api_key_here
AGENT_TEMPERATURE=0.7
AGENT_MAX_ITERATIONS=10

Running Examples

# Portfolio analysis example
npm run portfolio-analysis

# Risk assessment example
npm run risk-assessment

# Market research example
npm run market-research

# Full orchestrated workflow
npm run orchestrated

๐Ÿ“– Usage Guide

Individual Agent Usage

import { portfolioAnalystAgent } from './agents/portfolio-analyst';

const result = await portfolioAnalystAgent.generate(`
  Analyze this portfolio and provide recommendations:
  ${JSON.stringify(portfolio)}
`);

console.log(result.text);

Workflow-Based Orchestration

import { executePortfolioReview } from './workflows/portfolio-review-workflow';

const result = await executePortfolioReview({
  portfolio: clientPortfolio,
  client: clientProfile,
});

console.log('Analysis:', result.portfolioAnalysis);
console.log('Risks:', result.riskAssessment);
console.log('Recommendations:', result.recommendations);

Investment Decision Workflow

import { executeInvestmentDecision } from './workflows/investment-decision-workflow';

const decision = await executeInvestmentDecision({
  investmentType: 'ETF',
  investmentAmount: 100000,
  client: clientProfile,
  currentPortfolio: portfolio,
});

console.log('Approved:', decision.approved);
console.log('Confidence:', decision.confidence);
console.log('Reasoning:', decision.reasoning);

๐Ÿ”ง Available Tools

Portfolio Tools

  • analyzePortfolio - Asset allocation and diversification analysis
  • calculatePerformanceMetrics - Returns, Sharpe ratio, alpha, beta
  • suggestRebalancing - Portfolio rebalancing recommendations

Risk Tools

  • calculateRiskMetrics - VaR, CVaR, volatility, max drawdown
  • assessRiskProfile - Risk tolerance alignment
  • runStressTest - Market stress scenario testing

Market Tools

  • getMarketData - Current market data fetching
  • analyzeTrends - Technical and sentiment analysis
  • researchSector - Sector-specific research
  • analyzeEconomicIndicators - Macro indicator analysis

Compliance Tools

  • checkCompliance - Regulatory compliance verification
  • assessSuitability - Investment suitability scoring
  • generateComplianceReport - Audit trail generation

๐Ÿ“š Project Structure

mastra-agent-poc/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ agents/              # AI agent definitions
โ”‚   โ”‚   โ”œโ”€โ”€ portfolio-analyst.ts
โ”‚   โ”‚   โ”œโ”€โ”€ risk-assessment.ts
โ”‚   โ”‚   โ”œโ”€โ”€ market-research.ts
โ”‚   โ”‚   โ”œโ”€โ”€ compliance.ts
โ”‚   โ”‚   โ””โ”€โ”€ financial-advisor.ts
โ”‚   โ”œโ”€โ”€ tools/               # Agent tools
โ”‚   โ”‚   โ”œโ”€โ”€ portfolio-tools.ts
โ”‚   โ”‚   โ”œโ”€โ”€ risk-tools.ts
โ”‚   โ”‚   โ”œโ”€โ”€ market-tools.ts
โ”‚   โ”‚   โ””โ”€โ”€ compliance-tools.ts
โ”‚   โ”œโ”€โ”€ workflows/           # Multi-agent workflows
โ”‚   โ”‚   โ”œโ”€โ”€ portfolio-review-workflow.ts
โ”‚   โ”‚   โ””โ”€โ”€ investment-decision-workflow.ts
โ”‚   โ”œโ”€โ”€ examples/            # Usage examples
โ”‚   โ”‚   โ”œโ”€โ”€ portfolio-analysis.ts
โ”‚   โ”‚   โ”œโ”€โ”€ risk-assessment.ts
โ”‚   โ”‚   โ”œโ”€โ”€ market-research.ts
โ”‚   โ”‚   โ””โ”€โ”€ orchestrated-workflow.ts
โ”‚   โ”œโ”€โ”€ types/              # TypeScript type definitions
โ”‚   โ”œโ”€โ”€ config/             # Configuration management
โ”‚   โ””โ”€โ”€ index.ts            # Main entry point
โ”œโ”€โ”€ ARCHITECTURE.md         # Detailed architecture documentation
โ”œโ”€โ”€ README.md              # This file
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ tsconfig.json

๐Ÿ›ก๏ธ Safety & Governance

Built-in Safety Measures

  1. Human-in-the-Loop: Critical decisions flagged for human approval
  2. Compliance-First: All recommendations pass through compliance checks
  3. Explainable AI: Every agent decision includes reasoning
  4. Audit Trails: Complete logging of all agent interactions
  5. Graceful Degradation: Fallback mechanisms when agents fail

Security Considerations

  • Input validation and sanitization
  • Output filtering for inappropriate recommendations
  • Rate limiting to prevent abuse
  • Secure API key management
  • Data privacy protection

๐ŸŽฏ Use Cases

1. Comprehensive Portfolio Review

Multi-agent workflow analyzing portfolio from multiple perspectives:

  • Asset allocation analysis
  • Risk evaluation
  • Market context
  • Compliance verification

2. Investment Decision Support

Compliance-first workflow for evaluating new investments:

  • Regulatory pre-check
  • Market research
  • Risk assessment
  • Portfolio fit analysis

3. Risk Management

Proactive risk monitoring and mitigation:

  • Real-time risk metric tracking
  • Stress testing
  • Risk tolerance alignment
  • Mitigation strategies

4. Regulatory Compliance

Automated compliance checking:

  • Suitability assessments
  • Regulatory requirement verification
  • Audit trail generation
  • Conflict of interest detection

๐Ÿ”ฎ Future Enhancements

  • Memory Layer: Persistent client context and conversation history
  • RAG Integration: Connect to financial databases and documents
  • Multi-Modal Support: Document and chart analysis
  • Real-Time Data: Live market data integration
  • Advanced Orchestration: Dynamic agent selection based on complexity
  • Learning Loop: Agent improvement from historical interactions
  • Voice Interface: Voice-based agent interactions
  • Computer Use: Agents that can interact with financial software

๐ŸŒ Agent Framework Landscape

Why Mastra?

Mastra represents the DIY platform approach in the agentic framework spectrum:

Advantages:

  • Full control over agent behavior and orchestration
  • TypeScript-native for modern web development
  • Built by proven team (Gatsby creators)
  • Open-source and extensible
  • Production-ready with observability

Alternative Approaches:

  • Turnkey Solutions: LangChain, AutoGPT (higher abstraction, less control)
  • Provider-Specific: OpenAI Assistants, Anthropic Claude (vendor lock-in)
  • Custom Built: Full flexibility, higher development cost

๐Ÿ“Š Key Concepts: 2025 Year of the Agent

From Generative to Agentic AI

Generative AI (2022-2024)

  • Generate content (text, images, code)
  • Require explicit instructions
  • Single-turn interactions
  • Human drives the process

Agentic AI (2025+)

  • Execute complex tasks autonomously
  • Reason about goals and strategies
  • Multi-turn, iterative problem solving
  • AI drives the process with human oversight

Multi-Agent Orchestration Patterns

  1. Hierarchical: Orchestrator delegates to specialists (this POC)
  2. Collaborative: Agents work together as peers
  3. Sequential: Agents work in pipeline stages
  4. Competitive: Multiple agents propose solutions, best selected

๐Ÿค Contributing

This is a proof of concept for demonstration purposes. For production use:

  1. Implement real market data integrations
  2. Add persistent storage for client data
  3. Enhance security and authentication
  4. Add comprehensive testing
  5. Implement monitoring and alerting
  6. Add regulatory compliance modules specific to your jurisdiction

๐Ÿ“„ License

ISC License - see LICENSE file for details

๐Ÿ™ Acknowledgments

  • Mastra Framework - The TypeScript AI agent framework
  • Anthropic Claude - The LLM powering our agents
  • Financial services domain expertise from industry best practices

๐Ÿ“ž Support

For questions or issues:

  • Review the ARCHITECTURE.md for detailed design information
  • Check the examples in src/examples/
  • Open an issue in the repository

Built with โค๏ธ demonstrating the future of AI agents in financial services

This is a proof of concept for educational and demonstration purposes. Not for production use in regulated financial advisory without proper compliance review and licensing.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors