@@ -80,13 +80,16 @@ 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.
8384 """
8485 if self .tools is None or self .ctx is None :
8586 raise ValueError ('ToolManager has not been prepared for a run step yet' ) # pragma: no cover
8687
8788 if (tool := self .tools .get (call .tool_name )) and tool .tool_def .kind == 'output' :
88- # Output tool calls are not traced
89- return await self ._call_tool (call , allow_partial , wrap_validation_errors )
89+ # 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+ )
9093 else :
9194 return await self ._call_tool_traced (
9295 call ,
@@ -102,7 +105,8 @@ async def _call_tool(
102105 call : ToolCallPart ,
103106 allow_partial : bool ,
104107 wrap_validation_errors : bool ,
105- usage_limits : UsageLimits | None = None ,
108+ usage_limits : UsageLimits | None ,
109+ count_tool_usage : bool = True ,
106110 ) -> Any :
107111 if self .tools is None or self .ctx is None :
108112 raise ValueError ('ToolManager has not been prepared for a run step yet' ) # pragma: no cover
@@ -139,7 +143,7 @@ async def _call_tool(
139143
140144 result = await self .toolset .call_tool (name , args_dict , ctx , tool )
141145
142- if usage_limits is not None :
146+ if count_tool_usage :
143147 self .ctx .usage .tool_calls += 1
144148
145149 return result
0 commit comments