Models API Reference¶
Bases: _StrictModel
A multi-turn evaluation transcript.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier used as the pytest test name. |
turns |
list[Turn]
|
Ordered list of turns. |
threshold |
float
|
Fraction of runs that must pass (0.0-1.0). |
runs |
int
|
Number of times to execute this transcript. |
tags |
list[str]
|
Optional quality-gate tags (e.g. ["gate:booking"]). |
Source code in src/pytest_agent_eval/models.py
Bases: _StrictModel
A single turn in a transcript.
Attributes:
| Name | Type | Description |
|---|---|---|
user |
str
|
The user message (also used as the transcript when |
audio |
str | Path | None
|
Optional path to a WAV file for voice adapters. Resolved relative to the YAML file's directory when loaded from YAML. |
expect |
Expect
|
Expectations for the agent's reply. |
Source code in src/pytest_agent_eval/models.py
Bases: _StrictModel
Expectations for a single transcript turn.
Attributes:
| Name | Type | Description |
|---|---|---|
evaluators |
list[Evaluator]
|
Programmatic evaluators (Python API). Excluded from serialisation and from the JSON schema, since they are Python objects. |
judge |
JudgeConfig | None
|
YAML-defined judge config. |
tool_calls_include |
list[str]
|
Tool names that must appear in tool_calls. |
tool_calls_exclude |
list[str]
|
Tool names that must NOT appear in tool_calls. |
tool_calls_ordered |
bool
|
If True, tool_calls_include must appear in the given order. |
tool_calls_args |
list[ToolCallArgsConfig]
|
Assertions on the arguments of specific tool calls. |
reply_contains_any |
list[str]
|
Reply must contain at least one of these strings. |
reply_contains_all |
list[str]
|
Reply must contain all of these strings. |
reply_matches_any |
list[RegexPattern]
|
Reply must match at least one of these regex patterns. |
reply_matches_all |
list[RegexPattern]
|
Reply must match all of these regex patterns. |
Source code in src/pytest_agent_eval/models.py
Bases: str
A tool-call name that optionally carries the arguments it was invoked with.
Subclasses str so name-based checks keep working unchanged: "book_slot"
in ctx.tool_calls, equality against plain strings, and hand-rolled agents
returning list[str] (the runner normalises those to ToolCall with
args=None).
Example
Source code in src/pytest_agent_eval/models.py
name: str
property
¶
The tool name (the string value itself).
__new__(name: str, args: ToolArgs | None = None) -> ToolCall
¶
Create a ToolCall from a tool name and optional captured arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The tool name. |
required |
args
|
ToolArgs | None
|
The arguments the tool was called with, or None when the adapter could not capture them. |
None
|
Source code in src/pytest_agent_eval/models.py
Bases: NamedTuple
What one turn of an agent produced.
A NamedTuple, so reply, tool_calls = await agent(history) keeps working
unchanged while the fields also have names. Adapters return this; the agent
contract stays the wider plain tuple, so a hand-written
async def agent(history) -> tuple[str, list[str]] remains valid.
Attributes:
| Name | Type | Description |
|---|---|---|
reply |
str
|
The agent's text reply for this turn. |
tool_calls |
ToolCalls
|
Tools called during the turn. Plain strings are accepted; the
runner normalises them to |
Source code in src/pytest_agent_eval/models.py
Bases: Mapping[str, str]
One conversation message in OpenAI format.
A dataclass, so our own code reads msg.content rather than indexing a dict by
string key. Also a Mapping, because the history handed to user-written agents
and evaluators has always been subscriptable and must stay so: history[-1]["content"]
is what every example in the docs used to do, and what agents in the wild still do. The
docs now teach .content; the subscript is a compatibility guarantee, not a
deprecation, and tests/test_message.py exists to keep it honest.
eq=False lets Mapping.__eq__ take over, so a Message compares equal to the
plain dict it replaces — which is what makes the swap invisible to callers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
role
|
Role
|
Who produced the message. |
required |
content
|
str
|
The message text. |
required |
audio
|
str | None
|
WAV path a voice adapter should stream. Plugin-internal — never sent to
a text API, which is why |
None
|
Source code in src/pytest_agent_eval/models.py
__getitem__(key: str) -> str
¶
Return a field by name, raising KeyError when it is unset.
Source code in src/pytest_agent_eval/models.py
__iter__() -> Iterator[str]
¶
Yield the keys that are actually set, skipping an absent audio path.
__len__() -> int
¶
to_dict(*, include_audio: bool = False) -> dict[str, str]
¶
Plain dict for an SDK boundary; drops the plugin-internal audio key by default.
Every serialisation boundary has to say this out loud, because json.dumps on
a Message raises. That is deliberate: it is what stops the internal shape from
leaking into a provider request.
Source code in src/pytest_agent_eval/models.py
Bases: _StrictModel
One tool-argument assertion in a YAML transcript turn.
Attributes:
| Name | Type | Description |
|---|---|---|
tool |
str
|
Name of the tool whose arguments to check. |
args |
JsonMapping | None
|
Expected arguments for the deterministic check, or None. |
mode |
ToolCallArgsMode
|
"subset" or "exact" (deterministic check only). |
judge |
JudgeConfig | None
|
Optional LLM-judge config for the arguments. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither args nor judge is provided. |
Source code in src/pytest_agent_eval/models.py
Context passed to every evaluator for a turn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
str
|
The user message for this turn. |
required |
reply
|
str
|
The agent's reply. |
required |
tool_calls
|
list[ToolCall]
|
Tools called during the turn. Each entry is a ToolCall
(str-compatible); |
required |
history
|
History
|
Full conversation history, up to but not including the assistant
reply for this turn. Each entry is a :class: |
required |
Source code in src/pytest_agent_eval/models.py
Aggregated result across all runs of a transcript.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
passed
|
bool
|
True if score >= threshold. |
required |
score
|
float
|
Fraction of runs that passed (0.0-1.0). |
required |
threshold
|
float
|
Required pass fraction. |
required |
runs
|
list[RunResult]
|
Individual run results. |
required |