ContextReference

API

The public API in Python and TypeScript, side by side. Same behavior and verdicts, names idiomatic to each language.

ConceptPython (from viewportai import context)TypeScript (@viewportai/context)
Load a foldercontext.load_skills("skills", tools=[...], budget=8_000) (sync), await context.aload_skills(...)await loadSkills("skills", { tools, budget: 8_000 })
Inline skillcontext.Skill(name=..., description=..., instructions=...)defineSkill({ name, description, instructions })
Registrycontext.SkillRegistry([...], tools=...), skills.configure(...)new SkillRegistry([...], { tools }), skills.configure({...})
Sessionskills.session(), skills.session(state=...), skills.session(messages=...)skills.session(), skills.session({ state }), skills.session({ messages })
Dispatch a tool callawait 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.grantedsession.granted
The refusal the model gets for calling a tool now (None / undefined when callable, hidden or unknown), for adapters that refuse outside the guardsession.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 codesession.load("refunds"), session.unload("refunds")session.load("refunds"), session.unload("refunds")
Router and triggers for an inputawait session.prepare(input)await session.prepare(input)
What is loadedsession.loaded (each equals its name), "refunds" in sessionsession.loaded, session.loadedNames, session.has("refunds")
Save statesession.state (JSON-safe)session.state
Build a requestsession.prompt(input, messages=..., extra=...)session.prompt(input, { messages, extra })
Tool namesprompt.tool_namesprompt.toolNames
Budget reportprompt.budget (prints 450 / 8,000 tokens (ok)), prompt.droppedprompt.budget, prompt.dropped
Over budget as an exceptionprompt.raise_for_budget()prompt.throwIfOverBudget()
Render for a providerprompt.render("anthropic")prompt.render("anthropic")
Prefix checkprompt.shares_prefix_with(other)prompt.sharesPrefixWith(other)
Human-readable tableprompt.explain() (also the repr)prompt.explain()
Binding guard (core middleware)session.guardsession.guard
Counterscontext.counters.estimate(), context.counters.tiktoken("o200k_base")counters.estimate(), await counters.tiktoken("o200k_base")
Routercontext.keyword_router(top_k=2)keywordRouter({ topK: 2 })
Adaptersfrom viewportai.context.<slug> import with_skillsimport { withSkills } from "@viewportai/context/<slug>"
Test helpersviewportai.context.testing, pytest fixtures tmp_skills, skills, skill_events@viewportai/context/testing
ErrorsContextError, SkillNotFound, ContextBudgetExceeded, ToolNotLoadedsame 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)DefaultMeaning
budgetnone (report only)A number (input tokens) or { input_tokens, sections }
counterestimateA counter or a registered name: estimate, tiktoken:<encoding>, anthropic:<model>, openai:<model>
exposeautobound, deferred, allowed; auto resolves per provider
instructionsemptyBase instructions, first in the static tier
always, required[]Skills loaded statically; skills never dropped
allowallThe 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 / 64Where the catalog lives (system or tool); when search mode starts
on_over_budget (onOverBudget)evictevict (unload older model, router and trigger loads) or reject
routernoneA router or keyword
ambient, unbound[], errorAlways-visible tools; what to do with tools no skill binds
resourcesfalseEnable read_skill_resource
tool_name (toolName)load_skillRename the load tool for hosts with another convention

On this page