Skip to main content

Affordance

A browser for models. A web browser renders the internet's state into pixels for a person. Affordance renders the world's state into tokens for a model.

An app is written in TSX, like a web page. It renders its state (a task, a shell's output, notes, messages from other agents) into the exact token IDs the model reads. The actions still visible after layout (<aff>) are the model's tools. A reply picks one; its handler changes the state; the next render shows the result. The app owns its loop, its tools and its context policy; Affordance owns rendering, layout, effects and replay.

export default function Hello({name = "world"}) {
  return <box>
    <span label="greeting">{`Hello, ${name}!`}</span>
    <aff name="greet" onGreet={({name}) => ({name})}>{" [greet]"}</aff>
  </box>;
}

What it gives you

  • Exact token IDs. A render is the token sequence the model sees, with the chat template applied by a TSX template app. For 740 models it matches the official template's IDs (affordance check compares every case and prints the first divergence), and one command adds a model that is not among them.
  • Images, audio and video. <img>, <audio> and <video> put a model's placeholder tokens in the prompt and send the file with the request, to SGLang or to a chat endpoint such as vLLM's.
  • Layout for a token budget. Token style sheets bound boxes, drop old history in steps and elide old tool results, so a long session stays inside the window and its prompt prefix stays stable for the server's cache.
  • Deterministic replay. Each agent's inputs are journaled. Replaying a journal rebuilds the agent exactly: resume after a crash, or step through a run turn by turn. A command that was still running when the process died is sent again on resume, so a tool that writes to the outside world should be safe to repeat.
  • Stateful agents. Many agents in one process, each an event loop with timers, child instances, messages, machines to run commands on, and model calls it makes when its code decides to.

Affordance is not React, Node or a prompt builder. TSX is a documented subset interpreted in Rust; there is no npm resolver. See public contracts and known limits.

Try it

Install the affordance command (from a checkout until the first crates.io release):

cargo install --path .

Render the app above (no model, no Python):

echo '{"name":"world"}' | affordance render views/demo/hello.tsx --state -

It prints Hello, world! [greet] and its spans: which IDs are text and which are the greet action. Then write and run a first agent, against a local model server (llama.cpp, Ollama or vLLM) or a hosted API, with a shell on your machine:

affordance init my-agent && cd my-agent
affordance run                      # runs affordance.yaml here; journals go to .affordance/
affordance run --resume             # continue it
affordance run --set model.url=http://127.0.0.1:11434/v1   # another server, for one run

The agent init wrote is one file. The page is the task, the tools and the log of what the model saw and did; the loop is a library hook you can read and replace:

export default function Main({ task }) {
  const log = useLog();
  useLoop(log); // ask the model, run its calls, repeat
  const { shell } = machineTools(harness.machine.get("home"));
  /** Give your final answer. This ends the task. */
  function answer({ text }: { text: string }) {
    harness.stop({ answer: text });
    return "done";
  }
  return <ModelContext strategy="unrolled" log={[{ kind: "input", content: task }, ...log.records]}>
    <Tool fn={shell}>{"[shell] "}</Tool>
    <Tool fn={answer}>{"[answer]\n"}</Tool>
  </ModelContext>;
}

Or serve an app over HTTP. views/demo/memory_server puts a chat model with a memory longer than its context behind an OpenAI-compatible endpoint:

affordance serve views/demo/memory_server   # then point any OpenAI client at http://127.0.0.1:8000/v1

Or drive one from a frontend over stdio. views/demo/host is a coding chat that streams its replies, asks before each command, and stops a turn on Escape ({"type":"abort"}):

affordance host views/demo/host   # JSON lines: {"type":"prompt","text":"..."} in; deltas, output, questions out

Getting started walks through it; examples has more.

Learn more

Status

v0.1 beta. Developed on Linux; macOS support is new and less exercised (platform evidence). Template conformance is evidence from a finite test corpus, not a guarantee for arbitrary input.

License

Affordance's own code is licensed under Apache-2.0.

The files under views/third_party/ are different. Each is a model publisher's chat template, converted so that prompts for that model come out in its format, or prose that a template carries (a default system message, a tool-call instruction). They are included for interoperability and stay under their publishers' terms, which are not all Apache-2.0: some are non-commercial, some are for research, and one is not stated. Every folder has a NOTICE.md that names the model, the revision the text was read at and its license. A publisher who wants a template removed can open an issue and it will be removed.

Code ported from other projects is listed in third-party notices.

Metadata

Release files for affordance 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for affordance 0.1.0
File Actions
affordance-0.1.0-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details for affordance-0.1.0-py3-none-manylinux_2_28_x86_64.whl
affordance-0.1.0-py3-none-manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64 Details for affordance-0.1.0-py3-none-manylinux_2_28_aarch64.whl
affordance-0.1.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for affordance-0.1.0-py3-none-macosx_11_0_arm64.whl
affordance-0.1.0-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details for affordance-0.1.0-py3-none-macosx_10_12_x86_64.whl

Total release size: 35.4 MB

Release files / affordance-0.1.0-py3-none-manylinux_2_28_x86_64.whl

Download URL affordance-0.1.0-py3-none-manylinux_2_28_x86_64.whl
Size 9.1 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
fbe58cd16c64a69e41c0e9aa96440b27634470ee5de7b836f03b92d1b30d2b0e
BLAKE2b-256 checksum
How to use checksums
b6fd3832b4aad1f6898c5a6f31a019f8c947cda5c68f401c408416e87447d241
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / affordance-0.1.0-py3-none-manylinux_2_28_aarch64.whl

Download URL affordance-0.1.0-py3-none-manylinux_2_28_aarch64.whl
Size 9.0 MB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
e6df6c3fb40c985a798db43eefc4234430246d58069867fb82b372d00145562c
BLAKE2b-256 checksum
How to use checksums
ec90e158299ff8a9a826a4d6828b26d62c66f8c94fcfa3692fb3200774760d2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / affordance-0.1.0-py3-none-macosx_11_0_arm64.whl

Download URL affordance-0.1.0-py3-none-macosx_11_0_arm64.whl
Size 8.5 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
782daed77345973e58a315d3ae4eae542d064a0630ac077aa66ee1d994ad7b69
BLAKE2b-256 checksum
How to use checksums
fc59d66d0b689c17acbb4c2bce38ef16c25c3a656713935406ef7643dc51228b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / affordance-0.1.0-py3-none-macosx_10_12_x86_64.whl

Download URL affordance-0.1.0-py3-none-macosx_10_12_x86_64.whl
Size 8.8 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
e49f37ac3f56ad6b35469035016cdef4b4f5e0614aee2a83c91ffb78acca0a0c
BLAKE2b-256 checksum
How to use checksums
2b7ba2d7434cd533a9347891337593cf7fd82fef6db7c906b608652a91919914
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for affordance 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for affordance-0.1.0-py3-none-manylinux_2_28_x86_64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page