Introduction
Investing in stocks and other assets is an interesting affair but it can be very challenging and hectic even for the better of us. Now, imagine having a personal analyst who follows news, and trends, and advises financial strategy based on his observation. Sounds great, right? But let’s be honest most of us are not blessed enough to hire a personal financial analyst. But what if you have an intelligent financial analyst who works round the clock and keeps you updated with trends? Thanks to the recent advancement in AI technologies, you can create a personal financial analyst within a few minutes.
This article demonstrates how to build an AI investment analyst using CrewAI, Gemini models, and Composio.
Learning Objectives
Learn about the basics of CrewAI and Composio.
Understand the workflow of the AI investment analyst.
Build an AI investment analyst agent with CrewAI and Composio.
What is CrewAI?
CrewAI is an open-source framework for building collaborative multi-agent systems. It allows developers to build complex agentic automation workflows where interaction among multiple agents is paramount. CrewAI allows individual AI agents to assume roles, delegate tasks, and share goals akin to a real-world crew. CrewAI mainly consists of five core features Agents, Tasks, Tools, Processes, and Tasks.
Agents: Agents operate as autonomous entities tasked with reasoning, delegating tasks, and communicating with fellow agents, much like a team in the real world.
Tasks: Tasks are precise assignments allocated to agents. They outline the steps and actions required for an agent to achieve a specific goal.
Tools: Tools equip agents to carry out tasks that exceed the capabilities of LLMs, such as web scraping, email responses, and task scheduling.
Process: In CrewAI, processes manage the execution of tasks by agents, ensuring that tasks are allocated and performed effectively and systematically. These processes can be sequential, where tasks are completed one after another, or hierarchical, where tasks are carried out based on a tiered authority structure.
Crews: Crews within CrewAI consist of collaborative agents equipped with tasks and tools, all working together to tackle complex tasks.
What is Composio?
Composio is an open-source production-ready tooling solution for AI agents. It enables developers to seamlessly integrate external tools and applications with AI agents while handling OAuth and other authentication mechanisms crucial for deploying AI agents in real-world scenarios.
Composio has over 150 tools and integrations in its repertoire to accommodate a range of functionalities. These tools enable developers to customize AI agents for specific tasks, for instance, automating user feedback collection with Typeform, managing data flows with Google Sheets for CRM integration and trend analysis, or coordinating projects effectively using Jira and Trello. This versatility allows for highly customized and efficient workflows tailored to meet specific operational demands. For more information check out the documentation page.
This tutorial will use Composio’s SerpAPI tool for web search and information gathering.
Agent Workflow
Now, let’s explore the workflow of our AI investment analyst. We will use CrewAI to build a collaborative crew of agents. The crew will have a researcher, an analyst, and a recommender agent. Individual agents will have goals and backstories to give more context to the LLM about the agent before doing the task. The agents will have access to the necessary tools. We will equip the agents with a web search tool in this case. We will use SerpApi, so grab an API key.
And for LLM, we will use Google Gemini Pro. So, get your API key from Google AI Studio. You can use any other LLM as well.
The workflow starts with the user sending the query to the crew. The researcher agent picks up the query and searches the web to gather resources regarding the query. The search results are passed to the analyst agent to analyze the information and prepare a report. Finally, the report is sent to the recommender agent to give well-rounded advice on whether to invest or not.
Building the Agent
Now, that you know the workflow, the next step is to code the agent. First, as with any Python project, create a virtual environment and install the necessary dependencies. We will need CrewAI, Langchain, Composio, and SerpApi.
Add Gemini API key and SerpApi key to a .env file.
Add the SerpApi to your Composio account.
Import the necessary modules.
Now initialize the language model.
Define tools for the agents.
Defining the Agent
The next step is to define the agents, with goals, and backstories. As mentioned earlier, there are three agents, a researcher, an analyst, and a recommender. We will define the agents using CrewAI.
Each agent has a defined role, goal, tools, and a backstory. This provides LLMs with extra information about the agent, which aids in grounding the responses of the LLM.
Defining Task and Kickoff the Process
Now, define the task for the analyst agent.
Putting it all together.
Once you execute the script, the agent workflow will kick start and you can see the logs in your terminal.
Conclusion
In this tutorial, you developed an AI investment analyst utilizing CrewAI, Gemini, and Composio. We initially implemented a basic web search tool. To enhance the agent's capabilities, consider integrating a tool like Yahoo Finance, which provides detailed financial data. Additionally, incorporating a code interpreter with the Yahoo Finance tool will enable the agent to conduct sophisticated data analysis and create visual representations. This expansion allows for a more diverse and robust analysis capability, adapting to various financial scenarios and data requirements.
For additional tutorials, explore Composio’s collection of example use cases.