Welcome to the exciting world of Agentic AI! In this blog, we'll explore how to build your very first financial AI agent using the Phidata framework. This journey will take us through the setup, development, and deployment of an independent AI agent capable of analyzing financial data and providing insights.
Agentic AI represents a significant leap in AI development, allowing applications to operate autonomously and make informed decisions based on user queries. With frameworks like Phidata, creating these agents has become more accessible, even for those who may not have extensive programming backgrounds.
Phidata is an open-source framework designed to facilitate the development and monitoring of agentic systems. It allows developers to create multi-modal agents that can perform complex tasks and workflows. The framework supports various large language models (LLMs), enabling developers to choose the model that best fits their needs.
One of Phidata's standout features is its ability to integrate seamlessly with different AI models, including open-source options like Grok, Hugging Face, and more. This flexibility opens up a world of possibilities for building intelligent applications.
Before diving into the code, we need to set up our development environment. Here’s how to get started:
Create a Python Environment: Use the command line to create a virtual environment for your project. This helps keep your dependencies organized.
conda create -p venv python=3.12
Activate the Environment: Once the environment is created, activate it to start working within it.
conda activate venv
Create a Requirements File: Create a file named requirements.txt
to specify the libraries you will need. Here are some essential packages to include:
f-data
yfinance
duckduckgo-search
fastapi
uvicorn
Install Dependencies: Use pip to install the required libraries from your requirements.txt
.
pip install -r requirements.txt
With the environment set up, we can now proceed to write our financial agent.
The goal of our financial AI agent is to analyze stock data and provide recommendations based on user queries. This process involves creating multiple agents working together to achieve the desired outcome. Let's break it down step by step.
The first step is to create an agent that can search the web for financial information. This agent will utilize the DuckDuckGo search tool to gather relevant data.
from f.agent import Agent
from f.model import Grok
from f.tools import DuckDuckGo
web_search_agent = Agent(
name="Web Search Agent",
role="Search the web for financial information",
model=Grok(id="grok-70b"),
tools=[DuckDuckGo()],
instructions=["Always include sources in the response."],
show_tool_calls=True,
markdown=True
)
Next, we need a financial analysis agent that will interact with the Yahoo Finance API to fetch stock data and provide insights.
from f.tools import YFinance
finance_agent = Agent(
name="Finance AI Agent",
role="Analyze stock data and provide recommendations",
model=Grok(id="grok-70b"),
tools=[YFinance()],
instructions=["Use tables to display numerical data."],
show_tool_calls=True,
markdown=True
)
Now that we have both agents set up, we can create a multi-agent system that combines their functionalities. This allows the financial agent to leverage the web search agent's capabilities to gather information.
multi_agent = Agent(
name="Multi-Agent Financial AI",
team=[web_search_agent, finance_agent],
instructions=["Summarize analyst recommendations and share the latest news."],
show_tool_calls=True,
markdown=True
)
Finally, we can run the agent and test its functionality. We will create a simple query to see how it responds.
response = multi_agent.print_response("Summarize analyst recommendations for NVDA.")
print(response)
This setup allows the multi-agent system to gather and analyze data effectively, leveraging each agent's strengths.
To deploy our agent, we need to integrate it with the Phi Data platform. This involves creating a playground where users can interact with the agent in real-time.
from fastapi import FastAPI
from f.playground import Playground
app = FastAPI()
playground = Playground(agents=[multi_agent]).get_app()
if __name__ == "__main__":
playground.run(host="localhost", port=7777)
By running this FastAPI application, we create a user-friendly interface allowing users to interact seamlessly with our financial agent.
In this blog, we explored building a financial AI agent using the Phidata framework. We learned how to set up our environment, create individual agents, and combine them into a multi-agent system capable of analyzing stock data and providing insights.
Phidata's flexibility allows developers to create complex workflows easily, making it a powerful tool for anyone looking to delve into Agentic AI. As we continue to explore this field, the possibilities for creating intelligent applications are endless!
For those interested in further learning, I recommend checking out the Building Agentic AI Free Course | Krish C Naik to deepen your understanding of building agentic AI applications.
Feel free to connect with me on Linkedin for more updates and insights!
Join Roshni on Peerlist!
Join amazing folks like Roshni and thousands of other people in tech.
Create ProfileJoin with Roshni’s personal invite link.
0
3
0