# Affordance

> Open-source Rust engine that renders TSX apps into the exact token ids a language model reads and runs tool handlers when the model calls them.

Affordance is an open-source engine from Approximate Labs, written in Rust, that works as a browser for models. An app written in TSX is rendered into the exact token ids a language model reads, and the app's handlers run when the model calls one of its tools. It is currently a v0.1 beta under Apache-2.0 for Linux and macOS.

## What It Is

Affordance treats prompts as rendered output rather than strings. A web browser turns HTML into pixels and runs code on clicks; Affordance turns a TSX app into tokens and runs code when the model calls a tool. Apps are functions of state using React-style hooks (useState, useEffect, useRef), written in a documented subset of TypeScript and JSX that is interpreted in Rust, without React, Node or npm.

The project positions it as a replacement for Jinja chat templates and hand-written agent harnesses: the loop, tools, history rules and summarizing become short TSX files plus a token style sheet.

## How an App Works

An app's default export takes state as props and returns what the model should read. A `<Tool fn={...}>` element offers a function to the model, using the function's name, comment and argument type as the tool definition. A tool exists only where it is rendered. After a handler runs and updates state, the app re-renders.

Token style sheets (.tss) set budgets in tokens or context-window percentages, with rules such as max-tokens, overflow clipping and drop-step for dropping old history in steps. `ModelContext` applies a model's chat format, and `useLoop` calls the model and runs its chosen tools. The `affordance` CLI provides run, serve, host, init, render, test, lint and config commands.

## Models, Media and Serving

The project says chat formats for 740 models are included and were compared against the official templates and tokenizers; further models can be added with one command. Apps can pass pictures, sound and video to models whose formats support them. Exact tokens require a server that accepts token ids, such as SGLang or vLLM; with chat APIs the server applies its own template. `affordance serve` can expose an app as an OpenAI-compatible chat completions endpoint. Agent inputs are journaled so runs can be resumed or replayed.

## Current Status

The site describes v0.1 as a beta whose app API will change before 1.0. The language is a subset of TypeScript, and only Linux and macOS are supported. The project reports its own benchmarks, including first-token latency in forks of SGLang and vLLM and an RL training run, and notes they come from one machine and one or a few runs each.

## Features
- Renders TSX apps into exact model token ids
- Tools exposed via Tool component with handlers run on model calls
- Token style sheets with token budgets, overflow and drop-step history rules
- Chat formats for 740 models checked against official templates
- Image, audio and video input support
- Deterministic journaling, resume and replay
- Many agents in one process
- Serve any app as an OpenAI-compatible chat completions endpoint
- Runtime loading of TSX modules via loadModule
- Lint, render and test commands
- Cache-reuse diagnostics for prompts

## Integrations
SGLang, vLLM, llama.cpp, Ollama, OpenAI-compatible APIs, pi coding agent, Multiplet, MCP, Docker, SSH, bubblewrap

## Platforms
MACOS, LINUX, WEB, API, CLI

## Pricing
Open Source

## Version
v0.1.0

## Links
- Website: https://affordance.rs
- Documentation: https://affordance.rs/docs/index.html
- Repository: https://github.com/approximatelabs/affordance
- EveryDev.ai: https://www.everydev.ai/tools/affordance
