|
1 | 1 | from __future__ import annotations as _annotations
|
2 | 2 |
|
3 | 3 | import inspect
|
4 |
| -from collections.abc import Awaitable, Mapping, Sequence |
| 4 | +from collections.abc import Awaitable |
5 | 5 | from dataclasses import dataclass, field
|
6 | 6 | from typing import TYPE_CHECKING, Any, Callable, Generic, TypeVar, Union, cast
|
7 | 7 |
|
8 | 8 | from pydantic import ValidationError
|
9 | 9 | from pydantic_core import SchemaValidator
|
10 |
| -from typing_extensions import Concatenate, ParamSpec, TypeAlias, final |
| 10 | +from typing_extensions import Concatenate, ParamSpec, final |
11 | 11 |
|
12 | 12 | from . import _pydantic, _utils, messages
|
13 | 13 | from .exceptions import ModelRetry, UnexpectedModelBehavior
|
|
23 | 23 | 'RunContext',
|
24 | 24 | 'ResultValidatorFunc',
|
25 | 25 | 'SystemPromptFunc',
|
26 |
| - 'ToolReturnValue', |
27 | 26 | 'ToolFuncContext',
|
28 | 27 | 'ToolFuncPlain',
|
29 | 28 | 'ToolFuncEither',
|
30 | 29 | 'ToolParams',
|
31 |
| - 'JsonData', |
32 | 30 | 'Tool',
|
33 | 31 | )
|
34 | 32 |
|
@@ -75,17 +73,12 @@ class RunContext(Generic[AgentDeps]):
|
75 | 73 | Usage `ResultValidator[AgentDeps, ResultData]`.
|
76 | 74 | """
|
77 | 75 |
|
78 |
| -JsonData: TypeAlias = 'None | str | int | float | Sequence[JsonData] | Mapping[str, JsonData]' |
79 |
| -"""Type representing any JSON data.""" |
80 |
| - |
81 |
| -ToolReturnValue = Union[JsonData, Awaitable[JsonData]] |
82 |
| -"""Return value of a tool function.""" |
83 |
| -ToolFuncContext = Callable[Concatenate[RunContext[AgentDeps], ToolParams], ToolReturnValue] |
| 76 | +ToolFuncContext = Callable[Concatenate[RunContext[AgentDeps], ToolParams], Any] |
84 | 77 | """A tool function that takes `RunContext` as the first argument.
|
85 | 78 |
|
86 | 79 | Usage `ToolContextFunc[AgentDeps, ToolParams]`.
|
87 | 80 | """
|
88 |
| -ToolFuncPlain = Callable[ToolParams, ToolReturnValue] |
| 81 | +ToolFuncPlain = Callable[ToolParams, Any] |
89 | 82 | """A tool function that does not take `RunContext` as the first argument.
|
90 | 83 |
|
91 | 84 | Usage `ToolPlainFunc[ToolParams]`.
|
@@ -146,8 +139,8 @@ async def my_tool(ctx: RunContext[int], x: int, y: int) -> str:
|
146 | 139 | function: The Python function to call as the tool.
|
147 | 140 | takes_ctx: Whether the function takes a [`RunContext`][pydantic_ai.tools.RunContext] first argument.
|
148 | 141 | max_retries: Maximum number of retries allowed for this tool, set to the agent default if `None`.
|
149 |
| - name: Name of the tool, inferred from the function if left blank. |
150 |
| - description: Description of the tool, inferred from the function if left blank. |
| 142 | + name: Name of the tool, inferred from the function if `None`. |
| 143 | + description: Description of the tool, inferred from the function if `None`. |
151 | 144 | """
|
152 | 145 | f = _pydantic.function_schema(function, takes_ctx)
|
153 | 146 | self.function = function
|
|
0 commit comments