Evaluation framework for Pydantic AI agents
Project description
pytest-assay is a framework for the evaluation of Pydantic AI agents. By adding the @pytest.mark.assay decorator to a test, you can run an assay resulting in a readout report which contains the evaluation. The assay compares the current agent responses against pre-recorded baseline responses, e.g. from the main branch. The implementation is using pytest hooks which capture Agent.run() responses inside the test. Below is a minimal example which evaluates the creativity of a search query generation. For a fully functional example see tests/test_plugin_integration.py.
def generate_evaluation_cases():
...
return Dataset(cases)
@pytest.mark.assay(
generator=generate_evaluation_cases,
evaluator=PairwiseEvaluator(
model="openai:gpt-4o",
criterion="Which of the two search queries shows more genuine curiosity and creativity?",
),
)
@pytest.mark.asyncio
async def test_query_generation(context: AssayContext):
agent = Agent(
model="openai:gpt-4o",
system_prompt="Generate a concise web search query for the given research topic.",
)
for case in context.dataset.cases:
async with agent:
result = await agent.run(user_prompt=f"Generate a search query for the following topic: <TOPIC>{case.inputs['topic']}</TOPIC>")
Both baseline responses and the final readout report are stored in the assays/ subfolder.
tests
├── assays
│ └── test_evaluation
│ ├── test_query_generation.json # Baseline data
│ └── test_query_generation.readout.json # Readout report
└── test_evaluation.py
The baseline data are generated in new_baseline mode, and the readout report is generated in default evaluate mode.
uv run pytest tests/test_evaluation.py --assay-mode=new_baseline # Generates baseline data test_query_generation.json
uv run pytest tests/test_evaluation.py --assay-mode=evaluate # Generates readout report test_query_generation.readout.json
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_assay-0.1.2.tar.gz.
File metadata
- Download URL: pytest_assay-0.1.2.tar.gz
- Upload date:
- Size: 1.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9be8e3af0bb25c514dc2ca129d2f1005215951b5e465d364ed242f599765940a
|
|
| MD5 |
450b7df2afe8db9f6ddbe29001273315
|
|
| BLAKE2b-256 |
9d114872665669898a97a7bc1553ce6bc7dc02cbea856066f0beb13be974461f
|
File details
Details for the file pytest_assay-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pytest_assay-0.1.2-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7788f2b332ad1f3f47882b457de6dd637fc3f774c41ec485d73904d4dfc7cc60
|
|
| MD5 |
4ca9b74456a2c6b3f077223f5f4a46ad
|
|
| BLAKE2b-256 |
96d65f0e7415c6302e918a0b70a97d3322d2913550006795506f1c119f67d7ae
|