Context

Quickstart

Load a folder of skills, build a session, and watch tools appear as the agent loads skills.

npm install @viewportai/context @viewportai/core   # or: pnpm add @viewportai/context @viewportai/core
pip install viewport-context                        # or: uv add viewport-context

The TypeScript package needs Node 22 or later and is ESM only. The Python package needs Python 3.11 or later. Adapters for LangGraph, the OpenAI Agents SDK and others are optional: install the framework you use alongside.

From source.

To run the examples or work on Context itself, clone it next to a checkout of viewportai/core (Node 22.18 or later with corepack, Python 3.11+, uv). tsup 9, the build tool, declares Node 22.18 or later; the package itself runs on Node 22.

git clone https://github.com/viewportai/core.git
git clone https://github.com/viewportai/context.git
cd core && corepack pnpm install && corepack pnpm --dir ts run build && cd ..
cd context && make setup && make build

Node 25 and later ship without corepack: run npm install -g corepack first, or install pnpm 10 and use pnpm in place of corepack pnpm (make falls back to pnpm on its own). pnpm may print "Ignored build scripts: esbuild"; that is expected and needs no action.

1. Write skills

A skill is a folder with a SKILL.md. The frontmatter is the Agent Skills format plus a tools list: the tools this skill binds, by their wire names.

---
name: refunds
description: Issue refunds for damaged, late or wrong orders. Use when a customer asks for money back.
tools: [lookup_order, issue_refund]
requires: [support-voice]
---
# Refunds

1. Look up the order. Never refund an order you have not looked up.
2. Refund the order total for damaged or wrong items, shipping only for late ones.
3. Refunds over $100 need a human: say so and stop.

The example folder, examples/<language>/quickstart/skills/, has nine skills: one always skill (support-voice) and eight the model can load.

2. Define the tools

Skills bind tools by name. The quickstart's three tools are core tools in a file next to the program:

examples/python/quickstart/tools.py
"""The three tools every example shares, as core ``Tool`` values with the same JSON Schemas as the TypeScript
examples. Wire names (``lookup_order``) are what SKILL.md files bind, not the variable names."""

from __future__ import annotations

from typing import Any

from viewportai.core import Tool


async def _lookup_order(args: dict[str, Any]) -> dict[str, Any]:
    return {"order_id": args["order_id"], "status": "delivered", "total": 42.5}


async def _issue_refund(args: dict[str, Any]) -> dict[str, str]:
    return {"refund_id": f"R-{args['order_id']}"}


async def _search_docs(args: dict[str, Any]) -> list[str]:
    return [f"How to report {args['query']}"]


lookup_order = Tool(
    name="lookup_order",
    description="Look up an order by id.",
    input_schema={"type": "object", "properties": {"order_id": {"type": "string"}}, "required": ["order_id"]},
    execute=_lookup_order,
)

issue_refund = Tool(
    name="issue_refund",
    description="Refund an order, in dollars.",
    input_schema={
        "type": "object",
        "properties": {"order_id": {"type": "string"}, "amount": {"type": "number", "minimum": 0}},
        "required": ["order_id", "amount"],
    },
    execute=_issue_refund,
)

search_docs = Tool(
    name="search_docs",
    description="Search the help center.",
    input_schema={"type": "object", "properties": {"query": {"type": "string"}}, "required": ["query"]},
    execute=_search_docs,
)
examples/ts/quickstart/tools.ts
import { defineTool } from "@viewportai/core";

// Wire names (`lookup_order`) are what SKILL.md files bind, not the variable names.
export const lookupOrder = defineTool({
  name: "lookup_order",
  description: "Look up an order by id.",
  input_schema: { type: "object", properties: { order_id: { type: "string" } }, required: ["order_id"] },
  execute: async ({ order_id }: { order_id: string }) => ({ order_id, status: "delivered", total: 42.5 }),
});

export const issueRefund = defineTool({
  name: "issue_refund",
  description: "Refund an order, in dollars.",
  input_schema: {
    type: "object",
    properties: { order_id: { type: "string" }, amount: { type: "number", minimum: 0 } },
    required: ["order_id", "amount"],
  },
  execute: async ({ order_id }: { order_id: string }) => ({ refund_id: `R-${order_id}` }),
});

export const searchDocs = defineTool({
  name: "search_docs",
  description: "Search the help center.",
  input_schema: { type: "object", properties: { query: { type: "string" } }, required: ["query"] },
  execute: async ({ query }: { query: string }) => [`How to report ${query}`],
});

3. Build a session and drive it

The complete program, next to tools and skills/:

examples/python/quickstart/main.py
import asyncio

from tools import issue_refund, lookup_order, search_docs  # core Tool values, in tools.py next to this file
from viewportai import context


async def main() -> None:
    skills = context.load_skills("skills", tools=[lookup_order, issue_refund, search_docs], budget=8_000)
    session = skills.session()

    print(session.prompt("My order A-1001 arrived damaged.").tool_names)  # ['load_skill']   8 skills in the catalog
    print(session.prompt().budget)  # 450 / 8,000 tokens (ok)

    await session.call("load_skill", name="refunds")  # exactly what the model does
    early = await session.call("lookup_order", order_id="A-1001")  # same step as the load
    print(early.content)  # lookup_order is not available yet: the refunds skill was loaded in this same step. ...
    print(session.prompt().tool_names)  # ['load_skill', 'lookup_order', 'issue_refund']   the next step starts here
    order = await session.call("lookup_order", order_id="A-1001")
    print(order.content)  # {"order_id":"A-1001","status":"delivered","total":42.5}
    refused = await session.call("search_docs", query="damage")
    print(refused.content)  # search_docs is not available. Load the docs skill first.
    print(session.prompt().explain())


asyncio.run(main())
examples/ts/quickstart/main.ts
import { loadSkills } from "@viewportai/context";
import { issueRefund, lookupOrder, searchDocs } from "./tools.ts"; // defineTool({ name: "lookup_order", ... })

const skills = await loadSkills("skills", { tools: [lookupOrder, issueRefund, searchDocs], budget: 8_000 });
const session = skills.session();

console.log(session.prompt("My order A-1001 arrived damaged.").toolNames); // [ 'load_skill' ]   8 skills in the catalog
console.log(String(session.prompt().budget)); // 450 / 8,000 tokens (ok)

await session.call("load_skill", { name: "refunds" }); // exactly what the model does
const early = await session.call("lookup_order", { order_id: "A-1001" }); // same step as the load
console.log(early.content); // lookup_order is not available yet: the refunds skill was loaded in this same step. ...
console.log(session.prompt().toolNames); // [ 'load_skill', 'lookup_order', 'issue_refund' ]   the next step starts here
const order = await session.call("lookup_order", { order_id: "A-1001" });
console.log(order.content); // {"order_id":"A-1001","status":"delivered","total":42.5}
const refused = await session.call("search_docs", { query: "damage" });
console.log(refused.content); // search_docs is not available. Load the docs skill first.
console.log(session.prompt().explain());

Run it from the root of the context clone, no API key (each line works on its own):

(cd examples/python/quickstart && uv run --project ../../../python --all-extras python main.py)
(cd examples/ts/quickstart && node --experimental-strip-types main.ts)   # older Node 22 prints an ExperimentalWarning; expected

To run the same files outside the clone, point them at your builds: in Python, uv run --project <path to context>/python python main.py (or pip install -e <path to context>/python into your environment); in TypeScript, a package.json with "type": "module" and "dependencies": { "@viewportai/context": "file:<path to context>/ts", "@viewportai/core": "file:<path to core>/ts" }, then npm install (core is a direct dependency because the tools file defines core tools).

It prints (Python shows Python lists, otherwise the same bytes):

[ 'load_skill' ]
450 / 8,000 tokens (ok)
lookup_order is not available yet: the refunds skill was loaded in this same step. Read its instructions, then call lookup_order in your next step.
[ 'load_skill', 'lookup_order', 'issue_refund' ]
{"order_id":"A-1001","status":"delivered","total":42.5}
search_docs is not available. Load the docs skill first.
prompt (estimate)
  static     skill:support-voice                    35
  static     catalog                               305
  transcript skill:refunds                          75
  request    tools                                 255
  tools: load_skill, lookup_order, issue_refund  deferred: 1
  budget: 670 / 8,000 tokens (ok)

skills is an immutable registry: build it once at startup and share it. session is one conversation. The model starts with one tool. After load_skill, the refunds skill's tools are bound from the next step on, so the model reads the skill's instructions before it uses them: lookup_order called in the same step as the load is refused, with a message telling the model to call it next step. A step starts each time a prompt is built, which an agent loop does before every model call; in a script, build the prompt (as above) or call session.next_step() (nextStep()). The docs skill's search_docs is not bound at all, so a call to it is refused without running.

4. Put it in an agent loop

Every adapter does the same thing inside a framework. With the Vercel AI SDK it is one spread:

const skills = await loadSkills("../quickstart/skills", { tools: [lookupOrder, issueRefund, searchDocs] });
const model = scriptedModel(script(load("refunds"), call("lookup_order", { order_id: "A-1001" }), say("Refunded.")));
const prompt = "My order A-1001 arrived damaged.";

const result = await generateText({ model, prompt, stopWhen: isStepCount(10), ...withSkills(skills) });

With LangChain v1 or LangGraph, it is one middleware:

skills = context.load_skills("../quickstart/skills", tools=[lookup_order, issue_refund, search_docs])
model = scripted_model(script(load("refunds"), call("lookup_order", order_id="A-1001"), say("Refunded.")))

agent = create_agent(model, tools=[], middleware=[with_skills(skills)], checkpointer=InMemorySaver())
config = {"configurable": {"thread_id": "customer-42"}}
out = await agent.ainvoke({"messages": [{"role": "user", "content": "My order A-1001 arrived damaged."}]}, config)
const skills = await loadSkills("../quickstart/skills", { tools: [lookupOrder, issueRefund, searchDocs] });
const model = scriptedModel(script(load("refunds"), call("lookup_order", { order_id: "A-1001" }), say("Refunded.")));

const agent = createAgent({ model, tools: [], middleware: [withSkills(skills)], checkpointer: new MemorySaver() });
const config = { configurable: { thread_id: "customer-42" } };
const out = await agent.invoke({ messages: [{ role: "user", content: "My order A-1001 arrived damaged." }] }, config);

These run against the real frameworks with a scripted model (no key): the model's first step sees only load_skill, its second sees lookup_order and issue_refund as well.

On this page