Metadata-Version: 2.5
Name: viewport-context
Version: 0.1.1
Summary: Progressive skill and context loading for agents: a skills registry, tools bound only while their skill is loaded, context budgets and cache-friendly prompt assembly.
Project-URL: Homepage, https://getviewport.com
Project-URL: Documentation, https://docs.getviewport.com/context
Project-URL: Repository, https://github.com/viewportai/context
Project-URL: Issues, https://github.com/viewportai/context/issues
Author-email: Viewport <hello@getviewport.com>
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: agents,ai,claude-agent-sdk,context,langgraph,openai-agents,prompt-caching,skills,tokens
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: pydantic>=2.7
Requires-Dist: viewport-core>=0.1.0
Provides-Extra: anthropic
Requires-Dist: anthropic>=2.14; extra == 'anthropic'
Provides-Extra: claude-agent-sdk
Requires-Dist: claude-agent-sdk>=0.2.189; extra == 'claude-agent-sdk'
Provides-Extra: gemini
Requires-Dist: google-genai>=3.6; extra == 'gemini'
Provides-Extra: langgraph
Requires-Dist: langchain>=1.5.2; extra == 'langgraph'
Requires-Dist: langgraph>=1.2.24; extra == 'langgraph'
Provides-Extra: openai
Requires-Dist: openai>=3.59; extra == 'openai'
Provides-Extra: openai-agents
Requires-Dist: openai-agents>=0.26; extra == 'openai-agents'
Provides-Extra: otel
Requires-Dist: opentelemetry-api>=1.27; extra == 'otel'
Provides-Extra: pydantic-ai
Requires-Dist: pydantic-ai-slim>=2.75; extra == 'pydantic-ai'
Provides-Extra: tiktoken
Requires-Dist: tiktoken>=0.14; extra == 'tiktoken'
Description-Content-Type: text/markdown

# viewport-context

Progressive skill loading and per-skill tool binding for agents (Python, import `viewportai.context`). The model starts
with a short catalog and one tool, `load_skill`; each skill's instructions and tools arrive only when it loads, inside a
token budget. The npm package `@viewportai/context` implements the same spec, pinned by shared conformance vectors.

```sh
pip install viewport-context   # or: uv add viewport-context
```

Python 3.11 or newer. To build from source, see https://github.com/viewportai/context#from-source.

## Quickstart

Runs with no API key. In an empty folder, install the package (see above), then create these files.

Two skills, one folder each:

`skills/refunds/SKILL.md`

```markdown
---

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

# Refunds

Look up the order first. Refund the order total for damaged or wrong items. Refunds over $100 need a human.
```

`skills/docs/SKILL.md`

```markdown
---

name: docs
description: Answer how-to questions from the help center. Use for questions about features and settings.
tools: [search_docs]
---

# Help center

Search before you answer. If nothing matches, say so instead of guessing.
```

`tools.py`

```python
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,
)
```

`main.py`

```python
import asyncio

from tools import issue_refund, lookup_order, search_docs
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']
    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)  # refused: call it in the next step
    print(session.prompt().tool_names)  # ['load_skill', 'lookup_order', 'issue_refund']
    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.


asyncio.run(main())
```

Run it with `python main.py`.

Output:

```text
['load_skill']
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.
```

A skill's tools become callable in the next step, once a new prompt is built, so the model reads the instructions
first; a tool called in the same step as its skill's load is refused with a message to call it next step.

Adapters (extras): `viewportai.context.langgraph`, `.openai_agents`, `.claude_agent_sdk` (preview), `.pydantic_ai`,
`.anthropic`,
`.openai`; test helpers in `viewportai.context.testing` and pytest fixtures (`tmp_skills`, `skills`, `skill_events`).

## CLI

The package installs a `viewport-context` command that lints skills, prints per-skill token costs and shows the request
a session would send. After `pip install viewport-context` it is on your PATH.

```sh
viewport-context lint skills
viewport-context inspect skills
```

Docs, examples and the design: https://github.com/viewportai/context. License: Apache-2.0.
