Financial Analysis Agent
Overview
This recipe demonstrates how to build an AI-powered financial analysis agent using Airtop’s browser automation capabilities combined with OpenAI’s GPT-4o model and Vercel AI’s SDK. The agent can autonomously navigate financial websites, extract stock data, and analyze the data without human intervention. Airtop is used as a tool in the Vercel AI SDK, and this simple example shows how you can instruct an LLM to call Airtop autonomously to navigate and interact with the web.
The complete source code is available on GitHub.
Prerequisites
Before getting started, ensure you have:
- Node.js installed on your system
- PNPM package manager installed. See here for installation steps.
- A Node Version Manager (NVM preferably).
- An Airtop API key. You can get one for free.
- OpenAI API key with GPT-4o access
What it Does
Below is a demo of this recipe. You can sign up to create an API key for free and try it out yourself!
Getting Started
- Clone the repository:
- Follow the setup instructions in the root README to install dependencies and build packages.
What the Service Does
1. Session and Browser Management
The service handles browser session initialization and cleanup:
2. AI Tools Configuration
The service configures three main tools for the AI agent using Vercel AI:
- URL Loading Tool:
- Data Extraction Tool:
- Click Interaction Tool:
By configuring Airtop as a tool, the agent can call into Airtop independently as it generates and executes its plan. While you can call Airtop explicitly in your agents, this is an excellent pattern for when you need a more complex agent reasoning and deciding to act on the web autonomously.
5. AI Analysis Implementation
The analysis process is orchestrated through the performAnalysis
method:
6. AI Prompt Engineering
A carefully crafted prompt guides the AI agent. This prompt gives high-level instructions to the LLM and inserts a high-level goal. By including tool configuration, some guidelines, and a goal, the LLM will produce tool calls into Airtop when necessary.
Running the Agent
To run the financial analysis agent:
- Set up your environment variables:
- Execute the script:
Example Output
The agent will provide structured output like:
Best Practices
-
Error Handling
- Implement robust error handling for network issues
- Add retry logic for failed interactions
- Validate data extraction results
-
Rate Limiting
- Respect API rate limits for both Airtop and OpenAI
- Implement exponential backoff for retries
-
Session Management
- Always clean up sessions after use
- Implement session timeout handling
- Monitor session resource usage
Summary
This recipe implements a simple financial analysis tool using Vercel AI SDK and Airtop. If you are building an agentic workflow, use this pattern to get started working with Airtop as a tool. You can follow this pattern with other agentic frameworks like CrewAI or Langchain.