Evals

Viewport Evals

Tests for agents that act. Assert what your agent changed in the world and the rules it must never break, offline in pytest and vitest.

Status: Beta. Version 0.1.0 is on npm (@viewportai/evals) and PyPI (viewport-evals).

Tests for agents that act. Record the model calls, fake the world, fast-forward the clock, and assert what the agent did to it, offline in pytest and vitest, in front of every pull request merge. Viewport Evals sits next to observability platforms such as Langfuse, Braintrust, LangSmith and Phoenix: production traces come in as tests, scores go out.

Test the world, not the path. It checks what an agent did, not only what it said, and it leads with what lasts: what the agent changed in the systems it touched, and the rules it must never break, such as a tool it must never call, an approval before every side effect, and a turn and cost budget. It also checks tool arguments, whether the final answer holds up, and, where order truly matters, the tool sequence. An exact sequence can change when you edit a prompt or swap a model while the agent still does the right thing, so pin it only when one step depends on another. You write the test in code with trace() or as a YAML case. The first local run records the model traffic; every run after, and every CI run, replays it. Your agent code runs for real, the model does not, so tests are offline, keyless and deterministic.

Why trajectory tests

An agent can give the right answer the wrong way. Output-only evals pass all of these; a trajectory test fails them with the assertion that names the problem:

What happenedOutput-only evalTrajectory test
Refunded the order, but called delete_account on the waypasstools.not_called fails
Right answer after 9 model calls instead of 3passmodel_calls and budget.cost_usd fail
Polite reply, but refunded $142.50 instead of $42.50passtools.calls[0](issue_refund): args.amount fails
Issued the refund before the approval came backpassapprovals.before_side_effect fails
A prompt change doubled the tokens per conversationinvisiblebudget.tokens fails

Output still matters, so output checks are built in too: contains, regex, json_schema, jsonpath and LLM judges.

30-second example

A support agent refunds a cracked kettle from a tea order. Its tools act on a simulated payments world, and the model is a script, so the test runs with no keys. It checks what changed in the world first, then the guard rules and the reply, and the tool order last, because the refund amount comes from the lookup. In your project you pass your real client; the first run records it.

main.py
async def test_refunds_the_cracked_kettle_not_the_whole_order() -> None:
    model = refund_script()
    world = shop.create(SEED)

    async with trace() as t:
        t.output = await support_agent(
            model.async_anthropic(), world.tools, "My order LT-4810 came with a cracked kettle."
        )

    # What changed in the world: one refund for the kettle, and the charge is only partly refunded.
    assert world.changed == ["$.charges['CH-1'].amount_refunded", "$.charges['CH-1'].status", "$.refunds['RE-1']"]
    assert world.state["charges"]["CH-1"]["status"] == "partially_refunded"
    assert world.state["refunds"]["RE-1"]["amount"] == 5400

    # Guard rules: never charge the customer again, and stay within a turn and cost budget.
    assert not t.called("create_charge")
    assert len(t.model_calls) <= 4
    assert t.meets({"budget": {"tokens": 3000, "cost_usd": 0.02}})

    # What it said.
    assert "$54.00" in t.output

    # Order matters here: the refund amount comes from the lookup, so the lookup must come first.
    assert t.tool_names == ["lookup_order", "issue_refund"]
    model.assert_consumed()

main.ts
test("refunds the cracked kettle, not the whole order", async () => {
  const model = refundScript();
  const world = shop.create(seed);

  const t = await trace(() =>
    supportAgent(model.anthropic(), world.tools, "My order LT-4810 came with a cracked kettle."),
  );

  // What changed in the world: one refund for the kettle, and the charge is only partly refunded.
  expect(world.changed).toEqual(["$.charges['CH-1'].amount_refunded", "$.charges['CH-1'].status", "$.refunds['RE-1']"]);
  expect(world.state.charges["CH-1"]).toMatchObject({ amount_refunded: 5400, status: "partially_refunded" });
  expect(world.state.refunds["RE-1"]).toMatchObject({ amount: 5400, reason: expect.stringMatching(/crack/i) });

  // Guard rules: never charge the customer again, and stay within a turn and cost budget.
  expect(t).not.toHaveCalledTool("create_charge");
  expect(t).toHaveModelCalls({ max: 4 });
  expect(t).toBeWithinBudget({ tokens: 3000, cost_usd: 0.02 });

  // What it said.
  expect(t.output).toContain("$54.00");

  // Order matters here: the refund amount comes from the lookup, so the lookup must come first.
  expect(t.toolNames).toEqual(["lookup_order", "issue_refund"]);
  model.assertConsumed();
});

The same expectations work as a YAML case, run by viewport-evals run, by pytest, or by describeCases in vitest:

evals/refunds.yaml
# yaml-language-server: $schema=https://getviewport.com/schemas/evals/case/v1.json
# Given a shop with one paid order, a customer reports one damaged item. The agent must refund that item only.
id: cracked-kettle
description: A cracked kettle is refunded on its own; the rest of the order stands.
input: "My order LT-4810 came with a cracked kettle."

world:
  shop:
    seed:
      customers:
        CU-1:
          id: CU-1
          name: Odile Ferreira
          email: [email protected]
          card: { brand: visa, last4: "4242", status: valid }
      charges:
        CH-1:
          id: CH-1
          customer_id: CU-1
          amount: 8600
          currency: usd
          description: "Order LT-4810: cast iron kettle 5400, oolong sampler 3200"
          idempotency_key: "order:LT-4810"
          status: succeeded
          amount_refunded: 0

expect:
  # What changed in the world: one refund for the kettle; the rest of the order stands.
  world:
    shop:
      changed: ["$.charges['CH-1'].amount_refunded", "$.charges['CH-1'].status", "$.refunds['RE-1']"]
      state:
        charges: { CH-1: { amount_refunded: 5400, status: partially_refunded } }
        refunds: { RE-1: { amount: { lte: 5400 }, reason: { icontains: crack } } }
  # Guard rules: never charge the customer again, and stay within a turn and cost budget.
  invariants:
    - name: never charge again
      never: { tool: create_charge }
  model_calls: { max: 4 }
  budget: { tokens: 3000, cost_usd: 0.02 }
  output: { contains: "$54.00" }
  # Order matters here: the refund amount comes from the lookup, so the lookup must come first.
  tools: { exactly: [lookup_order, issue_refund] }

What ships in 0.1

  • trace() and its query helpers, pytest and vitest integration, and YAML cases with a strict schema: world end states, invariants, tools, model calls, budgets, output, errors, approvals and gated actions, skills, agents, handoffs, any event type, and assertion plugins.
  • Record and replay at the HTTP boundary, with five modes, pass thresholds over repeated runs, LLM judges with cached verdicts, and CI gates.
  • Invariants: rules over a whole run, in the same invariant/v1 format Viewport HITL enforces.
  • Worlds: simulated systems with end-state assertions, and crm, calendar, payments and inbox packs.
  • Simulated time and multi-episode cases, including DBOS durable workflows in Python.
  • Simulated users that write the next turn from the conversation.
  • Production replay: import a Langfuse, LangSmith or Braintrust trace as a test, serve its tool responses, assert the behavior diff.
  • A model matrix and flake detection for qualifying a cheaper model.
  • Score exporters to Langfuse, Braintrust, LangSmith, Phoenix and OpenTelemetry, and a results directory with an interactive viewer, served by viewport-evals ui.
  • Capture adapters for the Anthropic and OpenAI SDKs, LangGraph, the OpenAI Agents SDK, the Claude Agent SDK and OpenTelemetry in both languages, and the Vercel AI SDK in TypeScript.
  • Identical verdicts in Python and TypeScript, pinned by a shared conformance suite.

Not in 0.1: a Temporal time-skipping bridge, Pydantic AI and Mastra adapters, and a library of ready-made LLM judges.

Next: the quickstart.

On this page