Skip to content

Commit 123b2e7

Browse files
committed
refactor: default usage_limits to None
1 parent 87dc6fd commit 123b2e7

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

pydantic_ai_slim/pydantic_ai/_tool_manager.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,13 @@ async def handle_call(
8080
allow_partial: Whether to allow partial validation of the tool arguments.
8181
wrap_validation_errors: Whether to wrap validation errors in a retry prompt part.
8282
usage_limits: Optional usage limits to check before executing tools.
83-
count_tool_usage: Whether to count this tool call in usage metrics.
8483
"""
8584
if self.tools is None or self.ctx is None:
8685
raise ValueError('ToolManager has not been prepared for a run step yet') # pragma: no cover
8786

8887
if (tool := self.tools.get(call.tool_name)) and tool.tool_def.kind == 'output':
8988
# Output tool calls are not traced and not counted
90-
return await self._call_tool(
91-
call, allow_partial, wrap_validation_errors, usage_limits, count_tool_usage=False
92-
)
89+
return await self._call_tool(call, allow_partial, wrap_validation_errors, count_tool_usage=False)
9390
else:
9491
return await self._call_tool_traced(
9592
call,
@@ -105,7 +102,7 @@ async def _call_tool(
105102
call: ToolCallPart,
106103
allow_partial: bool,
107104
wrap_validation_errors: bool,
108-
usage_limits: UsageLimits | None,
105+
usage_limits: UsageLimits | None = None,
109106
count_tool_usage: bool = True,
110107
) -> Any:
111108
if self.tools is None or self.ctx is None:
@@ -138,7 +135,7 @@ async def _call_tool(
138135
else:
139136
args_dict = validator.validate_python(call.args or {}, allow_partial=pyd_allow_partial)
140137

141-
if usage_limits is not None:
138+
if usage_limits is not None and count_tool_usage:
142139
usage_limits.check_before_tool_call(self.ctx.usage)
143140

144141
result = await self.toolset.call_tool(name, args_dict, ctx, tool)

0 commit comments

Comments
 (0)