-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add tool_calls_limit to UsageLimits and tool_calls to RunUsage
#2633
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
Conversation
PR Change SummaryImplemented usage limits for tool calls in the Pydantic AI framework, enhancing control over tool execution during runs.
Modified Files
How can I customize these reviews?Check out the Hyperlint AI Reviewer docs for more information on how to customize the review. If you just want to ignore it on this PR, you can add the Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add |
cc5f0a3 to
2da0bb2
Compare
|
Side note: I had to update the uv lock, since the pre-commit format hook would otherwise fail due to the altered lock. |
8f7c248 to
2569f4a
Compare
2569f4a to
81a4aab
Compare
9dcc0fa to
5402c06
Compare
63041aa to
df30204
Compare
- Added `usage_limits` to `GraphRunContext` to manage usage constraints. - Introduced `tool_calls` attribute in `RunUsage` to track tool call counts. - Updated `UsageLimits` class to include `tool_calls_limit` and validation logic for tool calls. - Implemented a lock in `ToolManager` to ensure thread-safe usage limit checks during tool calls.
- Updated `agents.md` to clarify the inclusion of tool calls in usage limits. - Added examples demonstrating the use of `tool_calls_limit` in `agents.md` and `multi-agent-applications.md`. - Revised usage output examples across multiple documentation files to reflect the new `tool_calls` attribute. - Included a note in `tools.md` about limiting exact tool executions with `UsageLimits`.
- Modified assertions in multiple test files to include the new `tool_calls` attribute in `RunUsage`. - Added new test cases to validate tool call limits and ensure correct behavior when exceeding limits. - Updated existing tests to reflect changes in tool call tracking across different models and scenarios.
- Added a new test to verify that output tools do not increment the `tool_calls` metric.
…calls` usage metric - Adjusted the tool call counting mechanism to ensure that only successful tool invocations are counted towards the `tool_calls` metric. - Updated documentation in `tools.md` to clarify that output tools do not increment the `tool_calls` count. - Modified multiple test cases to reflect the correct counting of tool calls, including tests for failed tool calls and their impact on usage metrics.
- Updated docstrings in `RunContext`, `RunUsage`, and `UsageLimits` to specify that only successful tool calls are counted and to clarify the meaning of usage limits.
- Updated the `ToolManager` and related functions to incorporate `usage_limits` when handling tool calls. - Removed the `usage_limits` attribute from `RunContext` as it is now managed directly within the tool manager. - Ensured that usage limits are checked for non-output tool calls to maintain accurate tracking of tool usage.
9217bbd to
fba06eb
Compare
UsageLimitstool_calls_limit to UsageLimits and tool_calls to RunUsage
|
@tradeqvest Thanks Niko! |
Fixes Enforce usage limits by exact tool call count (not just request/turn count) #2593
Introduces a tool-call cap per run:
RunUsage.tool_calls(increments on successful tool execution).UsageLimits.tool_calls_limit; enforced before each invocation.Counting semantics:
Backward compatible: defaults to no limit (
None).