Skip to main content

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.

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.

pip install "viewport-evals[langgraph]" pytest    # or: uv add --dev "viewport-evals[langgraph]" pytest

The example above is a LangGraph agent, so it needs the langgraph extra; save it as test_refunds.py and run pytest. Other adapters are separate extras. The package also installs a viewport-evals command (run YAML cases, show recorded runs, serve the results viewer): viewport-evals --help.

Needs Python 3.11 or later. To build from source, see the repository README.

Apache-2.0.

Metadata

Release files for viewport-evals 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for viewport-evals 0.1.1
File Size Uploaded Provenance Actions
viewport_evals-0.1.1.tar.gz 553.8 kB Without provenance Details for viewport_evals-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for viewport-evals 0.1.1
File Interpreter ABI Platform Actions
viewport_evals-0.1.1-py3-none-any.whl Python 3 none any Details for viewport_evals-0.1.1-py3-none-any.whl

Total release size: 1.2 MB

Release files / viewport_evals-0.1.1.tar.gz

Download URL viewport_evals-0.1.1.tar.gz
Size 553.8 kB
Tags Source
SHA-256 checksum
How to use checksums
615acadc21d8bbcdd64be3efa84028ce08363619282492e425a701088eb423c5
BLAKE2b-256 checksum
How to use checksums
30eb411fa3e08e75550bd8e5ee32163f67b5e15a0ad88c357d89f2c2f4e38625
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / viewport_evals-0.1.1-py3-none-any.whl

Download URL viewport_evals-0.1.1-py3-none-any.whl
Size 607.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a70ed96bf85429def44bc01c50c728b05ccef50e8bd927569631233f0dc507c
BLAKE2b-256 checksum
How to use checksums
f6b033cf21ec8490fc60f82eb1cb187613c5d67677e5426560f06f72e151c40d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for viewport-evals 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page