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 checkcompares 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: restore 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 restore, 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:
cargo install affordance
Or run it without installing anything, with uv (Python's package
runner): put uvx in front of each affordance command below, as in uvx affordance render.
Save the app above as hello.tsx and render it. This needs no model:
echo '{"name":"world"}' | affordance render hello.tsx --state -
ids [15496, 11, 995, 0, 685, 70, 2871, 60]
text Hello, world! [greet]
span 0..4 label greeting
span 4..8 affordance greet
span 4..8 action greet(name)
span 0..8 box
The first four token IDs are the greeting and the last four are [greet]. The spans say what
each range is: IDs 4 to 8 are the greet action, which the model can call as a tool with a
name. With no --tokenizer, render uses GPT-2's.
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 --restore # 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>;
}
The other examples are in this repository:
git clone https://github.com/approximatelabs/affordance && cd affordance
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":"event","name":"user","payload":{"text":"..."}} in; deltas, output, questions out
Getting started walks through it; examples has more.
Learn more
- Writing and running agents
- The language and layout
- Instances, effects, storage and replay
- Model bindings
- Conversation and context libraries
- Pictures, sound and video
- Fetch, HTTP and MCP
- Embedding the engine in Rust
- Why it is shaped like a browser: where the line between engine and app is, and why
- Architecture, development and contributing
Status
v0.2 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.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| affordance-0.2.0-py3-none-manylinux_2_28_x86_64.whl | Python 3 | none | Linux glibc 2.28+ x86-64 | Details for affordance-0.2.0-py3-none-manylinux_2_28_x86_64.whl |
| affordance-0.2.0-py3-none-manylinux_2_28_aarch64.whl | Python 3 | none | Linux glibc 2.28+ ARM64 | Details for affordance-0.2.0-py3-none-manylinux_2_28_aarch64.whl |
| affordance-0.2.0-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details for affordance-0.2.0-py3-none-macosx_11_0_arm64.whl |
| affordance-0.2.0-py3-none-macosx_10_12_x86_64.whl | Python 3 | none | macOS 10.12+ x86-64 | Details for affordance-0.2.0-py3-none-macosx_10_12_x86_64.whl |
Total release size: 35.7 MB
Release files / affordance-0.2.0-py3-none-manylinux_2_28_x86_64.whl
| Download URL | affordance-0.2.0-py3-none-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 9.2 MB |
| Tags | Linux glibc 2.28+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
12d3910a860d89d670b74edd56773e1b8326805b90beba6597ef6dbccfe80f2a
|
|
BLAKE2b-256 checksum How to use checksums |
f657cacbab9620a0f29f8760d63163cebb762ddf4a1de748d4bb85bfc822b828
|
| 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 24, 2026.
Transparency logRelease files / affordance-0.2.0-py3-none-manylinux_2_28_aarch64.whl
| Download URL | affordance-0.2.0-py3-none-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 9.1 MB |
| Tags | Linux glibc 2.28+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
176be9a1a07e9a2d27eb85e309fc525242cc8249a26cfa97ff4d7a57042eddb6
|
|
BLAKE2b-256 checksum How to use checksums |
804d3da3ae0a8f396506e7eafd442a848b1c82859b163c97ad5a1624ebbb2103
|
| 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 24, 2026.
Transparency logRelease files / affordance-0.2.0-py3-none-macosx_11_0_arm64.whl
| Download URL | affordance-0.2.0-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 8.6 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
487254044b75df825c55cce1d89f8c7e3ba085904cd010bc9d3c8e15e06dc4aa
|
|
BLAKE2b-256 checksum How to use checksums |
cc0daafb0b5f00f97819b896625839a4cc5381518dfd44a5d137c6b1d5eb2b59
|
| 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 24, 2026.
Transparency logRelease files / affordance-0.2.0-py3-none-macosx_10_12_x86_64.whl
| Download URL | affordance-0.2.0-py3-none-macosx_10_12_x86_64.whl |
|---|---|
| Size | 8.9 MB |
| Tags | Python 3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
0f432464a5fdeed934b74020a38cdb9ab7202d069e194ce4ef4d47bff474f22e
|
|
BLAKE2b-256 checksum How to use checksums |
8357a3725ac363ee8a1b090c5a9f72b884a8ee9d062c7296d2e35bb7aab7c3b6
|
| 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 24, 2026.
Transparency logSecurity for affordance 0.2.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.
Attestation for affordance-0.2.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 24, 2026.
Transparency logA 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.