Skip to content

Commit a212829

Browse files
committed
fix pydantic ai changes
1 parent e5e609c commit a212829

3 files changed

Lines changed: 14 additions & 15 deletions

File tree

examples/slackbot/src/slackbot/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ async def handle_message(payload: SlackPayload, db: Database):
149149
conversation.extend(result.new_messages())
150150
assert event.channel is not None, "No channel found"
151151
await task(post_slack_message)(
152-
message=result.data,
152+
message=result.output,
153153
channel_id=event.channel,
154154
thread_ts=thread_ts,
155155
)

examples/slackbot/src/slackbot/research_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ async def research_topic(
102102
agent = create_research_agent(model)
103103
result = await agent.run(user_prompt=question, deps=context)
104104

105-
return result.data
105+
return result.output
106106

107107

108108
def research_prefect_topic(question: str, topic: str, version: str = "3.x") -> str:

examples/slackbot/src/slackbot/wrap.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from prefect import tags as prefect_tags
99
from prefect import task
10-
from pydantic_ai.tools import Tool
1110

1211
T = TypeVar("T")
1312

@@ -72,15 +71,12 @@ def prefect_wrapped_function(
7271
@wraps(func)
7372
async def wrapper(*args, **kwargs) -> T:
7473
if _progress := _progress_message.get():
75-
tool_name = "Unknown Tool"
76-
if args and hasattr(args[0], "name"):
77-
tool_name = args[0].name
78-
elif (
79-
args
80-
and hasattr(args[0], "function")
81-
and hasattr(args[0].function, "__name__")
82-
):
83-
tool_name = args[0].function.__name__
74+
# For call_tool method: self, name, tool_args, ctx, tool
75+
# The tool name is either in kwargs['name'] or args[1]
76+
tool_name = kwargs.get("name", "Unknown Tool")
77+
if not tool_name or tool_name == "Unknown Tool":
78+
if len(args) > 1:
79+
tool_name = args[1]
8480

8581
# Update tool usage counts
8682
counts = _tool_usage_counts.get()
@@ -129,8 +125,8 @@ class WatchToolCalls(DecorateMethodContext):
129125

130126
def __init__(
131127
self,
132-
patch_cls: type = Tool,
133-
patch_method_name: str = "run",
128+
patch_cls: type | None = None,
129+
patch_method_name: str = "call_tool",
134130
tags: set[str] | None = None,
135131
settings: dict[str, Any] | None = None,
136132
):
@@ -139,8 +135,11 @@ def __init__(
139135
tags: Prefect tags to apply to the flow.
140136
flow_kwargs: Keyword arguments to pass to the flow.
141137
"""
138+
# Import here to avoid circular imports
139+
from pydantic_ai.toolsets.abstract import AbstractToolset
140+
142141
super().__init__(
143-
patch_cls=patch_cls,
142+
patch_cls=patch_cls or AbstractToolset,
144143
patch_method_name=patch_method_name,
145144
decorator=prefect_wrapped_function,
146145
tags=tags,

0 commit comments

Comments
 (0)