Motia Icon

Finance Agent

A powerful event-driven financial analysis workflow that combines web search, financial data, and AI analysis to provide comprehensive investment insights.

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

finance-data.step.ts
openai-analysis.step.ts
query-api.step.ts
response-coordinator.step.ts
result-api.step.ts
save-result.step.ts
web-search.step.ts

🚀 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

🛠️ Installation

  1. Clone the repository:

    git clone https://github.com/MotiaDev/motia-examples
    cd examples/finance-agent
  2. Install dependencies:

    pnpm install
    # or
    npm install
  3. Configure environment variables:

    cp .env.example .env

    Update .env with 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:

Finance Agent

🚦 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

  1. Start the development server:

    pnpm dev
  2. Access the Motia Workbench:

    http://localhost:3000
  3. 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

Need help? See our Community Resources for questions, examples, and discussions.

On this page