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

Agent invoking model multiple times when tool calling #1664

Open
josephtrinh opened this issue Dec 30, 2024 · 2 comments
Open

Agent invoking model multiple times when tool calling #1664

josephtrinh opened this issue Dec 30, 2024 · 2 comments

Comments

@josephtrinh
Copy link

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

image

tool_call_limit=1

image

The issue fix for Pydantic AI

pydantic/pydantic-ai#142

@bigpo
Copy link

bigpo commented Dec 31, 2024

I encountered a similar issue as well, hope someone can clear it up, thanks! @ysolanky @manthanguptaa

@manthanguptaa
Copy link
Contributor

@josephtrinh @bigpo I tried the code you shared with tool_call_limit=1 and without it. I got the correct result in both scenarios. The first example you shared looks like the crawling is unsuccessful and the agent is retrying until it's successful and in the 2nd situation it succeeded in the first try. You can try to add debug_mode=True and see the tool calls and how its working under the hood

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