Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi agent framework not working as expected , issue with yfinance lib as well internally #1700

Open
GauravKasat opened this issue Jan 5, 2025 · 9 comments

Comments

@GauravKasat
Copy link

GauravKasat commented Jan 5, 2025

I am using yfinance agent alone using below code .

from phi.agent import Agent
from phi.tools.yfinance import YFinanceTools

agent = Agent(
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, stock_fundamentals=True)],
show_tool_calls=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."],
)
agent.print_response("Share the AAPL stock price and analyst recommendations", markdown=True)

i am getting correct prices which is
Screenshot 2025-01-05 at 5 31 20 PM

But when i am using agentic workflow adding web search as well , its fetching wrong prices. I suspect there is no clear distinction by multiagent (master agent) which agent should be used to fetch the prices and we are getting wrong prices.

Multi agent code
"""
from phi.agent import Agent
from phi.model.groq import Groq
from phi.tools.yfinance import YFinanceTools
from phi.tools.duckduckgo import DuckDuckGo
import phi.api
from phi.playground import Playground, serve_playground_app
import yfinance as yf
#web agent
web_agent = Agent(
name="Web Search agent",
role="Search the web for the required information",
model=Groq(
id="llama3-8b-8192",
),
tools=[DuckDuckGo()],
instructions=[""" You can use the DuckDuckGo tool to search the web. Always include the Sources in your response"""],
show_tool_calls=True,
markdown=True
)

def yfintool(symbol):
stockz = yf.Ticker(symbol)
return stockz.info['currentPrice']

yfinance agent

yfinance_agent = Agent(
name="YFinance agent",
role="Get the financial data for the required information",
model=Groq(id="llama3-8b-8192"),
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, stock_fundamentals=True)],
show_tool_calls=True,
description="You are an investment analyst that researches stock prices, analyst recommendations, and stock fundamentals.",
instructions=["Format your response in markdown and use tables to display data where possible."],
markdown=True
)

multi_agent = Agent(
agents=[web_agent,yfinance_agent],
model=Groq(id="llama3-8b-8192"),
instructions=[ """You can use the DuckDuckGo tool to search the web. Always include the Sources in your response""",
"""Format your response in markdown and use tables to display data where possible"""],
show_tool_calls=True,
markdown=True
)

multi_agent.print_response("What is the current market price for AAPL? Also Share the analyst recommendations",stream=True)
"""

Has anyone else encountered this?
Screenshot 2025-01-05 at 5 34 09 PM

@mahikshith
Copy link

@GauravKasat , the problem is with your prompt / instruction under multi_agent .

First you have created duckduckgo web agent to get information from web via an instruction and then yfinance to get close to accurate information.

But the real problem starts when you created a multi-agent which involves both the above agents and gave a very specific instruction to use the duckduckgo tool again. When creating a multi-agents you need to give a broad / global instruction rather than tool specific instruction. The moment you instructed multi-agent to use duckduckgo it prioritizes information from duckduckgo than yfinance and the search result from duckduckgo may not have updated information.

problem 2 : agents=[web_agent,yfinance_agent] the order matters a lot gaurav.

Probable solution : Change the prompt / instruction in multi-agent as follows : "Use the agents and get the real time information of APPL {specify date} " , use your best knowledge gaurav and never ever prefer one tool over other while creating a multi-agents which follows a linear path.

So change the instruction and try it again.

@GauravKasat
Copy link
Author

@mahikshith I have changed the order as well as specifically written to use yfin agent to fetch current prices and for normal search use web agent. Yet its still failing to fetch correct price.
Adding the code below
`from phi.agent import Agent
from phi.model.groq import Groq
from phi.tools.yfinance import YFinanceTools
from phi.tools.duckduckgo import DuckDuckGo
import phi.api
PHI_API_KEY='phi-o56OdQ2EFE5LWGvkkByBr6BUQ3Fmc-4wRlbJDWr-1sA'
phi.api = PHI_API_KEY
from phi.playground import Playground, serve_playground_app
import yfinance as yf
#web agent
web_agent = Agent(
name="Web Search agent",
role="Search the web for the required information",
model=Groq(
id="llama3-8b-8192",
api_key="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",
),
tools=[DuckDuckGo()],
instructions=[""" You can use the DuckDuckGo tool to search the web. Always include the Sources in your response"""],
show_tool_calls=True,
markdown=True
)

def yfintool(symbol):
stockz = yf.Ticker(symbol)
return stockz.info['currentPrice']

yfinance agent

yfinance_agent = Agent(
name="YFinance agent",
role="Get the financial data for the required information",
model=Groq(id="llama3-8b-8192"),
tools=[yfintool],
show_tool_calls=True,
description="You are an investment analyst that researches stock prices, analyst recommendations, and stock fundamentals.",
instructions=["Format your response in markdown and use tables to display data where possible."],
markdown=True
)

multi_agent = Agent(
agents=[yfinance_agent,web_agent],
description="Fetch the live current prices using yfinance agent and for normal searches use websearch agent",
model=Groq(id="llama3-8b-8192"),
instructions=[ """Always include the Sources in your response""",
"""Format your response in markdown and use tables to display data where possible"""],
show_tool_calls=True,
markdown=True
)

multi_agent.print_response("What is the current market price for AAPL on 5 jan 2025? Also Share the analyst recommendations",stream=True)`

@GauravKasat
Copy link
Author

Screenshot 2025-01-05 at 10 23 26 PM

@GauravKasat
Copy link
Author

Tried this as well . Getting wrong response again

from phi.agent import Agent
from phi.model.groq import Groq
from phi.tools.yfinance import YFinanceTools
from phi.tools.duckduckgo import DuckDuckGo
import phi.api
PHI_API_KEY='phi-o56OdQ2EFE5LWGvkkByBr6BUQ3Fmc-4wRlbJDWr-1sA'
phi.api = PHI_API_KEY
from phi.playground import Playground, serve_playground_app
import yfinance as yf
#web agent
web_agent = Agent(
name="Web Search agent",
role="Search the web for the required information",
model=Groq(
id="llama3-8b-8192"
),
tools=[DuckDuckGo()],
instructions=[""" You can use the DuckDuckGo tool to search the web. Always include the Sources in your response"""],
show_tool_calls=True,
markdown=True
)

def yfintool(symbol):
stockz = yf.Ticker(symbol)
return stockz.info['currentPrice']

yfinance agent

yfinance_agent = Agent(
name="YFinance agent",
role="Get the financial data for the required information",
model=Groq(id="llama3-8b-8192"),
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, stock_fundamentals=True)],
show_tool_calls=True,
description="You are an investment analyst that researches stock prices, analyst recommendations, and stock fundamentals.",
instructions=["Format your response in markdown and use tables to display data where possible."],
markdown=True
)

multi_agent = Agent(
agents=[yfinance_agent,web_agent],
description="Use the agents and get the real time information of Stock provided on 1/5/2025",
model=Groq(id="llama3-8b-8192"),
instructions=[ """Always include the Sources in your response""",
"""Format your response in markdown and use tables to display data where possible"""],
show_tool_calls=True,
markdown=True
)

multi_agent.print_response("What is the current market price for AAPL on 5 jan 2025? Also Share the analyst recommendations",stream=True)
Screenshot 2025-01-05 at 10 31 17 PM

@ysolanky
Copy link
Contributor

ysolanky commented Jan 6, 2025

Hello @GauravKasat !

@mahikshith is right. For an Agent team, please provide very explicit instructions for the best result.

Additionally, Llama 3 8b is not the best model for function calling. Please consider using models like GPT 4o, Sonnet 3.5 or Gemini 2.0 for consistent function calling

@GauravKasat
Copy link
Author

Hello @ysolanky I have tried using multiple explicit instruction and various prompts as well. Also changed the model to gpt4o. Not gettiing the results i want. Could you try the same thing once or maybe give some prompt for multi agent which you think would work , i have tried multiple prompts . i am not getting the results which are correct.

@mahikshith
Copy link

@GauravKasat since you are already using yfinance to get accurate results . I guess there is no point in using duckduckgo inside the multi agent , you could have simply used yfinance as a agent. If you still want to use multi-agent probably try with tavilly as a web-search agent

@GauravKasat
Copy link
Author

Even i am just using yfinance aget only , its not fetching correct results . @mahikshith can you also try once

@GauravKasat
Copy link
Author

GauravKasat commented Jan 10, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants