Skip to content

100+ AI Agents, Agent Skills and RAG Apps - Free and Open Source.

Update investment_agent.py

Madhu Shantan590a0d217c76
diff --git a/ai_agent_tutorials/ai_investment_agent/investment_agent.py b/ai_agent_tutorials/ai_investment_agent/investment_agent.py
index 62315083..699c2cc5 100644
--- a/ai_agent_tutorials/ai_investment_agent/investment_agent.py
+++ b/ai_agent_tutorials/ai_investment_agent/investment_agent.py
@@ -1,31 +1,34 @@
-# Import the required libraries
import streamlit as st
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.yfinance import YFinanceTools
-# Set up the Streamlit app
st.title("AI Investment Agent 📈🤖")
st.caption("This app allows you to compare the performance of two stocks and generate detailed reports.")
-# Get OpenAI API key from user
openai_api_key = st.text_input("OpenAI API Key", type="password")
if openai_api_key:
- # Create an instance of the Agent
- agent = Agent(
- llm=OpenAIChat(model="gpt-4o", api_key=openai_api_key),
- tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)],
+ assistant = Agent(
+ model=OpenAIChat(id="gpt-4o", api_key=openai_api_key),
+ tools=[
+ YFinanceTools(stock_price=True, analyst_recommendations=True, stock_fundamentals=True)
+ ],
show_tool_calls=True,
- markdown=True
+ description="You are an investment analyst that researches stock prices, analyst recommendations, and stock fundamentals.",
+ instructions=[
+ "Format your response using markdown and use tables to display data where possible."
+ ],
)
- # Input fields for the stocks to compare
- stock1 = st.text_input("Enter the first stock symbol")
- stock2 = st.text_input("Enter the second stock symbol")
+ col1, col2 = st.columns(2)
+ with col1:
+ stock1 = st.text_input("Enter first stock symbol (e.g. AAPL)")
+ with col2:
+ stock2 = st.text_input("Enter second stock symbol (e.g. MSFT)")
if stock1 and stock2:
- # Get the response from the Agent
- query = f"Compare {stock1} to {stock2}. Use every tool you have."
- response = agent.run(query, stream=False)
- st.write(response.content)
\ No newline at end of file
+ with st.spinner(f"Analyzing {stock1} and {stock2}..."):
+ query = f"Compare both the stocks - {stock1} and {stock2} and make a detailed report for an investment trying to invest and compare these stocks"
+ response = assistant.run(query, stream=False)
+ st.markdown(response.content)