-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Agent invoking model multiple times when tool calling #1664
Comments
I encountered a similar issue as well, hope someone can clear it up, thanks! @ysolanky @manthanguptaa |
@josephtrinh @bigpo I tried the code you shared with |
I encountered a similar issue as well, hope someone can clear it up, thanks! |
@manthanguptaa The main issue I would say is the agent invoking the model multiples times when tool calling. You can see from the attached log that the agent invoked the model again and again for the same url and added another url even when the tool has successfully scraped the content multiple times. This one run costed 250k token. At the moment, I avoided using tool calling when I need to search or scrape data. I do a lot of scraping and performing these tasks separately then sending over the content to the agent to process works 100% of the time while it a bit unpredictable and expensive for me going with agent tool calling. |
@josephtrinh would it be helpful if the agent stopped on tool call error? I.e. if that was configurable? |
I was trying to test out Crawl4ai with the sample code available at https://docs.phidata.com/tools/crawl4ai#crawl4ai. I have tried with both Deepseek and Mistral with pretty much the same result which, at the end, produced no result for me from the Agent. I did gave up 2 days ago and today I was watching "YourTechBud Codes" on Youtube talking about tool calling in Pydantic AI with a similar issue where the Agent invokes the model multiple time and that tends to happen with open source llm and not OPENAI and Sonnet. I went back to phidata and found "tool_call_limit" to which I set to 1 and everything finally works. Below is the error and it will keep on invoking the model to call the tool up to about 10 times before giving up. I'm not if the issue is the same as with Pydantic AI.
`from phi.agent import Agent
from phi.model.deepseek import DeepSeekChat
from phi.tools.crawl4ai_tools import Crawl4aiTools
import os
from dotenv import load_dotenv
load_dotenv()
DEEPSEEK_API_KEY = os.getenv('DEEPSEEK_API_KEY')
agent = Agent(
model=DeepSeekChat(
temperature=1.0,
api_key=DEEPSEEK_API_KEY,
),
tools=[Crawl4aiTools(max_length=None)],
# tool_call_limit=1,
instructions=[
"Always use tools to fulfil the user query.",
],
show_tool_calls=True
)
agent.print_response("Tell me about https://github.com/phidatahq/phidata.")
`
tool_call_limit not set
tool_call_limit=1
The issue fix for Pydantic AI
pydantic/pydantic-ai#142
The text was updated successfully, but these errors were encountered: