Skip to main content

Evaluation framework for Pydantic AI agents

Project description


codecov Build Python Version Ask DeepWiki PyPI License

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.

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

For full examples, please run the integration tests in tests/test_plugin_integration.py.

uv run pytest --log-cli-level=DEBUG tests/test_plugin_integration.py | grep pytest_assay

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

pytest_assay-0.1.3.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_assay-0.1.3-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file pytest_assay-0.1.3.tar.gz.

File metadata

  • Download URL: pytest_assay-0.1.3.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","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

Hashes for pytest_assay-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a364a108bd43656a9e0ac5a1ed371f3a388bffc6b072c82287de8846be191c12
MD5 64a80b8a2f791b4f9c05aa1b59ff5eb3
BLAKE2b-256 1b73e6a6b203c262f4b05d1ec7b39c56080c351442129a06bb6c444baec79bb8

See more details on using hashes here.

File details

Details for the file pytest_assay-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pytest_assay-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","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

Hashes for pytest_assay-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2577c399394fca3d880089f1fe73d732e35ff6d8927b348a126a01477b5fe59a
MD5 ef9681fdcb1d5ee28d2ce0fd3335cea5
BLAKE2b-256 b761560554e91c1d4e4477315e4058bf4d7b4ee7fe0e0c1764552b70177121bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page