Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pydantic_ai_slim/pydantic_ai/_tool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class ToolManager(Generic[AgentDepsT]):
"""The cached tools for this run step."""
failed_tools: set[str] = field(default_factory=set)
"""Names of tools that failed in this run step."""
default_max_retries: int = 1
"""Default number of times to retry a tool"""

@classmethod
@contextmanager
Expand Down Expand Up @@ -176,7 +178,7 @@ async def _call_tool(

return result
except (ValidationError, ModelRetry) as e:
max_retries = tool.max_retries if tool is not None else 1
max_retries = tool.max_retries if tool is not None else self.default_max_retries
current_retry = self.ctx.retries.get(name, 0)

if current_retry == max_retries:
Expand Down
2 changes: 1 addition & 1 deletion pydantic_ai_slim/pydantic_ai/agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ async def main():
output_toolset.max_retries = self._max_result_retries
output_toolset.output_validators = output_validators
toolset = self._get_toolset(output_toolset=output_toolset, additional_toolsets=toolsets)
tool_manager = ToolManager[AgentDepsT](toolset)
tool_manager = ToolManager[AgentDepsT](toolset, default_max_retries=self._max_tool_retries)

# Build the graph
graph = _agent_graph.build_agent_graph(self.name, self._deps_type, output_type_)
Expand Down