The protocol
Once the work lives in a daemon, every window is a separate program, perhaps in another language. They share no memory and no objects. All they share is what they write to each other. So what do they write, and how does a window that was closed for an hour catch up without missing a word, or seeing one twice?
The idea
In agents generally
A protocol is the agreement two programs keep when they talk. It answers five questions:
- Where does one message end? Bytes arrive in pieces, so the receiver needs a rule: a length in front, or a line break after. This is framing.
- What kind of message is it? Usually one of three: a request that wants an answer, the response to it, or a notification that wants none. A request carries an id, and its response carries the same id, so answers can come back in any order.
- What fields does it have? The shapes, written down in a schema, so both sides read the same names and types.
- What happens when the two sides change? A version, checked when they first connect.
- What does a window do after it was gone? It needs a way to ask for what it missed.
An agent's protocol has two directions with different jobs. Commands go from a window to the agent and ask: send this message, cancel that run, allow this tool. Events go from the agent to every window and tell what already happened: a token arrived, a tool finished, the run ended.
The second rule is what makes several windows work: an event is a fact, and the screen is built from the facts, in order. A window keeps no private story of the chat. If each event also has a number, a window that drops out asks for everything after the last number it has, and draws the same screen as one that never left. Sending every event to every window that follows a session is called fan-out.
How agents usually do it
The wire:
| Approach | How it works | Good at | Costs |
|---|---|---|---|
| Function calls | The window and the agent are one program, and call each other | Nothing to design | Only works in one process and one language |
| HTTP and server-sent events | A request per command, and a long response that streams events | Every language and tool speaks HTTP | Two channels, a port, and a login. Order between a reply and an event is not given |
| A WebSocket with JSON | One connection both ways, a JSON message per frame | Browsers speak it, both directions on one socket | Still a port and an HTTP upgrade, and each side invents its own envelope |
| JSON-RPC 2.0 over a stream | Requests, responses, and notifications in one envelope, over stdio or a socket. LSP frames each with a Content-Length header, and MCP's stdio with one line each | A small standard: ids, errors, and notifications already defined | Text JSON is bigger and slower than binary |
| gRPC and protobuf | A schema in .proto files, generated code, binary frames over HTTP/2 | Fast, typed, streaming built in | A toolchain on both sides, and a wire you can't read by eye |
The shapes:
| Approach | Costs |
|---|---|
| Written by hand on both sides | The two copies drift, and the bug shows up as a wrong screen |
| A schema, with types generated for each language | One more build step, which must run before a change is done |
| One language's types as the source, generated for the other | The source language decides what the schema can say |
The open problems are the same in every agent:
- Catching up. A window that drops out mid-answer must get the rest without a gap or a repeat.
- A slow window. One terminal that reads slowly must not slow the run, or the other windows.
- The token stream. A long answer is thousands of small events. Keeping all of them forever costs space, and dropping them costs the replay.
- Versions. A window and an agent from different releases must say clearly that they can't talk, not break halfway.
How golem does it
In golem
golem speaks JSON-RPC 2.0, one object per line, over the daemon's Unix socket. The shapes are Python classes, and just gen writes JSON Schema and TypeScript from them (ADR-003).
- Framing. Each message is one line of UTF-8 JSON, ended by
\n. JSON writes a line break inside a string as\n, so a message never contains one. A line over 1 MiB closes the connection. - The envelope. A command is a JSON-RPC request with an
id. Its reply has the sameid, withresultorerror. An event is a notification with methodevent, and noid. hellofirst. The client sends its protocol version. A different major number is refused, and any minor on the same major is accepted. Today it is2.78.- Events carry
seq. A rising number per session, from the event log, so it survives a restart. Each event is written togolem.dbbefore it is sent (Sessions). - Attach and replay. A connection gets a session's events only after
session.attachwithafter_seq. The daemon sends the stored events after that number, then the reply withlast_seq, then live events. One lock per session covers both, so no event lands in between (ADR-007). - Fan-out. Every connection attached to a session gets every event. Each connection has its own queue and writer, so a slow one never blocks a run, and one that falls 20 000 lines behind is dropped. It reconnects, and attaches from its last
seq. - One client.
@golem/clientis the only code that speaks the protocol, for the TUI,golem status, and the web UI. It sends apingevery 5 s, and after a reconnect attaches to each session again from its lastseq. - The browser. A web page speaks the same lines over a WebSocket to the gateway (
golem), which checks the token, theOrigin, and the method, and passes each line on unchanged (ADR-028).
Here is the real wire, recorded against a throwaway daemon with qwen3.5:4b. Connection A opens a session and asks a question. When its fifth token arrives, connection B says hello and attaches to the same session from the start. The ids are shortened, and long lines are cut with …:
0.000 A → {"jsonrpc":"2.0","id":1,"method":"hello",
"params":{"protocol_major":2,"protocol_minor":34,
"client":"tui"}}
0.001 A ← {"jsonrpc":"2.0","result":{"protocol_major":2,
"protocol_minor":34,"daemon_version":"0.0.0-dev"},
"id":1}
0.002 A → {"jsonrpc":"2.0","id":3,"method":"session.attach",
"params":{"session_id":"s_520d…","after_seq":0}}
0.002 A ← {"jsonrpc":"2.0","method":"event","params":
{"seq":1,…,"type":"session.created",…}}
0.002 A ← {"jsonrpc":"2.0","result":{…,"last_seq":1},"id":3}
0.002 A → {"jsonrpc":"2.0","id":4,"method":"message.send",
"params":{"session_id":"s_520d…",
"text":"In one sentence, what is a golem?"}}
0.180 A ← {"jsonrpc":"2.0","result":{"run_id":"r_6681…"},
"id":4}
6.038 A ← … seq 5 to 9, the first tokens
6.081 B → {"jsonrpc":"2.0","id":2,"method":"session.attach",
"params":{"session_id":"s_520d…","after_seq":0}}
6.083 B ← seq 1 to 9, the replay, in one burst
6.083 B ← {"jsonrpc":"2.0","result":{…,"last_seq":9},"id":2}
6.092 B ← {"jsonrpc":"2.0","method":"event","params":
{"seq":10,…,"type":"message.delta",
"data":{…,"text":" mythical"}}}
6.092 A ← the same line
6.453 A, B ← seq 42, message.completed: "A golem is a
mythical creature created by Jewish mystics
from inanimate materials…"
6.455 A, B ← seq 43, run.completedThe attach reply comes after its replay, and says where the replay ended. Everything after it is live. Seq 10 reached both connections in the same millisecond, and neither got an event twice.
A third connection shows what the daemon refuses:
C → {"jsonrpc":"2.0","id":1,"method":"session.list","params":{}}
C ← {"jsonrpc":"2.0","error":{"code":-32002,
"message":"hello required","data":null},"id":1}
C → {not json
C ← {"jsonrpc":"2.0","error":{"code":-32700,
"message":"parse error","data":null},"id":null}
C → {"jsonrpc":"2.0","id":2,"method":"hello","params":
{"protocol_major":1,"protocol_minor":0,"client":"old"}}
C ← {"jsonrpc":"2.0","error":{"code":-32001,
"message":"protocol major mismatch: client 1, daemon 2",
"data":{"client_major":1,"daemon_major":2}},"id":2}While the model loaded, A also got two model.server.status notifications, with no seq. The daemon sends those to every connection, attached or not.
Where it lives in the code:
packages/protocol/golem_protocol/: the shapes, incommands.py,events.py, andrpc.py, andversion.py.packages/protocol/gen/: the generated JSON Schema and TypeScript. Never edited by hand.packages/daemon/golem/server/framing.py:read_frame, one line at a time.packages/daemon/golem/server/dispatcher.py: the envelope,hello, the error codes, and each command run as a task.packages/daemon/golem/server/handlers.py: one handler per command.packages/daemon/golem/sessions/log.pyandsessions/bus.py:seq, attach, and fan-out.packages/client/src/connect.ts:connectGolem, the one client, overunix-link.tsorws-link.ts.
Why this way
JSON, not a binary format. Python and TypeScript both read it with no library. A person can read it too: in /debug wire, in a log, or by typing into nc. Its cost is size and speed, and neither is what limits an agent. In the trace, a token arrived every 11 ms, as a line of about 300 bytes. The model is the slow part, by far.
JSON-RPC 2.0, not an envelope of our own. It already says how an id pairs a reply with its request, how an error looks, and what a notification is. It is the same envelope LSP and MCP use, so golem's own MCP client speaks the same shape, and the error codes, such as -32700 and -32602, mean what they mean everywhere.
Lines, not length headers. A newline is the whole framing rule: the daemon reads with one readuntil(b"\n"), and a client splits on \n. JSON never puts a raw line break inside a message, so nothing needs escaping. LSP's Content-Length headers solve the same problem with more code on both sides.
One socket for both directions, not HTTP. A command, its reply, and the events all go through one queue per connection, so the order on the wire is the order they happened. HTTP with server-sent events would need two channels and a port. A port would need a login, and the socket's file mode already is one (The daemon). The WebSocket appears only where a browser needs it, at the gateway, and carries the same lines.
Not gRPC. Protobuf needs a compiler and generated code for both languages, and HTTP/2 under it. The golem command is one bun binary (ADR-019), and its wire would no longer be readable by eye. Its gains, smaller and faster messages, solve a problem golem doesn't have.
Events are facts, written first (ADR-006, ADR-007). The screen is a function of the events, so a replay is not a special mode: it is the same stream, read from a number. A second window, a reconnect, and a restart of the TUI all use it.
A queue per connection, and a limit. Writing to a socket from the place that emits an event would let one slow terminal stall the run. Waiting on a full queue would do the same. Dropping a client that falls 20 000 lines behind turns it into a reconnect, which the replay already handles.
Python classes as the source (ADR-003). The daemon reads every line into the same Pydantic class it was written from, so an unknown field or a wrong type is refused at the door. The TypeScript is generated from those classes, so the two can't drift, and just check fails if someone forgot just gen.
A major and a minor. Adding a command or an event bumps the minor, and an older client ignores what it doesn't know. Changing a shape, or which connection gets an event, bumps the major, and hello refuses the mismatch at once.
Try it
Open
golem tui, type/debug wire, and send a message. It lists the recent protocol lines in both directions, with pings hidden.Talk to the daemon yourself:
shhello='{"jsonrpc":"2.0","id":1,"method":"hello",' hello+='"params":{"protocol_major":2,"protocol_minor":34,' hello+='"client":"nc"}}' ask='{"jsonrpc":"2.0","id":2,"method":"daemon.status"}' { echo "$hello"; echo "$ask"; sleep 1; } \ | nc -U ~/.golem/run/golem.sockTwo lines come back: the
helloreply, and the daemon's status.Open
golem tuiin two terminals, and pick the same chat in/sessionsin the second. Send a message in one: both stream it.
The details
For contributors: the reference for the protocol's shapes, what is on the wire, and the error codes.
Why the daemon translates
The protocol exists so a client never has to understand the daemon's insides.
The graph library has its own message classes, and those classes change. If the TUI spoke those classes, every client would be tied to that library, and a reconnect would have no stable history to read. So the daemon translates. What crosses the socket is our messages only.
Two directions
Commands go from client to daemon. They ask for something: open a session, send a sentence, approve a tool, cancel a run, list flows.
Events go from daemon to client. They report something that already happened: a token arrived, a tool finished, a model was chosen, a run stopped.
An event is a fact. The client builds the whole screen from the facts, in order. The daemon writes every fact to the event log first. Replay is not a special mode: it is the same stream, read from the start or from the last number the client has.
hello is the first command. The client and the daemon compare protocol versions. A break in the shapes bumps the major number, and the daemon refuses the client. Any minor on the same major is accepted. The current numbers and what each minor added are in ADR-003.
A connection gets a session's events only after session.attach. Several connections can attach to one session, and each gets every event. The daemon holds one lock per session while it reads the replay and subscribes the connection, so no event lands in between. Each connection has its own outbound queue, so a slow terminal does not slow a run. A client that falls 20 000 lines behind is dropped, and it attaches again from its last seq.
Each event line is one JSON-RPC 2.0 notification. The fields that matter:
| Field | Meaning |
|---|---|
seq | A rising number for this session. It survives a restart and can skip numbers. The client uses it to ask for "everything after here". |
session_id | Which chat or flow |
run_id | Which execution, when a session can have more than one |
type | What happened, such as message.delta |
data | The payload for that type |
tool.writing says how far the model got writing a write_file or edit_file call, while the reply is still streaming: message_id, index (the call's place in the reply), name, path (null until the whole path is written), and lines and chars of the file text so far. It comes at most once a second per call, only from providers that stream tool calls, and golem.db deletes it when the reply's message.completed is written.
model.waiting says a chat call waits, or no longer waits, for its turn on a local model server: message_id and waiting. When the call loads the model again with a larger window (see context.changed with grew), it also sends model and window with waiting true, and the meter says loading <model> with a 64K window. Otherwise it is sent only for the call that waits, after it has waited more than a second, and never for a title or another internal job. golem.db deletes it when the reply's message.completed is written, and a client clears it at the first token or when the run ends.
branch.changed says the branch of a session's folder is not the one its model last heard of: from_branch, to_branch and paths_count (the files that differ, null when git could not say). The daemon reads the branch before each turn. When it changed, the model gets a note before that turn's messages (the new branch, a request to read a file again before editing it, and up to 50 paths from git diff --name-only), the log gets this event, and watchers get a new session.summary. It is sent once per change. SessionSummary.branch is the folder's branch, null outside a repo or when the head is detached.
tool.output works the same way for a running tool call: its rows are deleted when the call's tool.completed or tool.failed is written, which keeps a short preview.
message.delta is the live token stream. golem.db keeps the deltas only while the message is open. Writing its message.completed deletes them in the same transaction, so the database does not keep every fragment, and a reader that comes in mid-answer can still see the text so far. That is why seq skips numbers.
message.thinking.delta carries the thinking of a model that thinks, apart from the answer in message.delta. It is kept and dropped the same way: golem.db deletes the thinking deltas of a message when its message.completed is written. message.completed then has thinking (the whole text) and thinking_ms (from the first thinking fragment to the first answer fragment, or to the end when no answer text came). Both are null when the model did not think, and for a message written before they existed. When an answer's content starts with <think>, the daemon moves everything up to </think> into thinking (ADR-045).
message.completed has interrupted: true when the run stopped before the model finished. Its text is then what had streamed.
session.set_plan {session_id, on} puts one session in plan first, or takes it out, and answers {session_id, on}. The daemon stores session.plan.changed {on} (not run-scoped) unless the answer is the one the session has. The switch is kept with the session, so it survives a restart, and plan_first on a session summary says it. While it is on, the model is offered only the read-only and internal tools and propose_plan, and a call to any other tool is refused with plan first is on: this run only reads. End with propose_plan. before anything asks or runs. propose_plan ends the run with plan.proposed {plan_id, call_id, title, steps: [{text, files}]}, a run event stored in the log. A browser may call session.set_plan. Minor 78 adds all of this.
What is on the wire today
| Commands | Events |
|---|---|
hello, ping, daemon.status, session.create, session.attach, session.detach, session.list, session.rename, session.fork, session.close, session.set_skills, message.send, run.cancel, approval.respond, route.consent.answer, session.inspect, config.get, policy.update, policy.remove, session.revoke, auth.set, auth.remove, auth.list, model.list, session.set_model, session.set_route, session.compact, model.set_default, permissions.set_mode, model.probe, model.pull, model.pull_cancel, model.delete, model.score_reset, model.check, artifact.read, mcp.list, mcp.enable, mcp.disable, mcp.tools, mcp.restart, mcp.login, mcp.logout, mcp.set_enabled, mcp.add, mcp.remove, skill.list, setup.status, ollama.install, ollama.install_cancel, ollama.start, fs.list_dirs, git.info, git.branches, file.read, file.list, session.set_plan | session.created, model.selected, model.routed, message.started, message.delta, message.thinking.delta, message.completed, tool.requested, tool.writing, model.waiting, tool.started, tool.output, tool.completed, tool.failed, approval.needed, approval.resolved, route.consent.needed, route.consent.answered, todos.updated, skill.activated, skill.deactivated, skill.skipped, run.started, run.completed, run.failed, run.cancelled, session.updated, session.closed, session.completed, branch.changed; session.summary to watchers; model.pull.progress, model.pull.done, model.check.progress, model.check.done, model.options.saved, ollama.install.output, ollama.install.done, mcp.server.status, mcp.login.done, model.server.status, and skill.registry.changed to every connection |
After hello, a client sends ping every few seconds so a half-open socket is noticed. daemon.status returns the pid, uptime, and configured model, and the local model servers golem has used: who runs each one, and for one golem started its pid and memory. A new chat sends session.create with its cwd, then session.attach with after_seq 0, then message.send. session.list returns sessions newest activity first, each with idle, running, or waiting for an approval, its title, its folder (cwd), and its last seq. With cwd, it lists only the sessions in that folder; cwd does not go with watch. With watch: true, the connection also gets a session.summary after every change to any session, until it closes. session.rename sets a title by hand. session.fork copies a session's history up to one message into a new session, and the client attaches to it. session.detach stops one session's events. session.inspect reads the saved checkpoint messages and does not call the model. When golem has a system prompt for the session, it comes first, with role system, and message_count leaves it out (ADR-031). A reply that called tools lists each call as → name(args) after its text. auth.set tries a model provider's API key against the provider, then stores it in the Keychain, and a key the provider refuses is not stored (ADR-035). auth.remove deletes it, and auth.list says where each provider's key is without returning it. The client shows auth.set in the wire view with the key replaced by [redacted].
Switching a session's model, model errors, the local model server, and downloads are in Talking to models.
The MCP methods, mcp.list to mcp.server.status, are in MCP.
fs.list_dirs lists the folders under a path for the web page's folder browser, so a person can pick a session's folder without typing it. It is narrow on purpose (ADR-040): the path is resolved first and must be the home folder or below it, only folders come back (no file names, sizes, or contents), dot-folders, ~/Library, and the sandbox's secret folders are left out, and a list stops at 500 with truncated. A refused path fails with INVALID_PARAMS. session.create and the other calls that take a cwd also check that it is a folder that exists.
git.info and git.branches tell the page what git says about a folder, read only: git.info returns repository, root, branch, detached, changed (lines of git status --porcelain), and worktrees (path, branch, main, agent, main checkout first); git.branches returns current and up to 200 local branches (name, last_used), newest commit first. The path is checked as fs.list_dirs checks it, except that dot-folders are allowed because agent worktrees live in .claude/worktrees/. Each git call is stopped after two seconds, and a refused path or a timeout fails with INVALID_PARAMS.
file.read returns the start of one text file of a session's folder, for the web page's file view: {session_id, path} gives {path, text, truncated, lines}. The path is relative to the folder and is checked by the same code as the model's read_file, so a path outside the folder (through .., an absolute path, or a symlink) fails with INVALID_PARAMS, as do a folder, a binary file, a file that is not UTF-8, a file over 5 MB, and a session without a folder. text is cut at 1,000,000 characters and truncated says so; lines counts the whole file. file.list takes {session_id, query?, limit?, hidden?} (limit 1 to 200, default 50; hidden defaults to false) and returns {paths, more}: the files whose relative path holds query without case, shortest first, then alphabetical. It skips the folders glob skips (.git, node_modules, and the like). Unless hidden is true it also leaves out dot files and files in dot folders, and does not walk into dot folders. It stops walking after 20,000 entries; more is true when other files match or the walk stopped.
changes.commit, changes.commit_info and changes.suggest_message let a client commit files the session changed. They are actions of the user, not of the model: git runs in the session folder, outside the sandbox, with the user's hooks, as if they typed it, and golem never pushes. changes.commit {session_id, paths, message} runs git add -- <paths> then git commit -m <message> -- <paths>, each limited to 60 seconds, with no prompt and no stdin, so a commit that wants a passphrase or an editor fails. It answers {ok, sha, output}: a failing hook or a folder that is not a repository is ok: false with git's text (at most 4,000 characters), not an error. A path outside the session folder fails with INVALID_PARAMS, and a session with a run in progress or waiting for an approval with SESSION_BUSY. changes.commit_info {session_id} answers {repository, branch, paths}: whether the folder is in a git work tree, its branch, and which files of the session's change set git sees as changed or untracked, as paths under the session folder. changes.suggest_message {session_id, paths} asks the session's model for {message}: a subject, then a blank line and a body when there is one. It reads the diff of paths against HEAD (cut at 12,000 characters) and the last eight subjects. When the model fails it answers INTERNAL_ERROR and no message. All three are browser calls. They arrived in protocol 2.78.
The default model and model.list are in Talking to models.
changes.revert {session_id, target, force} puts back what golem wrote to files, and a browser may call it. The target has a kind: change with change_id, file with path, hunk with path and hunk (0-based, in the file's net diff), or run with run_id, which also takes back the files that later turns changed (Undo). A target with another field, or one that names nothing in the session, is INVALID_PARAMS, and so is a hunk that does not exist. A file that is not what golem last wrote is not touched and comes back in conflicts as {path, reason: "changed_on_disk"}, unless force is set; the other files are written anyway. A file that already has the wanted text is skipped. The result is {reverted, conflicts}. Each write is a change of its own with source: "revert", and is announced by a file.changed event with reverts set and run_id null. A session with an active run answers SESSION_BUSY.
Helpers (Helpers) add events and commands. The lead's log gets helper.started, helper.model, helper.step, helper.state, helper.wait, helper.ended, helper.applied and helper.discarded. The commands are helper.stop, helpers.respond, helper.apply, helper.discard and helper.retry, and a browser may call all of them, besides the agents.* methods. SessionSummary.pending_items lists every question of a lead and its helpers, and pending stays for an older client. helper.apply fails with HELPER_CONFLICT (-32027) when a file changed in the project.
cost.get answers "what did I spend", from the model_calls table (The usage table). It takes an optional session_id and does not call a model. The result has today and week (the last 7 local days), and session when a session was asked for. Each is {calls, input, output, cost_usd, saved_usd}. by_model lists {provider, model, tier, calls, input, output, cost_usd} for the week, the dearest first. by_role lists {role, calls, input, output, cost_usd} for the week, the dearest first (chat, explore for a helper, titles, ...). by_day has {day, local_tokens, paid_tokens, cost_usd} for each of the 7 days, oldest first. saved_usd prices the tokens of local calls at a reference model, the cheapest budget-tier model in the model list that does not refuse tools, and saved_reference names it, or is null when there is none. A browser may call it. model.call.started has a tier.
eval.routing replays the stored events of the sessions of the last days days (14 by default), or of one session_id, through three scenarios: a pinned frontier model, a pinned local model and auto. It calls no model. The result has days, sessions, calls and skipped (calls that could not be sized), a row for each scenario in scenarios and one for what really ran in actual, each {name, calls, input, output, cost_usd, cuts, step_ups, clears, summaries, peak_share} with step_ups null for a pinned scenario, and top, the sessions where auto would have spent most, as {session_id, calls, cost_usd}. It holds no message text. It is not browser-callable (local in golem_protocol.methods).
chat.get and chat.set read and change [chat], and a browser may call both. chat.get takes no params and answers {instructions, plan_first, mode}, where mode is [permissions] mode, read only here. chat.set takes a partial, instructions (at most 30 lines of 1 to 300 characters after trimming, blank lines dropped) and plan_first, and answers {ok, errors, values} like notifications.set; an error names the bad line by number. session.create takes an optional plan_first; left out, a new session follows [chat] plan_first.
model.star takes {ref, starred} and writes [model_menu] starred, and a browser may call it. While the key is unset, the first call writes the whole menu as model.list last showed it, then adds or removes ref. It answers {starred}, the list as stored. A listed model has starred, true when it is in the menu. A ref no provider lists is listed with source profile and a status that is not ready.
chat.prompt shows what the model of a new chat reads now, and a browser may call it. It builds the prompt for the default model with no folder, no pinned skills, no on-demand MCP servers, and plan first as [chat] plan_first says. instructions (optional, checked as chat.set checks them) stand in for the saved lines for this answer only, and nothing is written. The result is {model, parts, tools_tokens, total_tokens}: model is the default model or null, parts are {name, text, tokens} in prompt order, tools_tokens is the size of the tool schemas (0 for a model that takes no tools), and a token is a count of characters over four, rounded up. With no default model the memory block is left out. It calls no model.
notifications.get and notifications.set are the typed way to read and change [notifications], and a browser may call both, and notify.test. notifications.get takes no params. Its result has needs_you (always true), failed, finished, open_in, terminal_app, terminal_apps (the names terminal_app may take), and finished_routines and failed_routines, the routines whose own notify_finished or notify_failed says yes while the global key says no. notifications.set takes a partial: failed, finished, open_in, terminal_app. A key left out stays. There is no needs_you in it. A wrong value comes back as {ok: false, errors} and nothing is written; otherwise the file is edited with its comments kept and the result is {ok: true, values}. The notifier reads the file at each notice, so no restart is needed.
routing.get and routing.set are the typed way to read and change [routing], [routing.ladder], [routing.roles], [budget] and [context], and a browser may call both. routing.get takes no params. Its result has the five tables as routing, ladder, roles, budget and context (the values golem uses, defaults included), and picked, the model golem would take in each tier, as provider/model or null, when the ladder line is empty. routing.set takes a partial of each table. A key left out stays, and a null removes the key from the file so its default applies again. Every value is checked with the same models the settings load with, and a model named in the ladder or in a role must exist, and a ladder line must hold a model of its own tier. When anything is wrong the result is {ok: false, errors}, each error a {path, message} with the setting's path such as context.clear_to, and nothing is written. Otherwise the file is edited with its comments kept, and the result is {ok: true, values} with what routing.get would now answer. The router reads the file again at its next call, so no restart is needed.
The model.call.started and model.call.completed events, and the trace.get and trace.span commands, are in Tracing.
Why a protocol package
Those shapes are written once, as Python classes in golem_protocol. just gen writes JSON Schema, then TypeScript, into packages/protocol/gen/. @golem/client imports the generated types, and the TUI and golem status both use that client. A hand-written TypeScript copy would drift, and the bug would show up as a wrong screen. Here just check fails if the generated files do not match the classes.
Adding a message is the same every time. Add a class, run just gen, and the client sees a typed payload.
Error codes
| Code | Name | When |
|---|---|---|
-32700 | parse error | A line that is not JSON |
-32600 | invalid request | JSON that is not a JSON-RPC request |
-32601 | method not found | A method the daemon doesn't have |
-32602 | invalid params | Params that don't fit the command's class |
-32603 | internal error | A handler failed |
-32001 | protocol mismatch | hello with another major |
-32002 | hello required | Any command before hello |
-32003 | session not found | |
-32004 | session busy | message.send while a run is open |
-32005 | model not configured | |
-32006 | run not found | run.cancel with an id the daemon never ran |
-32007 | message not found | session.fork at a message it can't cut at |
-32008 | keychain unavailable | |
-32009 | model pull failed | |
-32010 | approval not found | approval.respond when no run waits on that call, and route.consent.answer when no run waits on that question |
-32011 | invalid tool args | Edited arguments that the tool or the rules refuse |
-32012 | artifact not found | |
-32013 | skill not found | A skill the session can't run |
-32014, -32015 | key rejected, key unchecked | auth.set |
-32016 | Ollama failed | |
-32017 | budget spent | message.send on a paid model while a cap in [budget] is spent |
-32018 | local only | message.send on a hosted model in a folder that stays on this Mac |
-32020 | not allowed from the browser | Sent by the gateway, never by the daemon |
Limits
- A line is at most 1 MiB. A longer one gets
-32700withline too long, and the connection closes. The gateway refuses a WebSocket message over the same size before it reaches the daemon. - A replay is one burst. Attaching to a long session queues its whole replay inside the session's lock, so an emit for that session waits until the burst is queued.
Files
| File | What it does |
|---|---|
packages/protocol/golem_protocol/commands.py | The params and results of every command |
packages/protocol/golem_protocol/events.py | ChatEvent and its data, one class per event type |
packages/protocol/golem_protocol/rpc.py | The JSON-RPC envelope: requests, results, errors, notifications |
packages/protocol/golem_protocol/version.py | PROTOCOL_MAJOR and PROTOCOL_MINOR |
packages/protocol/golem_protocol/codegen.py | What just gen writes into packages/protocol/gen/ |
packages/daemon/golem/server/framing.py | One line at a time, with the size limit |
packages/daemon/golem/server/dispatcher.py | The envelope, hello, and the error codes |
packages/daemon/golem/server/handlers.py | One handler per command |
packages/daemon/golem/sessions/bus.py | Which connections follow which session |
packages/client/src/connect.ts | connectGolem: hello, ping, reconnect, attach, and seq |
packages/client/src/unix-link.ts, ws-link.ts | The two links: the Unix socket, and a WebSocket to the gateway |
packages/gateway/src/framing.ts, bridge.ts | The gateway's filter, and its bridge to the daemon |
Read more
- Next: Sessions, the event log and checkpoints that the events come from.
- Before: The daemon.
- ADR-003 lists every shape and what each minor added.
- JSON-RPC 2.0, the envelope.
- The overview: the whole system on one page.