Welcome to this month's next newsletter edition!
Today, we're diving into something exciting - creating ProfitPilot AI, a powerful financial analysis tool that combines artificial intelligence with real-time market data. This project will give you hands-on experience with modern tech stacks with building AI Agents.
What We're Building
ProfitPilot AI is your personal financial analyst that helps you make data-driven decisions by analyzing both short-term market movements and long-term investment opportunities. The best part? It's powered by AI agents that work together to provide comprehensive insights sometimes called Multi-Agent Systems.
The Technology Stack
Let's break down the key components we'll be using:
1. CrewAI - Your AI Agent Framework
CrewAI is the backbone of our project, managing multiple AI agents that work in harmony. Each AI agent has a specific role:
One analyzes short-term market trends
Another focuses on long-term patterns
A third agent combines these insights into actionable recommendations
2. Streamlit - Your Frontend
Streamlit turns your Python scripts into beautiful web applications with minimal effort. We'll use it to create:
An interactive dashboard displaying real-time market data
Visual representations of AI insights
User-friendly controls for customizing analysis parameters
3. Yahoo Finance Library - Data Source
This library will be our window into the financial world, providing:
Real-time stock prices
Historical market data
Company fundamentals
Block Diagram
Let me explain how the architecture shown in this diagram works for ProfitPilot AI. This diagram illustrates the complete flow of how data and requests move through the system.
The process begins with the user interface, where a user (shown on the left) can input a stock query - in this example, they're interested in Tesla (TSLA). This interaction happens through a Streamlit interface, which provides a clean, web-based frontend for users to interact with the system.
When a query is submitted, it flows into the core ProfitPilot AI system, which then initiates AI agent, managed by CrewAI.
The first branch connects to Yahoo Finance (shown in the top right) as a custom tool. This is crucial because it fetches real-time financial data and ratios about Tesla. Think of this as the system's way of gathering raw financial intelligence about the stock.
This data then flows to two specialized agents:
1. The Financial Analyst Agent, which processes the raw financial data to understand the company's financial health, market position, and performance metrics.
2. The Investment Advisor Agent, which takes this analyzed information and transforms it into actionable investment advice.
Both these agents are powered by OpenAI's GPT-4-mini model (shown on the far right), which provides the artificial intelligence capabilities needed to process and interpret the financial data intelligently.
Finally, the system compiles all this information - the raw data, the financial analysis, and the investment advice - and returns it to the user through the Streamlit interface as a comprehensive result.
This architecture is particularly elegant because it combines the best of both worlds: the precision of financial data tools with power of AI, all while maintaining a user-friendly interface. The CrewAI framework ensures that these different components work together to provide best results.
Let’s look into the code
We will divide this in 5 parts,
Setup the streamlit dashboard
Create Agents
Create tool required to fetch the stock data from yahoo finance library
Creating the Crew
Bringing It All to Life: Running the Investment Analysis
1. Setup the streamlit dashboard
What you see below is the dashboard of the ProfitPilot AI we have build it using streamlit.
The UI has two main cards - one for short-term analysis and another for long-term analysis. The short-term and long-term analyses come from our Investment Advisor Agent working together with Financial Analyst Agent through CrewAI.
Code responsible for creating the dashboard is as below,
Streamlit function create_investment_dashboard() generates an interactive investment dashboard, analyzing a company's short-term and long-term outlook. It presents key insights—investment action, confidence score, and analysis—through visually structured cards. Designed for clarity, this tool helps investors make informed decisions at a glance.
2. Create Agents through CrewAI
Creating agents in CrewAI is straightforward. It has two parts
Defining three key elements of an Agent : Role, Goal, and Backstory—each playing a crucial part in shaping the agent’s effectiveness.
Role – The agent’s identity or function (e.g., "Financial Analyst" or "Market Researcher").
Goal – The specific objective the agent is designed to achieve (e.g., "Analyze stock trends and provide investment recommendations").
Backstory – A contextual narrative that enhances the agent’s decision-making accuracy by aligning it with a persona (e.g., "A seasoned Wall Street analyst with years of market expertise").
Define the task for above agent - In CrewAI, tasks provide clear instructions on what an agent should do and what kind of output to generate.
Description - The task to be done
Expected output - What needs to be delivered
Agent - Which AI agent will execute this task
Below is the code snippet of our financial Analyst AI Agent -
Corresponding Agent configuration is defined in yaml files as below,
and for tasks it is configured like below,
Now let’s move on to understanding how do we fetch the data from Yahoo Finance library and feed it to our AI Agent.
3. Creating a custom tool to fetch stock data
What is a Tool? - In CrewAI, tools enhance an AI agent’s capabilities by allowing it to interact with external data sources, APIs, or functions.
What is a Custom Tool? - While CrewAI offers built-in integrations, sometimes an agent needs specialized functionality. A custom tool is a user-defined function or API that expands an agent’s abilities beyond standard tools.
For example, if we want our The Financial Analyst Agent to fetch and analyze alternative data sources, we can create a custom tool like this shown below,
That was our first agent—now let’s move on to the second one, the Investment Advisor Agent. In the snippet below, something interesting happens: we take the output from our first agent and pass it to the second agent, enabling it to generate more accurate insights. This is where collaboration comes into play, forming what’s known as a multi-agent setup in CrewAI.
4. Creating the Crew
Now that our agents are ready, it's time to bring them together into a Crew to execute the end-to-end investment analysis. By structuring agents into a seamless workflow, we enable collaboration, allowing each agent to contribute its specialized expertise for a comprehensive stock analysis.
Let’s take a look at the snippet below:
@crew Decorator – Registers this function as a CrewAI crew setup.
Agents (self.agents) – A list of AI agents assigned to this crew, automatically generated via the
@agent
decorator.Tasks (self.tasks) – The defined tasks that agents will execute, created using the
@task
decorator.Process.sequential – Defines the execution flow as sequential, meaning agents complete tasks in a step-by-step manner rather than running in parallel.
verbose=True – Enables detailed logging, making it easier to track the workflow execution.
By structuring our Crew, we ensure that agents work together efficiently, passing insights from one to another to generate a complete, well-analyzed investment report.
5. Bringing It All to Life: Running the Investment Analysis
Now that we have structured our Crew, the final step is to kick off the execution and let our AI agents collaborate on the investment analysis. This is where the magic happens!
What is happening here?
User Interaction – When the user clicks the Analyze button, the process begins.
Crew Execution – The Investmentcrew() instance is initialized, and the kickoff() function is triggered with the stock ticker as input.
Data Processing – The raw results from the AI agents are structured into a well-defined investment report.
Dashboard Visualization – The investment dashboard is generated, providing a clear view of short-term and long-term stock insights.
Error Handling – If anything goes wrong, the user is notified with an error message
Since we are using the streamlit as UI, Just hit below command to start the application
Once the application is up and running, you’ll be greeted with an intuitive interface. Simply enter the name or ticker symbol of any stock, and watch as AI agents work in real-time to analyze it for you.
With just one input, you’ll get:
✅ Short-term & long-term investment insights
✅ Confidence scores for decision-making
✅ A comprehensive summary & conclusion
Go ahead—enter any stock name and see AI-driven analysis on the go…
Here is my git repo where all code can be found - github link
In case you prefer a video of the above explanation, go through my video below. Don’t forget to hit the like button and subscribe if you find the video useful—your support helps me create more valuable content like this!
And that’s a wrap for this edition! Stay tuned for more updates in the next newsletter. Until then, take care and stay curious!