Connecting a model
Everything on this site so far has been the runtime being sure. It reads a plan, weighs it, judges it, applies it, records it — and none of that involves guessing about anything.
There is exactly one step that guesses, and it is the first one: turning "add a closing line to the end of this page" into a list of operations. This page is about putting a real language model in that slot — what it gets shown, what it is allowed to say back, what that costs, and what to do when it fails.
Hello from a tree
Nothing here was written as markup.
Every one of these goes through the same pipeline a model’s answer would: interpreted, analysed, weighed, judged, applied, appended. The log is real and it is in this tab — reload the page and the example is back as it was.
show the treehide the tree
{
"kind": "element",
"id": "n_firsttree5",
"type": "loom.page",
"props": {
"fills": true,
"width": "readable",
"loom:theme": {
"palette": "minimal",
"fontPack": "minimal-sans",
"stylePreset": "precise"
}
},
"children": [
{
"kind": "element",
"id": "n_firsttree2",
"type": "loom.heading",
"props": {
"level": 1
},
"children": [
{
"kind": "text",
"id": "n_firsttree1",
"value": "Hello from a tree"
}
]
},
{
"kind": "element",
"id": "n_firsttree4",
"type": "loom.prose",
"props": {},
"children": [
{
"kind": "text",
"id": "n_firsttree3",
"value": "Nothing here was written as markup."
}
]
}
]
}The box above is doing every step except the guess. Read on and you can see the exact request the guess would have been.
The slot, and what goes in it
An interpreter is an interface with one method:
import type { EditIntent, InterpretationError, LoomTree, ProposedChange, Result } from "@jam-overture/loom"
type ChangeInterpreter = {
interpret: (intent: EditIntent, tree: LoomTree) => Promise<Result<ProposedChange, InterpretationError>>
}
A sentence and a page go in; a proposal or a reason comes out. Nothing else in the runtime knows what is behind it. That is not a small property — it is what lets the Gate, the log and every test in this repository run without a network.
Loom ships one implementation, modelInterpreter, and it is deliberately not
wired to a vendor. It takes a ModelClient: one method, one request, one reply.
The Anthropic adapter is the only file in Loom that knows a specific vendor
exists, and it lives behind its own entry point so a host that brings its own
model never loads it.
import Anthropic from "@anthropic-ai/sdk"
import { dataCatalogue, modelInterpreter, randomIdFactory, systemClock } from "@jam-overture/loom"
import { anthropicModelClient } from "@jam-overture/loom/anthropic"
import { catalogueOf } from "@jam-overture/loom/sdk"
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY })
export const interpreter = modelInterpreter({
client: anthropicModelClient(anthropic.messages),
idFactory: randomIdFactory,
clock: systemClock,
catalogue: catalogueOf(registry),
themeCatalogue: themes.catalogue(),
dataCatalogue: dataCatalogue(sources),
})
That object is a ChangeInterpreter. It goes into the runtime you already have,
in the slot the preset was in, and nothing downstream changes.
Three of those arguments are the interesting ones
catalogue, themeCatalogue and dataCatalogue are all optional, and leaving
any of them out is legal and usually wrong. Each one is a list of names your
deployment is willing to be asked for, and the model can only name what is on
them.
Without catalogue the model is told nothing about what your deployment can
build with, so the only primitives it knows are the ones already on the page.
Without themeCatalogue, "make it warmer" has nowhere to go: the tree names
one palette and nothing says another exists, so the model either leaves it alone
or invents an id that fails to resolve. Without dataCatalogue, "put our
services here" has the same problem one floor down — a model can tell that a
node is able to ask a question and cannot tell which questions you answer, so it
names a source you never registered and the seam refuses it.
Give it all three, and it is choosing from lists you wrote.
A model you host yourself
You do not have to send your readers' pages to a company. The slot above takes anything with that one method, and one of the things that fits is a server you run yourself — on your own machines, or on a rented one with an open model already loaded.
Most of those servers answer the same shape of request, because they copied it from one another: vLLM, llama.cpp's server, Ollama, and the hosted services that serve open models the same way. Loom publishes an adapter for that shape behind a door of its own, and the swap is still one argument.
import { dataCatalogue, modelInterpreter, randomIdFactory, systemClock } from "@jam-overture/loom"
import { openAiCompatibleModelClient } from "@jam-overture/loom/openai-compatible"
import { catalogueOf } from "@jam-overture/loom/sdk"
export const ownModelInterpreter = modelInterpreter({
client: openAiCompatibleModelClient({
endpoint: "https://models.example.com/v1",
apiKey: process.env.OWN_MODEL_KEY,
fetch,
}),
model: "llama-3.3-70b-instruct",
idFactory: randomIdFactory,
clock: systemClock,
catalogue: catalogueOf(registry),
themeCatalogue: themes.catalogue(),
dataCatalogue: dataCatalogue(sources),
})
Two things about that call are worth saying out loud.
It is handed fetch rather than a client library. There is nothing to
install for this door, which is the small reason. The large one is that a model
server's address is configuration — somebody types it — and an address somebody
types can point at your own network as easily as at the internet. An adapter
that brought its own networking would be deciding, on your behalf, what that
address is allowed to reach. This one asks you. Loom's own portal hands it a
fetch that refuses private, loopback and link-local addresses and checks again
after the name resolves, which is the shape of guard to copy if the address came
from somebody else.
The model's name is yours and nothing checks it. Nothing in Loom knows what
an open model is called, so model is a string your server understands, passed
through untouched. It is the one field of the request that differs between the
two doors.
What goes over the wire
The same request. Not a similar one — the same one, in a different envelope:
POST https://models.vaughan-rill.example/v1/chat/completions
redirect: error — a server that redirects is answered as one that refused, never followed
{
"model": "llama-3.3-70b-instruct",
"max_tokens": 16000,
"messages": [
{
"role": "system",
"content": "… 2,816 characters of standing instructions"
},
{
"role": "user",
"content": "… 28,363 characters of vocabularies, then the page, then the sentence"
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "loom_reply",
"schema": {
"…": "3,381 characters of reply schema"
},
"strict": true
}
}
}The adapter posted that as this page built, with the page answering in the
server's place. The six blocks below are all inside the one user message; the
standing instructions are the system message; the reply schema rides along as
the response_format a server of this kind constrains its answer to.
One field of the request never appears in it. How hard the model should think has no spelling that every server of this kind honors, so the adapter does not send it. A translation that invented one would be writing a field some servers ignore and others reject, and the first a host would hear of it is a failed call.
The address is https and a redirect is a refusal. Not a setting — the
adapter passes redirect: "error" on every call, so a server that answers with
"ask over there instead" is reported as a server that did not answer, rather
than quietly followed to an address nobody configured.
What comes back, and what your reader is left with
A server you run has more ways to not answer than a service does, precisely because you are running it. Here is every one of them, with the same page answering in its place:
| What the server did | Status | The adapter reports | Your reader’s page gets |
|---|---|---|---|
| answered, and said which model served it | 200 | a completion | a proposal, 1 operationrecorded as served by llama-3.3-70b-instruct-awqnaming n_firsttree5, a node of the tree above |
| answered, without saying which model served it | 200 | a completion | a proposal, 1 operationrecorded as served by llama-3.3-70b-instructnaming n_firsttree5, a node of the tree above |
| the model declined to answer at all | 200 | refused | refused |
| the server's own content filter stopped the reply | 200 | refused | refused |
| the reply hit the server's output ceiling mid-sentence | 200 | incomplete | malformed-proposal |
| answered 200 with something that is not a chat completion | 200 | incomplete | malformed-proposal |
| too many requests at once | 429 | unavailable | interpreter-unavailable |
| the key was not accepted | 401 | misconfigured | interpreter-misconfigured |
| no model of that name on this server | 404 | rejected | interpreter-request-rejected |
| nothing answered — the address did not resolve | nothing | unavailable | interpreter-unavailable |
Each row is two real calls on the same answer: one through the adapter alone, for the middle column, and one through a whole interpreter, for the last. Three things in that table are worth more than the rest.
The two rows that worked differ only in the name. A server that says what
served the request is recorded under that name — llama-3.3-70b-instruct-awq is
the build that actually answered, not the one that was asked for — and a server
that says nothing is recorded under the name you asked by. Neither is a guess
the runtime made: the first is the server's own word and the second is the only
name anybody involved knows, and which one you got is a thing your log can tell
you afterwards.
An open model that cannot hold to the reply schema is a malformed answer, not a refusal. That is the failure mode to expect from a smaller model, it is the third and fourth rows, and it costs something: the reply gets the one repair attempt any bad reply gets, your server is billed for both attempts, and nothing reaches your readers.
The last row is the one this page would like to be wrong about. A model name your server does not have comes back as a 404; the rule that reads a status — shared by both adapters, so that a 429 means the same thing whichever door it came through — reads any other 4xx as the request itself was refused, and the runtime attributes a refused request to itself. So a mistyped model name is reported in your logs as the runtime's fault rather than as a thing you typed. It is wrong, it is filed, and it is what the code does today.
What the model is actually shown
Not a screenshot, and not your JSX. Six blocks of plain text, in this order — generated below from the same functions the runtime calls, against the same registries the example above renders through, for the sentence on its first chip:
The standing instructions
The same words on every request, so a provider's cache can hold them and so what Loom asks for is one string somebody can read.
You translate a request about a user interface into discrete edits to a component tree.
The tree is given as an indented outline. Every line starts with a node id. There are three node kinds:
- element — an instance of a primitive, with props and ordered children
- text — a leaf string
- slot — a named region whose children are fallback content
… 24 more linesWhat it may build with
Your registry, one line each. A model cannot invent a primitive because it is never shown one it does not have.
- loom.page — The root of a page. Mounts the theme and stacks its children in one column. props: fills?, width?
- loom.nav — The bar across the top of a page: a brand region, loom.link children as the menu, and an actions region. props: align?, position?, tone? slots: brand, actions
- loom.menu — A run of loom.link behind one button, dropped over the page — the nested menu in a header or the folded column in a footer. props: align?, label?, placement?
- loom.banner — The announcement strip above a page: a short message as children, and a region for the one thing to do about it. props: align?, label?, tone? slots: action
- loom.section — A band of the page: an optional heading region above its content. props: align?, anchor?, eyebrow?, tone?, width? slots: heading
- loom.split — Two side-by-side regions, start and end, that stack when the page is narrow. props: align?, ratio?, reverse?, stick? slots: start, end
… 103 more primitivesWhat it may theme with
Palettes, font packs and style presets by id and description — never a color, which is the whole of the theming bargain.
Palettes:
- minimal — Minimal. White paper, black ink, one green. Components are outlined rather than filled; the green appears only as rules, rings and tinted marks.
- editorial — Editorial. Restrained, high-contrast magazine palette with a single muted accent.
- bold — Bold. Black canvas with bright yellow and red accents. High-energy, graphic.
- paper — Paper. Warm ivory with a terracotta accent. A printed page rather than a screen.
- slate — Slate. Cool grey with an indigo accent. Restrained, technical, quiet.
… 48 more linesWhat it may ask about
The sources this deployment registered, and the one instruction that turns a binding from a guess into a choice from your list.
- catalogue.services — What this shop offers, most popular first. params: limit, tag - profile.field — One field of the shop's own profile, by name. params: field - shop.opening-hours — When the shop is open, a line per day. params: none - catalogue.classes — The classes this shop is running next, soonest first. params: limit
The page as it stands
The tree above, as an indented outline. Every line begins with the node id an operation would have to name.
tree t_firsttree1 revision 0
n_firsttree5 element loom.page fills=true loom:theme={"palette":"minimal","fontPack":"minimal-sans","stylePreset":"precise"} width="readable"
n_firsttree2 element loom.heading level=1
n_firsttree1 text "Hello from a tree"
n_firsttree4 element loom.prose
n_firsttree3 text "Nothing here was written as markup."What was asked
The sentence somebody typed, and who was doing the typing.
Request (user-instruction): Add a closing line to the end of this page.
Five things are worth noticing before the detail.
The page is an outline, and every line starts with an id. That is the whole
addressing scheme. An operation says remove n_firsttree2, and it can only do
that because the model was handed that id and told to copy it exactly.
The instructions are a constant. The same words on every request for every tree, which is why they sit at the front where a provider's cache can hold them, and why "what are we asking the model to do" is a string you can read rather than a template you have to reconstruct.
Your registry is the vocabulary, stated in full. A model cannot propose
marquee.blink because it has never been shown one. This is the bounded
vocabulary bargain doing its work in the most literal way it ever does.
No colors appear anywhere. Themes are given as ids and the sentence their author wrote about each. A model choosing between your registered palettes is the deal; a model choosing hex is the thing that deal rules out.
What your deployment can be asked about is a list as well, and it is the shortest block with the longest instructions. The lines in that block are every source this site registered — the shop from Where the content comes from, which is the only data vocabulary it has. Most of that block is not the list, though. It is the paragraph after it, because a list of ids can show a model which sources exist and cannot show it the two further ways a binding goes wrong: params the source never declared, and a binding name no primitive on the node reads, which is answered and then read by nobody.
What it is allowed to say back
The reply is constrained to a JSON schema, and the schema is narrower than the tree model in three ways that all matter:
- An inserted node carries no id. Identity is minted by the runtime, always. A model that could name a new node could collide with an existing one, and the provenance of an id would stop meaning anything.
- Props arrive as a JSON-encoded string rather than a typed structure — and nothing is trusted about the contents. They are parsed, required to be an object, and checked value by value before anything reaches a tree.
- Only elements and text can be inserted. A slot is a region a primitive declares, not content an edit adds.
The reply is also a three-way outcome rather than a delta: change,
no-change, or not-understood. "I understood you and nothing needs
changing" is an answer, not a failure to answer, and conflating the two would
make every satisfied request look like a broken one.
Why the props are a string, which looks like a mistake
Structured output compiles a schema into a grammar, and the grammar has a size ceiling. A typed prop union repeated at every element at every level put the schema four times over that ceiling, which meant no live call ever succeeded. Encoding props as one string costs the grammar a single production however many props there are, and buys back the nesting depth.
The margin is not generous, and it is measured rather than assumed. The reply schema is capped at a nesting depth of 4, which compiles to 3,381 bytes against a budget of 3,500. Depth 5 would be 3,818, and over.
What one request costs
measurePrompt answers this without sending anything, which makes "what did
registering another twenty primitives cost me" a number instead of a feeling:
| Block | Characters | Share |
|---|---|---|
| The standing instructions | 2,816 | 9% |
| What it may build with | 20,175 | 65% |
| What it may theme with | 6,155 | 20% |
| What it may ask about | 1,595 | 5% |
| The page as it stands | 367 | 1% |
| What was asked | 71 | 0% |
| One request, with 109 primitives, 51 theme ids and 4 sources registered | 31,179 | 100% |
| The same request, with nothing registered | 3,254 | 10% |
The reader's question — the page and the sentence they typed — is under two per cent of the request. Everything else is the vocabulary this deployment chose to offer, and it is re-sent on every proposal and again on every repair.
That is not an argument for registering less. It is an argument for knowing the number, and for putting the stable blocks at the front where a cache can hold them, which is where they already are.
When it fails, and who has to do something
A guess can fail in seven ways. A host that switches on seven codes has to hold all of them in its head and can still get the grouping wrong, so the runtime answers the question that actually matters first: who would have to do something for the next attempt to go differently.
- asker
- Nothing failed except the asking. Say it differently.
- model
- The answer that came back. The same question may work on a second try.
- provider
- The service, this time. Waiting is a reasonable response.
- deployment
- Your deployment, until somebody changes it. Waiting never fixes this one.
- runtime
- Loom, for what it sent. Neither waiting nor configuration helps.
| Code | Whose | What the runtime says |
|---|---|---|
| not-understood | asker | the request was not understood: "make it pop" could mean the heading, the accent or the spacing |
| no-change-needed | asker | nothing needed to change: the heading is already the largest thing on the page |
| malformed-proposal | model | the model's answer could not be used: operations.0.parentId: not a node id |
| refused | model | the model declined to answer: the model's own safety policy declined |
| interpreter-unavailable | provider | the model could not be reached, and may answer later: the request timed out |
| interpreter-misconfigured | deployment | this deployment cannot reach a model until an operator changes that: no API key was configured |
| interpreter-request-rejected | runtime | the model service rejected the request, and would reject it again unchanged: the output schema exceeded the grammar budget |
Two of those clear on their own. Three of them never do, however many times you
retry. Notice what is deliberately not here: there is no retryable flag.
Whether to resample a bad answer is a policy, and a host that resamples
malformed replies and refuses to resample anything else is making a reasonable
choice the runtime should not have made for it.
A second go
A model can be told its proposal was refused and asked to try again more
conservatively. That is a separate interface, ChangeRepairer, and a runtime
handed no repairer cannot repair — so "this deployment lets AI have a second
attempt" is a visible choice where you compose things, rather than a property of
whichever interpreter you happened to wire in.
modelInterpreter implements both, so you can offer it or not. A repair sends
the whole request again plus the refused delta and the Gate's objection, so it
costs about twice what the table above reports.
The one rule the repair prompt insists on is worth reading even if you never turn it on: a revision must be a more conservative way to satisfy the same request — smaller in what it destroys, or narrower in what it touches. It must not be the same change split into a piece small enough to slip through, with the remainder asked for again.
What this site is running, and why it matters
Every chip in every box on this site is a deterministic interpreter. It computes its operations from the tree in front of it rather than guessing them.
That is not a mock. It is a real implementation of the same interface, it
re-plans against the page as it stands, it can decline, and everything after it
— the analysis, the stakes, the Gate, the log — cannot tell the difference and
is not told. Its provenance says authoredBy: "runtime" and a confidence of
1, because a computed delta is not a guess and a confidence nobody graded must
not walk into calibration as a model's perfect record.
It is what makes this site possible: dozens of examples that must behave identically on every visit is not a thing to point at a model, and a documentation site whose examples only worked when somebody had configured an API key would be broken for everyone who cloned the repository.
The swap is one argument. Everything you have read on this page, and every verdict you have seen on the others, is what happens on the other side of it.