Core
Quickstart
Record a tool call into a trajectory and assert on it, in Python and TypeScript.
Install the package for your language:
npm install @viewportai/core # Node 22.3 or later
pip install viewport-core # Python 3.11 or laterTo run the examples below from a clone, install from source. You need Node 22.18 or later with corepack (on
Node 25 and later, install corepack first with npm install -g corepack, or pnpm with npm install -g pnpm), Python
3.11 or later, and uv:
git clone https://github.com/viewportai/core.git
cd core && make setup distThen run the examples from core/ with node --experimental-strip-types examples/ts/quickstart/main.ts and
uv run --project python python examples/python/quickstart/main.py.
Define a tool, call it inside trace(), and match the recorded call:
import asyncio
from viewportai.core import match, stable_json, tool, trace
@tool
async def issue_refund(order_id: str, amount: float) -> dict[str, str]:
"""Refund an order."""
return {"refund_id": f"R-{order_id[2:]}"}
async def main() -> None:
async with trace() as t:
await issue_refund("A-1001", 42.5)
call = t.trajectory.tool_calls()[0]
print(stable_json(call.result)) # {"refund_id":"R-1001"}
print(str(match({"tool_name": "issue_refund", "args": {"amount": {"lte": 100}}}, call).passed).lower()) # true
asyncio.run(main())import { defineTool, match, stableJson, toolCalls, trace } from "@viewportai/core";
const issueRefund = defineTool({
name: "issue_refund",
description: "Refund an order.",
input_schema: {
type: "object",
properties: { order_id: { type: "string" }, amount: { type: "number" } },
required: ["order_id", "amount"],
},
execute: async ({ order_id }) => ({ refund_id: `R-${order_id.slice(2)}` }),
});
const { trajectory } = await trace(() => issueRefund.execute({ order_id: "A-1001", amount: 42.5 }));
const call = toolCalls(trajectory)[0];
console.log(stableJson(call?.result)); // {"refund_id":"R-1001"}
console.log(match({ tool_name: "issue_refund", args: { amount: { lte: 100 } } }, call).passed); // trueWhat happened:
@tool(Python) anddefineTool(TypeScript) made a recorded tool. In Python the input schema comes from the type hints and the description from the docstring; in TypeScript the arguments are typed frominput_schema.trace()opened a scope. The tool saw it and emitted onetool_callevent withargs,result,started_atandlatency_ms. Outside a scope, recording costs one context lookup.matchcompared plain data. The spec is a partial pattern:tool_nameandargs.amountmust match, other fields are ignored.
Next, learn the Matcher or see how tools and middlewares compose.