Finance Agent
import { CodeFetcher } from '../../../components/CodeFetcher'
Let's build a finance agent that:
- Real-time Financial Analysis: Combines multiple data sources for comprehensive insights
- AI-Powered Insights: Leverages OpenAI GPT-4 for intelligent market analysis
- Web Search Integration: Aggregates latest market news and analysis
- Financial Data Integration: Real-time stock and company information
The Steps
<Tabs items={['finance-data', 'openai-analysis', 'query-api', 'response-coordinator', 'result-api', 'save-result', 'web-search']}>
🚀 Features
- Real-time Financial Analysis: Combines multiple data sources for comprehensive insights
- AI-Powered Insights: Leverages OpenAI GPT-4 for intelligent market analysis
- Event-Driven Architecture: Built on Motia's robust event system for reliable processing
- Web Search Integration: Aggregates latest market news and analysis
- Financial Data Integration: Real-time stock and company information
- Persistent Storage: Stores analysis results for future reference
- RESTful API: Easy integration with existing systems
📋 Prerequisites
- Node.js v16+
- npm or pnpm
- API keys for:
- Alpha Vantage (financial data)
- SerperDev (web search)
- OpenAI (AI analysis)
🛠️ Installation
-
Clone the repository:
git clone https://github.com/MotiaDev/motia-examples
cd examples/finance-agent -
Install dependencies:
pnpm install
# or
npm install -
Configure environment variables:
cp .env.example .envUpdate
.envwith your API keys:ALPHA_VANTAGE_API_KEY=your_alpha_vantage_api_key_here
SERPER_API_KEY=your_serper_api_key_here
OPENAI_API_KEY=your_openai_api_key_here
🏗️ Architecture
The workflow consists of several specialized steps that work together to provide comprehensive financial analysis:

🚦 API Endpoints
Query Endpoint
POST /finance-query
Content-Type: application/json
{
"query": "Latest information about AAPL and MSFT"
}
Response:
{
"message": "Query received and processing started",
"traceId": "abc123def456"
}
Results Endpoint
GET /finance-result/:traceId
Response:
{
"query": "Latest information about AAPL and MSFT",
"timestamp": "2023-06-15T12:34:56.789Z",
"response": {
"summary": "Results for \"Latest information about AAPL and MSFT\"",
"webResources": [...],
"financialData": [...],
"aiAnalysis": {...}
},
"status": "success"
}
🏃♂️ Running the Application
-
Start the development server:
pnpm dev -
Access the Motia Workbench:
http://localhost:3000 -
Make a test request:
curl -X POST http://localhost:3000/finance-query \
-H "Content-Type: application/json" \
-d '{"query": "Latest information about AAPL and MSFT"}'
🙏 Acknowledgments
- Motia Framework for the event-driven workflow engine
- Alpha Vantage for financial data
- SerperDev for web search capabilities
- OpenAI for AI analysis