Building a Multi AI-Agent for Stock Search and Analysis
Hafiz Muhammad Ahmed
AI Engineer | Build AI Agents and Workflow Automations using (n8n | LangGraph | Crew AI) | Pursuing MSc in AI | Develop AI Applications using (Next.js | FastAPI)
In the world of AI, the ability to combine tools and models to create specialized applications is a game changer. I developed a multi-agentic application that utilizes PhiData, Python, and the Groq AI model to cater to two essential tasks: real-time web searches and detailed stock recommendations and analysis. Let me take you a walk through of building a robust and intuitive AI-driven system.
The Idea Behind the Agents
Together, these agents form a team that can handle user queries.
The Tech Stack I Used:
Implementation
Step 1: Setting Up the Environment
# Create a virtual environment
python -m venv myenv
source myenv/bin/activate
# Install dependencies
requirements.txt file
phidata
python-dotenv
yfinance
packaging
duckduckgo-search
groq
pip install -r requirements.txt
领英推荐
Step 2: Configure Environment Variables
GROQ_API_KEY=your-groq-api-key
PHI_API_KEY=your-phi-api-key # you will get the phiData Api keys from there website
Step 3: Define the Agents
from phi.agent import Agent
from phi.model.groq import Groq
from phi.tools.duckduckgo import DuckDuckGo
from phi.tools.yfinance import YFinanceTools
web_search_agent = Agent(
name="web_search_agent",
model=Groq(id="llama3-groq-70b-8192-tool-use-preview"),
tools=[DuckDuckGo()],
instructions=['Always include sources'],
show_tools_calls=True,
markdown=True,
debug_mode=True
)
finance_agent = Agent(
name="Finance Agent",
model=Groq(id="llama3-groq-70b-8192-tool-use-preview"),
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)],
instructions=["Use tables to display data"],
show_tool_calls=True,
markdown=True
)
Step 4: Combine Agents into a Multi-Agent System
multi_agent = Agent(
name="Multi Agent",
team=[web_search_agent, finance_agent],
model=Groq(id="llama3-groq-70b-8192-tool-use-preview"),
instructions=["Use tables to display data"],
show_tool_calls=True,
markdown=True
)
multi_agent.print_response("Tell me about the stocks of Tesla and also tell me about the company", stream=True)
Output
Conclusion
This project showcases how combining multiple AI agents can create intelligent applications capable of handling intricate queries. Whether you're a data enthusiast or a developer, this architecture offers limitless potential for customization and expansion.
Supply Chain Practitioner | Gen AI Enthusiast | Lifelong Learner | Committed to Delivering Value
2 个月????????? ??????