Server tools vs runtime tools
A tool can run in two places. In your backend, while the model writes its answer, so the values end up written into the UI as a snapshot. Or in the browser, after the UI renders, so the data stays live and changes without asking the model again. Same tool, very different interface.
By the end of this lesson you can
- trace a server tool call and a runtime tool call from the user's question to the pixels;
- say which one gives a snapshot and which one gives live data, and what a refresh costs in each;
- explain how the model learns about each kind of tool, and which prompt wording each setup needs;
- choose server tools, runtime tools or both for a given screen.
One tool, two places it can run
Take one tool, get_weather, defined once in your backend. A server tool runs during the model's turn: the model asks for it, your API runs it, the result goes back to the model, and the model writes OpenUI Lang with the numbers typed in. A runtime tool runs after the model has finished: the model writes a Query statement that names the tool, and the browser's Renderer calls it through its toolProvider. OpenUI's docs call these agent-side and UI-side tools.
The same question, two places to run the tool
- The user asks for the weather in Pune. In both setups the browser sends the question to your API, which calls the model with the system prompt. On the left the request also carries tool definitions the model can call; on the right the prompt carries an
## Available Toolssection the model can write calls for. - Server tool: the model stops mid-turn and asks for
get_weather({city: "Pune"}). Your API runs it and hands the result back. Runtime tool: the model never sees any weather. It writesQuery("get_weather", {city: $city}, defaults)and finishes. - Server tool: the model writes the UI with
31and"Thunderstorm"typed into it. Runtime tool: the Renderer reaches theQuery, callsget_weatherthrough itstoolProvider, which POSTs to your API, and draws the result. - The user wants Tokyo instead. On the left nothing on screen can change: the user asks again, and the whole turn repeats (model call, tool call, a new program). On the right
$citychanges, the Query's arguments change, and the browser fetches again. The model is idle. - The difference in one line: a server tool gives a snapshot fixed at answer time; a runtime tool gives live data that follows the UI's state. You can use both in one answer.
| Server tool (agent-side) | Runtime tool (UI-side) | |
|---|---|---|
| Who runs it | Your backend, during the model's turn | The browser's Renderer, through toolProvider, after the program arrives |
| How the model learns it exists | Your agent framework's tool definitions (for example AI SDK tools) | The ## Available Tools section of the OpenUI system prompt, built from ToolSpecs |
| What the response contains | The values, written into the program | A Query or Mutation statement, plus defaults |
| Fresh data costs | A new model turn | One function call, no model |
| Where the implementation and keys live | Your server | Your server too: the browser only calls your API |
| OpenUI-specific setup | None | Tool specs in the prompt, and a toolProvider on the Renderer |
Both kinds can come from one registry. This repo's reference code defines each tool once and derives three consumers from it: the prompt's tool list, the endpoint the browser calls, and the server-side tool the model can call mid-turn.
Step through three setups
Pick a scenario and step through it. The bottom panel keeps a running tally: how many model turns, how many tool runs on the server, how many tool calls from the browser, and whether what is on screen is a snapshot or live. The weather values come from this course's simulated get_weather.
Things to look for
- In server tool, the tool result goes into the model's context, and the program on the wire contains
31.4. Asking about Tokyo costs a second full turn. - In runtime tool, the program on the wire contains no weather at all, only
Query(...)and defaults. After the program arrives, the model lane goes quiet. - In both, the sentence the model wrote is a snapshot (it compares Pune and Tokyo as they were), while the card below it is live. Change the city and the card moves on; the sentence does not.
A baked card and a live card
Two recorded answers to the same question, rendered side by side by the course's simulator. The left one was written after a server tool call, so the weather is part of the program text. The right one was written with a runtime tool, so the program holds a Query bound to $city. Type a city below. The field sets $city in the live card, exactly as an Input bound to $city would; this page waits until you pause typing.
Baked: server tool
Model turns: 1 · server tool runs: 1 · browser tool calls: 0
Live: runtime tool
Model turns: 1 · server tool runs: 0 · browser tool calls: 0
Simulated: no model is called and the tool is an in-page function with a short delay. The cards are drawn by a teaching subset of @openuidev/react-lang; the real Renderer draws them with React.
Break it
Predict first. Tick Render the live card with toolProvider={null}. What does the live card show, and which error do you get?
What should happen
The card shows its defaults (an empty city and 0°) and there is no error at all. With no provider, the query manager never fetches: Query keeps its defaults and Mutation does nothing, silently. That is the real behaviour of @openuidev/lang-core 1.0.1, and it is the trap the chat lesson fixes: the stock chat message renders without a toolProvider. A provider that exists but lacks the tool is different: then you get tool-not-found. Now untick it and clear the city field: the tool rejects an empty city, and the live card reports a tool-error while the baked card, which never calls anything, stays as it was.
What the prompt has to say
The model learns about the two kinds of tool from two different places, and the system prompt has to describe the setup you actually have. When you pass tools to library.prompt({ tools }), the generated prompt gains the Query, Mutation and Available Tools sections. It also gains a ## Data Workflow section whose first step is:
1. FIRST: Call the most relevant tool to inspect the real data shape before generating code
That step assumes the model can call tools during its turn, which is only true when you also give it server tools. So each setup needs a sentence or two of its own, added with additionalRules in PromptOptions (they are appended after ## Final Verification). In plain terms:
- No tools at all. Tell the model it has no data tools: it must never invent live data such as the weather, and should say the data is unavailable instead.
- Runtime tools only. Tell it that it cannot call tools while writing; it writes
QueryandMutationstatements that the browser runs, and uses the output shapes from Available Tools as defaults. Tell it to bind user-editable arguments (a city, the units) to$variablesand never to hardcode the data. - Both. Describe the two ways: call a tool now, on the server, when it needs the data to decide what to say; write
QueryorMutationso the UI fetches live. Then say which to prefer: the live form whenever the user may change the inputs or edit records.
Key idea
Server tools are invisible to OpenUI: they are ordinary agent tools, declared and run by your framework, and the model sees their results. Runtime tools are visible only to OpenUI: the model sees their name and schemas in the prompt, never their results, and the browser does the calling.
OpenUI rule
Treat a runtime tool's arguments as untrusted. The model chose them and the call comes from the browser, so your tool endpoint validates them like any other client request.
Choosing
OpenUI's docs boil it down to one question: does the user need the data to change without asking the agent again? If a snapshot is enough (an answer, a summary, a one-off lookup) use a server tool. If the user will filter, refresh or edit in place (a dashboard, a filterable table, a form that writes) use a runtime tool. Most agents start with server tools and add runtime tools for the screens people keep working in. Sort these:
- "Summarise last quarter's revenue" answered with one chart. A snapshot is the answer. Nobody will change the quarter in place; a follow-up question is fine.
- A ticket table the user filters by priority. Each filter change should be one function call, not a model turn: Query bound to a $variable.
- A form that creates a calendar event. A write the user triggers: a Mutation fired by @Run when they click.
- "How is the Acme account doing?" The agent must first work out which account is meant, then show its metrics with a changeable date range. Server tool to resolve the account while deciding what to say; a Query on that account's id for the live dashboard. This is the docs' own example of using both.
- Check which columns a dataset has before deciding what chart to draw. The model needs the data to decide what to write. Only a server tool puts data in front of the model.
- "Is it warmer in Pune or Tokyo?", and the user wants to try other cities afterwards. The comparison sentence needs the data now (server tool); the card for further cities should be live (runtime tool).
Common misconception
"Runtime tools put my API keys in the browser." They do not. The browser calls your endpoint, which holds the keys and calls the upstream API. What runtime tools do expose is that endpoint: anyone with the page can call it with any arguments, so it needs the same authentication, authorization and rate limits as the rest of your API.
Quick check
The model answered with a weather card after calling get_weather on the server. The user wants the same card for Tokyo. What has to happen?
How does the model learn that a runtime tool exists?
A generated dashboard uses Query, but the Renderer was given no toolProvider. What does the user see?
tool-not-found appears only when a provider exists and lacks that tool.Recap
- A server (agent-side) tool runs in your backend during the model's turn; the model sees the result and writes it into the program. The UI is a snapshot, and fresh data costs a new turn.
- A runtime (UI-side) tool runs from the browser through
toolProviderafter the program arrives; the model only writesQueryorMutation. The data stays live, and a$variablechange re-fetches with no model. - The model learns server tools from your framework's tool definitions and runtime tools from the prompt's Available Tools section. Add
additionalRulesthat match your setup: no tools, runtime only, or both. - One question decides: does the user need the data to change without asking again? Use both when the model needs data to decide what to say and the user needs it live afterwards.