Building a Multi AI-Agent for Stock Search and Analysis

Building a Multi AI-Agent for Stock Search and Analysis

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

  1. Agent 1: Conducts live web searches and retrieves relevant information
  2. Agent 2: Fetches stock-related data such as prices, company information, recommendations, and analysis.

Together, these agents form a team that can handle user queries.


The Tech Stack I Used:

  • PhiData: For agent orchestration.
  • Groq AI Model: A 70-billion parameter model optimized for tool usage.
  • DuckDuckGo API: For seamless web searches.
  • YFinanceTools: To fetch and analyze financial data.
  • Python: Building the agent


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


Agent 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.



Khalid Baig

Supply Chain Practitioner | Gen AI Enthusiast | Lifelong Learner | Committed to Delivering Value

2 个月

????????? ??????

要查看或添加评论,请登录

Hafiz Muhammad Ahmed的更多文章

社区洞察

其他会员也浏览了