API
The public API in Python and TypeScript, side by side. Same behavior and verdicts, names idiomatic to each language.
| Concept | Python (from viewportai import context) | TypeScript (@viewportai/context) |
|---|---|---|
| Load a folder | context.load_skills("skills", tools=[...], budget=8_000) (sync), await context.aload_skills(...) | await loadSkills("skills", { tools, budget: 8_000 }) |
| Inline skill | context.Skill(name=..., description=..., instructions=...) | defineSkill({ name, description, instructions }) |
| Registry | context.SkillRegistry([...], tools=...), skills.configure(...) | new SkillRegistry([...], { tools }), skills.configure({...}) |
| Session | skills.session(), skills.session(state=...), skills.session(messages=...) | skills.session(), skills.session({ state }), skills.session({ messages }) |
| Dispatch a tool call | await session.call("load_skill", name="refunds"), await session.dispatch(name, args, call_id=...) | await session.call("load_skill", { name: "refunds" }, { callId }) |
| Skills this session may load by any path (the grant, with everything they require) | session.granted | session.granted |
The refusal the model gets for calling a tool now (None / undefined when callable, hidden or unknown), for adapters that refuse outside the guard | session.refusal(tool) | session.refusal(tool) |
| Start a new step by hand (a skill loaded by the model binds its tools from the next step; building a prompt does this too) | session.next_step() | session.nextStep() |
| Load from code | session.load("refunds"), session.unload("refunds") | session.load("refunds"), session.unload("refunds") |
| Router and triggers for an input | await session.prepare(input) | await session.prepare(input) |
| What is loaded | session.loaded (each equals its name), "refunds" in session | session.loaded, session.loadedNames, session.has("refunds") |
| Save state | session.state (JSON-safe) | session.state |
| Build a request | session.prompt(input, messages=..., extra=...) | session.prompt(input, { messages, extra }) |
| Tool names | prompt.tool_names | prompt.toolNames |
| Budget report | prompt.budget (prints 450 / 8,000 tokens (ok)), prompt.dropped | prompt.budget, prompt.dropped |
| Over budget as an exception | prompt.raise_for_budget() | prompt.throwIfOverBudget() |
| Render for a provider | prompt.render("anthropic") | prompt.render("anthropic") |
| Prefix check | prompt.shares_prefix_with(other) | prompt.sharesPrefixWith(other) |
| Human-readable table | prompt.explain() (also the repr) | prompt.explain() |
| Binding guard (core middleware) | session.guard | session.guard |
| Counters | context.counters.estimate(), context.counters.tiktoken("o200k_base") | counters.estimate(), await counters.tiktoken("o200k_base") |
| Router | context.keyword_router(top_k=2) | keywordRouter({ topK: 2 }) |
| Adapters | from viewportai.context.<slug> import with_skills | import { withSkills } from "@viewportai/context/<slug>" |
| Test helpers | viewportai.context.testing, pytest fixtures tmp_skills, skills, skill_events | @viewportai/context/testing |
| Errors | ContextError, SkillNotFound, ContextBudgetExceeded, ToolNotLoaded | same names |
Adapter slugs: ai-sdk (TypeScript), langgraph, openai-agents (openai_agents), claude-agent-sdk
(claude_agent_sdk, preview), pydantic-ai (Python, pydantic_ai), anthropic, openai, otel (TypeScript).
Registry options
Set on the registry (load_skills, configure), overridable per session. Precedence: explicit arguments, then
environment (VIEWPORT_CONTEXT_SKILLS, _BUDGET, _COUNTER, _EXPOSE), then the config file
([tool.viewport.context] in pyproject.toml, context: {} in viewport.config.ts), then defaults. The config file
is read from the working directory (or cwd) only when you pass no skills path, or set config (true to search,
or a file); in TypeScript viewport.config.* is imported, so it runs as code: keep it under your control.
| Option (Python / TypeScript) | Default | Meaning |
|---|---|---|
budget | none (report only) | A number (input tokens) or { input_tokens, sections } |
counter | estimate | A counter or a registered name: estimate, tiktoken:<encoding>, anthropic:<model>, openai:<model> |
expose | auto | bound, deferred, allowed; auto resolves per provider |
instructions | empty | Base instructions, first in the static tier |
always, required | [] | Skills loaded statically; skills never dropped |
allow | all | The grant: skills this session may load by any path (model, code, triggers, router, always, restored state), with everything they require. A session's or configure's allow is intersected with the registry's: it narrows the grant, never widens it. An explicit always outside it is an options error (pass always: [] to clear an inherited one) |
catalog / catalog_limit (catalogLimit) | system / 64 | Where the catalog lives (system or tool); when search mode starts |
on_over_budget (onOverBudget) | evict | evict (unload older model, router and trigger loads) or reject |
router | none | A router or keyword |
ambient, unbound | [], error | Always-visible tools; what to do with tools no skill binds |
resources | false | Enable read_skill_resource |
tool_name (toolName) | load_skill | Rename the load tool for hosts with another convention |