pydantic_ai.models.function
A model controlled by a local function.
FunctionModel is similar to TestModel, but allows greater control over the model's behavior.
It's primary use case for more advanced unit testing than is possible with TestModel.
FunctionModel
dataclass
Bases: Model
A model controlled by a local function.
Apart from __init__, all methods are private or match those of the base class.
__init__
__init__(function: FunctionDef) -> None
__init__(*, stream_function: StreamFunctionDef) -> None
__init__(
function: FunctionDef,
*,
stream_function: StreamFunctionDef
) -> None
__init__(
function: FunctionDef | None = None,
*,
stream_function: StreamFunctionDef | None = None
)
Initialize a FunctionModel.
Either function or stream_function must be provided, providing both is allowed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function
|
FunctionDef | None
|
The function to call for non-streamed requests. |
None
|
stream_function
|
StreamFunctionDef | None
|
The function to call for streamed requests. |
None
|
AgentInfo
dataclass
Information about an agent.
This is passed as the second to functions.
retrievers
instance-attribute
retrievers: Mapping[str, AbstractToolDefinition]
The retrievers available on this agent.
allow_text_result
instance-attribute
allow_text_result: bool
Whether a plain text result is allowed.
result_tools
instance-attribute
result_tools: list[AbstractToolDefinition] | None
The tools that can called as the final result of the run.
DeltaToolCall
dataclass
Incremental change to a tool call.
Used to describe a chunk when streaming structured responses.
DeltaToolCalls
module-attribute
DeltaToolCalls: TypeAlias = dict[int, DeltaToolCall]
A mapping of tool call IDs to incremental changes.
FunctionDef
module-attribute
A function used to generate a non-streamed response.
StreamFunctionDef
module-attribute
StreamFunctionDef: TypeAlias = Callable[
[list[Message], AgentInfo],
Union[Iterable[str], Iterable[DeltaToolCalls]],
]
A function used to generate a streamed response.