Google Sheets Financial Modeling Agent Template
A Mastra template showcasing a financial modeling agent that integrates with Google Sheets through Composio. This agent specializes in creating professional-grade financial models, projections, and analysis directly in Google Sheets.
Overview
This template demonstrates the powerful integration between Mastra and Composio to create an intelligent agent that can:
- š Create sophisticated financial models in Google Sheets
- š Build multi-year projections with detailed granularity
- š Develop integrated three-statement models (P&L, Balance Sheet, Cash Flow)
- š Design scenario planning frameworks and sensitivity analysis
- šÆ Provide professional spreadsheet design and formatting
- š¾ Maintain conversation memory and context.
Key Technologies
- Mastra: Core AI agent framework providing memory, tools integration, and conversation management
- Composio: Tool integration platform enabling seamless Google Sheets connectivity and authentication
- Claude 3.7 Sonnet: Language model for financial expertise and reasoning
- LibSQL: Local database for agent memory and vector storage
- FastEmbed: Efficient embeddings for semantic memory recall
Prerequisites
Before using this template, ensure you have:
- Node.js 20.9.0 or higher installed
- Composio account with Google Sheets integration configured
- Anthropic API key for Claude access
- Google account for Sheets integration (configured through Composio)
Required Configuration
Environment Variables
Create a .env file in the project root with the following variables:
1# Composio Configuration
2COMPOSIO_API_KEY=***
3COMPOSIO_AUTH_CONFIG_ID=***
4
5# AI Model Configuration
6ANTHROPIC_API_KEY=***
Composio Setup
- Create a Composio account at composio.dev
- Create a new Composio project
- Set up Google Sheets integration:
- Navigate to your Composio dashboard
- Create a new auth config
- Enable the Google Sheets toolkit
- Configure OAuth settings for Google Sheets access
- Note your
COMPOSIO_AUTH_CONFIG_IDfrom the integration settings
- Get your Composio API key from your account settings
Anthropic API Setup
- Create an Anthropic account at console.anthropic.com
- Generate an API key
- Add credits to your Anthropic account for API usage
Installation & Usage
-
Use this template:
npx create-mastra@latest --template google-sheets -
Install dependencies:
pnpm install -
Configure environment variables:
1cp .env.example .env 2# Edit .env with your actual API keys and configuration -
Start the development server:
pnpm dev -
Access the agent:
- API documentation:
http://localhost:4111/docs - Agent endpoint:
http://localhost:41111/api/agents/financialModelingAgent
- API documentation:
Agent Features
Authentication Flow
- Automatic Google OAuth integration through Composio
- Dynamic authentication prompts when user needs to authenticate
- Seamless reconnection handling for expired tokens
Financial Modeling Capabilities
- Revenue Analysis: Model diverse revenue streams (SaaS, transactional, recurring)
- Cost Structure: Build detailed COGS and operational expense models
- Cash Flow: Create comprehensive cash flow projections
- Scenario Planning: Design optimistic, base, and pessimistic scenarios
- Visualizations: Generate charts and executive summary dashboards
Memory & Context
- Persistent Memory: LibSQL-backed storage for conversation history
- Semantic Recall: Intelligent retrieval of relevant past interactions
- Working Memory: Maintains context within conversation threads
- Thread Management: Automatic title generation and organization
Project Structure
1template-google-sheets/
2āāā src/
3ā āāā mastra/
4ā āāā agents/
5ā ā āāā financial-modeling-agent.ts # Main agent configuration
6ā āāā index.ts # Mastra instance & middleware
7āāā .env.example # Environment variables template
8āāā package.json # Dependencies & scripts
9āāā tsconfig.json # TypeScript configuration
10āāā README.md # This file
Key Implementation Details
Dynamic Authentication
The agent uses runtime context to determine authentication state and provides appropriate instructions:
- When unauthenticated: Provides OAuth redirect URL and authentication instructions
- When authenticated: Proceeds directly to financial modeling tasks
Tool Integration
- Dynamic Tool Loading: Composio tools are loaded based on user's authenticated account
- Google Sheets Integration: Full access to Sheets API through Composio's normalized interface
Memory System
- Vector Storage: FastEmbed-powered semantic search across conversation history
- Contextual Recall: Retrieves relevant financial models and discussions from past sessions
- Thread Continuity: Maintains context across multiple modeling sessions
Customization
Modifying the Agent
Edit src/mastra/agents/financial-modeling-agent.ts to:
- Adjust the agent's expertise and instructions
- Modify the authentication flow
- Add additional capabilities or constraints
Adding Tools
The agent automatically receives Google Sheets tools through Composio. To add custom tools:
- Implement tools in the agent configuration
- Add them to the tools function alongside Composio tools
Memory Configuration
Adjust memory settings in the agent configuration:
lastMessages: Number of recent messages to includesemanticRecall: Vector search parametersworkingMemory: Enable/disable working memory features
Troubleshooting
Authentication Issues
- Verify
COMPOSIO_AUTH_CONFIG_IDmatches your Google Sheets integration - Ensure Google OAuth is properly configured in Composio dashboard
- Check that user has necessary Google Sheets permissions
API Errors
- Confirm
ANTHROPIC_API_KEYis valid and has sufficient credits - Verify
COMPOSIO_API_KEYhas access to Google Sheets integration - Check rate limits and API quotas
Support
For questions and support:
- Mastra Documentation: mastra.ai/docs
- Composio Documentation: docs.composio.dev
- Template Issues: Create an issue in the Mastra templates repository
