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    # or: uv add --dev viewport-evals

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.0

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.0
File Size Uploaded Provenance Actions
viewport_evals-0.1.0.tar.gz 553.7 kB Without provenance Details for viewport_evals-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 1.2 MB

Release files / viewport_evals-0.1.0.tar.gz

Download URL viewport_evals-0.1.0.tar.gz
Size 553.7 kB
Tags Source
SHA-256 checksum
How to use checksums
185b34d868cf279c3b4fbef8b23d73017453638bd8e0cc4e8341d5509b067886
BLAKE2b-256 checksum
How to use checksums
0659968e64f5cc196497334bd1c3620bc8b4da52eaf5c671c7c1313053b942f4
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.0-py3-none-any.whl

Download URL viewport_evals-0.1.0-py3-none-any.whl
Size 607.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
42e8e5299192a0e2ea6290ceaf85483e85ac0b67179feabe29f9300d3c10a2b2
BLAKE2b-256 checksum
How to use checksums
a9d80db7ac2ff0220fc664ffb8cb64a033c1ac2dfd06a1681c0f11636e06d331
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.0

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.0 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