Metadata-Version: 2.5
Name: viewport-evals
Version: 0.1.0
Summary: Viewport Evals: declarative trajectory tests for AI agents. Record once, replay offline, assert on tools, arguments, round trips, cost and output.
Project-URL: Homepage, https://getviewport.com
Project-URL: Documentation, https://docs.getviewport.com/evals
Project-URL: Repository, https://github.com/viewportai/evals
Project-URL: Issues, https://github.com/viewportai/evals/issues
Author-email: Viewport <hello@getviewport.com>
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: agents,ai,evals,llm,pytest,testing,trajectory
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: httpx>=0.27
Requires-Dist: pydantic>=2.7
Requires-Dist: viewport-core>=0.1.0
Provides-Extra: anthropic
Requires-Dist: anthropic>=2.14; extra == 'anthropic'
Provides-Extra: claude-agent-sdk
Requires-Dist: claude-agent-sdk>=0.2.189; extra == 'claude-agent-sdk'
Provides-Extra: clock
Requires-Dist: time-machine>=2.16; extra == 'clock'
Provides-Extra: langgraph
Requires-Dist: langchain-core>=1.8; extra == 'langgraph'
Requires-Dist: langgraph>=1.2; extra == 'langgraph'
Provides-Extra: openai
Requires-Dist: openai>=3.59; extra == 'openai'
Provides-Extra: openai-agents
Requires-Dist: openai-agents>=0.26; extra == 'openai-agents'
Provides-Extra: otel
Requires-Dist: opentelemetry-api>=1.45; extra == 'otel'
Requires-Dist: opentelemetry-sdk>=1.45; extra == 'otel'
Provides-Extra: pydantic-ai
Requires-Dist: pydantic-ai-slim>=2.74; extra == 'pydantic-ai'
Description-Content-Type: text/markdown

# viewport-evals

Tests for agents that act. Test the world, not the path: assert what your agent changed in a simulated world and the
rules it must never break (a tool it must never call, an approval before a side effect, a turn and cost budget),
offline in pytest or from the `viewport-evals` CLI. Pin the tool sequence only where order truly matters. Import it as
`viewportai.evals`.

```python
from typing import Annotated, Any

from langchain_core.tools import InjectedToolCallId, tool
from langgraph.graph import START, MessagesState, StateGraph
from langgraph.prebuilt import ToolNode, tools_condition
from viewportai.core import ToolContext

from viewportai.evals import trace, world
from viewportai.evals.testing import reply, script, tool_call

# A simulated shop: plain JSON state plus a tool that changes it.
shop = world("shop", state={"refunds": {}})


@shop.tool(name="issue_refund")
def record_refund(state: dict[str, Any], order_id: str, amount: float) -> str:
    state["refunds"][order_id] = {"amount": amount}
    return "refunded"


async def test_refunds_a_damaged_order() -> None:
    w = shop.create()

    @tool
    def lookup_order(order_id: str) -> str:
        """Look up an order by id."""
        return f"{order_id}: delivered, damaged, total 42.50"

    @tool
    async def issue_refund(order_id: str, amount: float, call_id: Annotated[str, InjectedToolCallId]) -> Any:
        """Refund an order."""
        args = {"order_id": order_id, "amount": amount}
        return await w.tool("issue_refund").execute(args, ToolContext(call_id=call_id))

    # A scripted model, so the test needs no keys. With a real model, the first run records and CI replays.
    model = script(
        tool_call("lookup_order", order_id="A-1001"),
        tool_call("issue_refund", order_id="A-1001", amount=42.5),
        reply("Refund R-1001 is on its way."),
    )
    tools = [lookup_order, issue_refund]
    llm = model.langgraph().bind_tools(tools)
    graph = StateGraph(MessagesState)
    graph.add_node("model", lambda state: {"messages": [llm.invoke(state["messages"])]})
    graph.add_node("tools", ToolNode(tools))
    graph.add_edge(START, "model")
    graph.add_conditional_edges("model", tools_condition)
    graph.add_edge("tools", "model")
    agent = graph.compile()

    async with trace() as t:
        await agent.ainvoke({"messages": [("user", "My order A-1001 arrived damaged.")]})

    # What changed in the world.
    assert w.changed == ["$.refunds['A-1001']"]
    assert w.state["refunds"]["A-1001"] == {"amount": 42.5}

    # Guard rules: a tool it must never call, and a turn and token budget.
    assert not t.called("delete_account")
    assert len(t.model_calls) <= 4
    assert t.meets({"budget": {"tokens": 2000}})

    # Order matters here: the refund amount comes from the lookup.
    assert t.tool_names == ["lookup_order", "issue_refund"]
```

The pytest plugin loads on install, and `async def` tests run without pytest-asyncio.

```sh
pip install viewport-evals    # or: uv add --dev viewport-evals
```

Needs Python 3.11 or later. To build from source, see the [repository README](https://github.com/viewportai/evals#from-source).

- Repository, examples and status: [github.com/viewportai/evals](https://github.com/viewportai/evals)
- Docs: [docs.getviewport.com/evals](https://docs.getviewport.com/evals)
- TypeScript package: `@viewportai/evals` on npm, with identical verdicts for the same case files.

Apache-2.0.
