Metadata-Version: 2.5
Name: attest-ai
Version: 1.1.0-rc.3
Summary: Test framework for AI agents
Project-URL: Homepage, https://github.com/attest-framework/attest
Project-URL: Repository, https://github.com/attest-framework/attest
Project-URL: Issues, https://github.com/attest-framework/attest/issues
Project-URL: Documentation, https://github.com/attest-framework/attest#readme
Author: Attest Contributors
License-Expression: Apache-2.0
Keywords: agents,ai,evaluation,llm,testing
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.10
Requires-Dist: jsonschema>=4.20
Provides-Extra: all
Requires-Dist: anthropic>=0.30; extra == 'all'
Requires-Dist: crewai>=0.60; (python_version < '3.14') and extra == 'all'
Requires-Dist: google-adk>=1.0; extra == 'all'
Requires-Dist: google-genai>=1.0; extra == 'all'
Requires-Dist: langchain-core>=0.3; extra == 'all'
Requires-Dist: llama-index-core>=0.10.20; extra == 'all'
Requires-Dist: ollama>=0.4; extra == 'all'
Requires-Dist: openai>=1.30; extra == 'all'
Requires-Dist: opentelemetry-api>=1.20; extra == 'all'
Requires-Dist: opentelemetry-sdk>=1.20; extra == 'all'
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.30; extra == 'anthropic'
Provides-Extra: crewai
Requires-Dist: crewai>=0.60; (python_version < '3.14') and extra == 'crewai'
Provides-Extra: dev
Requires-Dist: anthropic==0.81.0; extra == 'dev'
Requires-Dist: build>=1.0; extra == 'dev'
Requires-Dist: google-genai==1.63.0; extra == 'dev'
Requires-Dist: junitparser>=3.2; extra == 'dev'
Requires-Dist: langchain-core==1.3.3; extra == 'dev'
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: ollama==0.6.1; extra == 'dev'
Requires-Dist: openai==1.83.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest-xdist>=3.5; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Requires-Dist: twine>=6.0; extra == 'dev'
Provides-Extra: gemini
Requires-Dist: google-genai>=1.0; extra == 'gemini'
Provides-Extra: google-adk
Requires-Dist: google-adk>=1.0; extra == 'google-adk'
Provides-Extra: integration-test
Requires-Dist: crewai>=0.60; (python_version < '3.14') and extra == 'integration-test'
Requires-Dist: google-adk>=1.0; extra == 'integration-test'
Requires-Dist: google-genai>=1.0; extra == 'integration-test'
Requires-Dist: langchain-core>=0.3; extra == 'integration-test'
Provides-Extra: langchain
Requires-Dist: langchain-core>=0.3; extra == 'langchain'
Provides-Extra: llamaindex
Requires-Dist: llama-index-core>=0.10.20; extra == 'llamaindex'
Provides-Extra: ollama
Requires-Dist: ollama>=0.4; extra == 'ollama'
Provides-Extra: openai
Requires-Dist: openai>=1.30; extra == 'openai'
Provides-Extra: otel
Requires-Dist: opentelemetry-api>=1.20; extra == 'otel'
Requires-Dist: opentelemetry-sdk>=1.20; extra == 'otel'
Description-Content-Type: text/markdown

# attest-ai

Test framework for AI agents. Deterministic assertions (schema validation, cost constraints, trace ordering, content matching) over agent execution traces.

## Install

```bash
uv add "attest-ai>=1.0.1" pytest
```

With LLM provider support:

```bash
uv add "attest-ai[openai]>=1.0.1"      # OpenAI
uv add "attest-ai[anthropic]>=1.0.1"   # Anthropic
uv add "attest-ai[gemini]>=1.0.1"      # Google Gemini
uv add "attest-ai[ollama]>=1.0.1"      # Ollama (local)
uv add "attest-ai[all]>=1.0.1"         # All providers
```

## Quick start

Save as `test_refund_agent.py`. The `attest` fixture starts the engine, and `attest.evaluate(chain)` runs every assertion in the chain and fails the test on a hard failure. A chain that is never passed to `evaluate()` checks nothing.

```python
from attest import AgentResult, TraceBuilder, expect


def refund_agent_result() -> AgentResult:
    """Stand-in for your agent: build the trace it produced."""
    trace = (
        TraceBuilder("refund-agent")
        .add_tool_call("lookup_order", args={"order_id": "ORD-123"}, result={"status": "paid"})
        .add_tool_call("process_refund", args={"order_id": "ORD-123"}, result={"refund_id": "R-1"})
        .set_output(message="Your refund R-1 is on its way.", structured={"refund_id": "R-1"})
        .set_metadata(cost_usd=0.01, latency_ms=800)
        .build()
    )
    return AgentResult(trace=trace)


def test_refund_agent(attest):
    result = refund_agent_result()
    attest.evaluate(
        expect(result)
        # Layer 1: schema validation
        .output_matches_schema({"type": "object", "required": ["refund_id"]})
        # Layer 2: cost and latency constraints
        .cost_under(0.05)
        .latency_under(5000)
        # Layer 3: trace structure
        .tools_called_in_order(["lookup_order", "process_refund"])
        .no_tool_loops("lookup_order", max_repetitions=3)
        # Layer 4: content
        .output_contains("refund")
        .output_not_contains("sorry")
    )
```

```bash
pytest test_refund_agent.py --attest-report=report.json
```

Change one assertion, for example `.output_contains("refund")` to `.output_contains("chargeback")`, and the test fails with a diagnostic for that assertion.

## Helpers

- `TraceBuilder.set_metadata(...)` merges: fields given in a later call are added, and fields it leaves out keep their value. `set_metadata(cost_usd=0.5)` followed by `set_metadata(latency_ms=100)` keeps both, so `cost_under(0.05)` fails on the cost.
- `@agent("name")` wraps a function with a `builder` parameter that Attest injects. A string return becomes the output `{"message": <str>}`, so `output_contains` works on a plain agent; a dict return is the output as is. Positional arguments are forwarded: with `def my_agent(builder, user_message)`, both `my_agent("hello")` and `my_agent(user_message="hello")` work. `adapter=` converts a provider adapter's return value and raises `TypeError` at decoration for an adapter that cannot convert.
- When the engine cannot be found or downloaded (offline, or behind a blocking proxy), pytest ends the run with one error line that names `ATTEST_ENGINE_PATH`, without a traceback. Build an engine with `make engine` and point `ATTEST_ENGINE_PATH` at it to run offline.

## Pytest integration

Attest registers as a pytest plugin automatically:

```bash
pytest tests/ --attest-engine=/path/to/attest-engine
```

## Links

- [Repository](https://github.com/attest-framework/attest)
- [Contributing](https://github.com/attest-framework/attest/blob/main/CONTRIBUTING.md)
- [License](https://github.com/attest-framework/attest/blob/main/LICENSE) (Apache-2.0)
