fix pydantic ai changes#1191
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR updates the codebase to align with changes in the PydanticAI library API, specifically addressing breaking changes in the tool execution interface and result object structure.
- Updates tool wrapping logic to work with the new
call_toolmethod instead of the deprecatedrunmethod - Changes result attribute access from
result.datatoresult.outputto match new API - Refactors tool name extraction logic to work with the new method signature
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| examples/slackbot/src/slackbot/wrap.py | Updates tool wrapping to use AbstractToolset and call_tool method, refactors tool name extraction |
| examples/slackbot/src/slackbot/research_agent.py | Changes result attribute from data to output |
| examples/slackbot/src/slackbot/api.py | Changes result attribute from data to output |
| tool_name = kwargs.get("name", "Unknown Tool") | ||
| if not tool_name or tool_name == "Unknown Tool": | ||
| if len(args) > 1: | ||
| tool_name = args[1] | ||
|
|
There was a problem hiding this comment.
The condition checks if tool_name equals "Unknown Tool" but the default value is set to "Unknown Tool" on line 76. This means the condition will always be true when no name is found in kwargs, making the args[1] fallback unreachable when tool_name is "Unknown Tool".
| tool_name = kwargs.get("name", "Unknown Tool") | |
| if not tool_name or tool_name == "Unknown Tool": | |
| if len(args) > 1: | |
| tool_name = args[1] | |
| if "name" in kwargs: | |
| tool_name = kwargs["name"] | |
| elif len(args) > 1: | |
| tool_name = args[1] | |
| else: | |
| tool_name = "Unknown Tool" |
| # The tool name is either in kwargs['name'] or args[1] | ||
| tool_name = kwargs.get("name", "Unknown Tool") | ||
| if not tool_name or tool_name == "Unknown Tool": | ||
| if len(args) > 1: |
There was a problem hiding this comment.
Accessing args[1] without verifying it exists or has the expected type could cause an IndexError or AttributeError. The code should validate that args[1] is a string before assignment.
| if len(args) > 1: | |
| if len(args) > 1 and isinstance(args[1], str): |
No description provided.