-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: enforce tool call limit enforcement for parallel tool calls #2978
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
base: main
Are you sure you want to change the base?
Conversation
- Removed the unused `parts` variable in `UserPromptNode`.
c0165b0
to
5280163
Compare
@tradeqvest Since we'll raise an error regardless, is it worth executing tool calls up to the limit, instead of just raising immediately? I was thinking we could do something like this: pydantic-ai/pydantic_ai_slim/pydantic_ai/_agent_graph.py Lines 476 to 484 in bfcccba
Where we optimistically increment a copied version of the usage, and check the usage limit against that. |
@DouweM It would definitely be simpler, yet I was thinking that the tool output up until the UsageLimit violation could still be of value, captured and further processed. Let me know what you think. |
@tradeqvest I think it'd be misleading if those results never get sent back to the model to use, and the user will think their action failed even though some tools (with side effects) may have in fact been executed. If we had a way to, instead of failing hard, tell the model "this call was not executed because you hit the limit" for the calls over the limit, executing the earlier ones makes sense, but until we have such a mode I'd rather not run the tools at all. |
Fix parallel tool call limit enforcement
Problem
The
tool_calls_limit
inUsageLimits
was not properly enforced for parallel tool execution. When multiple tools were called in parallel, all tools would start executing before the limit was checked, allowing the limit to be exceeded before raisingUsageLimitExceeded
.For example, if
tool_calls_limit=6
and the model returned 8 parallel tool calls, all 8 tools would start executing before the error was raised.Solution
This PR modifies the parallel tool execution logic in
_agent_graph.py
to enforce the limit before starting tool tasks:UsageLimitExceeded
after the allowed tools complete if more were requested