Skip to content

Unreleased

Generated from the docstrings of Tau 0.16.0-dev (commit c439c401) by scripts/api_docs.py in the Tau repository. Not the 0.15 API.

The wire protocol

tau serve serves one session over a Unix socket, so a frontend in any language can drive it. Python programs use RemoteClient and need none of this page; it is for the author of a client in another language. For what the calls mean, read the model and writing a frontend: the wire is the Client contract, serialized.

How it travels

  • Transport. A WebSocket over the Unix socket $TAU_HOME/serve/<session id>.sock (or the --socket path). The socket's file permissions are the only authentication. tau serve -d --json prints the socket's path; see the quickstart.
  • Messages. JSON-RPC 2.0, one message per WebSocket text message. A client sends requests, with parameters by name only ({"cursor": 0, "text": "hi"}). It sends no batches and no notifications. The server answers each request, and sends the notifications event and end.
  • hello comes first. It names the protocol the client speaks, the client's stable id (john@laptop:vscode) and, if it wants one, the buffer of its event stream. The answer is a Welcome. A different protocol number is refused with ProtocolMismatch and the connection closes: the match is exact. Any other request before hello, or a second hello, is an invalid request and closes the connection.
  • One call per Client method. The method has the Client method's name, and a call that returns nothing answers null. Calls begin in the order they arrive and may finish in any order; match a response to its request by id. close is not a call: close the connection.
  • Events. The notification event has the event's fields as its parameters, plus kind, the event's name ({"kind": "CursorView", "cursor": 0, ...}). The server sends every event a response depends on before the response: when open answers 3, the CursorView of cursor 3 has already arrived. A client hears Live events only for the cursors it watches; every other event goes to every client.
  • The end. The last message is the notification end, then the server closes the connection. Its error is null when the server stopped, CutOff when the client fell too far behind its buffer, and Stopped when the driver failed.
  • No resume. A reconnecting client gets a fresh snapshot of events and reads the tree again. The log is the truth.

Reading a value

Two styles share the schema, and both are tagged the way Rust's serde tags them:

  • A node and what it holds (Body, Part, Outcome, Author, Item, Ending) are externally tagged: a variant with data is an object with one key, {"User": "hi"}, and a variant without is a bare string, "Core". This is the encoding of the session's own log.
  • An event carries its name in kind.

Everything else is plain JSON: a dataclass is an object, a tuple an array. Node ids, cursor ids and item ids are non-negative integers, dense, and never reused. A node never changes once written, so a client may cache it.

Errors

A failed call answers a JSON-RPC error object: code, message (the exception's text) and, for two codes, data. The table names every code. RemoteClient raises the Python class in its last column, so a client in another language maps codes to its own errors the same way.

A call on a server whose driver has stopped or failed answers Stopped (-32013).

The descriptions below say which error a call answers by the name in the table, which gives its code. Where a value is absent they say null.

The version

protocol in hello is an integer, now 1. It changes only between tagged releases, when the schema below changed since the last tag. Between releases the wire changes freely: build a client against the schema of the tau you run, and check tau serve --schema.

Calls

Every call of Client. hello is first; the rest follow in any order.

hello method

The first message of a connection: the protocol the client speaks, its stable client id (john@laptop:vscode) and the buffer of its event stream (the server's default if left out). A different protocol is ProtocolMismatch. The server answers Welcome.

Parameters:

field type notes
protocol integer
client string
buffer integer or null optional

Result: Welcome

abort method

Abort the cursor's step and decline its open questions.

Parameters:

field type notes
cursor integer

Result: null

answer method

Answer an open question with a decoded JSON value; null declines. Refused if the value is wrong (the question stays open), NotFound if the question is closed or unknown (the first good answer wins), NotYours if it is for another client.

Parameters:

field type notes
question integer
value any JSON value

Result: null

children method

The ids of the children of node id, in append order.

Parameters:

field type notes
id integer

Result: array of integer

close_cursor method

Close the cursor (D17): abort its step as abort does, wait for it to rest, drop its pending items, and close it. Clients are sent a CursorGone. Its id, last node and labels stay; reopen restarts from them. CursorClosed if it is already closed.

Parameters:

field type notes
cursor integer

Result: null

commands method

Each command's form: its name, description and argument schema (named types with their "format", each default), fixed until the driver reloads. If some extension has options there is one more, config, whose one argument is the extension; it is changed with configure, not run.

No parameters.

Result: array of Form

complete method

The values of a named type ("path", "model", "cursor", "label", "node"; the "format" of a schema) that start with prefix, as cursor sees them. Paths are the driver's machine's, relative to its working directory.

Parameters:

field type notes
cursor integer
named string
prefix string

Result: array of string

complete_line method

commandline.completions of line on the driver: what could finish its last word, in one call.

Parameters:

field type notes
cursor integer
line string

Result: array of string

configure method

Change the options named in values (decoded JSON) of extension on cursor's branch: a step of the cursor writes a Config node. With save, the server also writes the user's config file (extensions.<name>), which every session reads: the options in values and those a Config node on the branch set, wherever they differ from the file's (options equal to the file's stay untouched; values may be {}; options only the user, project or command-line layers set are not copied). A client needs no access to that file. ConfigError for an extension without options, or values its options type refuses (or, with save, a driver with no user config), Busy unless the cursor is at rest; nothing is written then, neither node nor file.

Parameters:

field type notes
cursor integer
extension string
values object
save boolean optional

Result: null

go_to method

Move the cursor to node to, aborting a busy step (which declines its open questions).

Parameters:

field type notes
cursor integer
to integer

Result: null

input method

Add text to the cursor's scratchpad as this client's input; returns the item.

Parameters:

field type notes
cursor integer
text string

Result: integer

node method

The node with this id; NoSuchNode if there is none.

Parameters:

field type notes
id integer

Result: Node

nodes method

Up to limit nodes from id start, in id order; none past the end. Ids are dense and a node never changes, so a tree is read in ranges. Refused for a negative start or limit.

Parameters:

field type notes
start integer
limit integer

Result: array of Node

open method

Open a cursor at node at; it wakes. Returns its id.

Parameters:

field type notes
at integer

Result: integer

options method

extension's options as they stand at cursor: a form whose schema has every option, each default the value now. ConfigError if it has no options.

Parameters:

field type notes
cursor integer
extension string

Result: Form

parse_line method

commandline.parse of line with this driver's forms and the options forms cursor sees: the command, its arguments, and the required parameters still missing. UnknownCommand if no command has the name (send the line as text), Refused for a line that cannot be read, plain NotFound for a bare name two extensions share.

Parameters:

field type notes
cursor integer
line string

Result: Parsed

remove_item method

Take back a pending input this client added to cursor (input or send): it is removed from the scratchpad before the cursor delivers it. NotFound once it is delivered, or if there is no such item on the cursor; NotYours for an item another client or an extension added. Wakes nothing and does not turn auto-step off.

Parameters:

field type notes
cursor integer
item integer

Result: null

remove_label method

Remove label; NoSuchLabel if there is none.

Parameters:

field type notes
label string

Result: null

reopen method

Open a new cursor at the closed cursor's last node, and move each of its labels onto it. Returns the new id. Refused if cursor is open, NoSuchCursor if it was never opened.

Parameters:

field type notes
cursor integer

Result: integer

run method

Run /command ("note", or "a:note", the extension's qualified name) with decoded JSON args on cursor; returns the command's result (null if it has none) once it has finished. CommandFailed (its message is the failure as "Type: msg") if it raised, or was aborted; it is raised as soon as the command raises, even when the command's step has not yet ended: the cursor may still be busy for a moment while the step ends, and a retry then gets Busy. A command's progress and cursor.tell arrive as Notices. NotFound for an unknown command or a bare name two extensions share ("/note is two commands: /a:note, /b:note"), Refused naming the problem for arguments that fit no parameter (the values are checked with the session, "new" last), Busy for a command that runs as a step of the cursor when it is not at rest.

Parameters:

field type notes
cursor integer
command string
args object

Result: string or null

send method

input with auto-step on.

Parameters:

field type notes
cursor integer
text string

Result: integer

set_auto method

Turn cursor's auto-step on or off; on wakes it.

Parameters:

field type notes
cursor integer
on boolean

Result: null

set_label method

Put label on cursor; a label set elsewhere moves.

Parameters:

field type notes
cursor integer
label string

Result: null

step method

Start a step on a cursor at rest; Busy otherwise.

Parameters:

field type notes
cursor integer

Result: null

walk method

The nodes from the root to id.

Parameters:

field type notes
id integer

Result: array of Node

watch method

Hear the Live of exactly these cursors from now on (a call replaces the last), starting with what each sample in flight has streamed that is not in the tree yet.

Parameters:

field type notes
cursors array of integer

Result: null

Events

The params of the notification event.

Live

A delta, on the cursor whose sample or tool call produced it. Never in the tree: a client draws it as a layer over the cursor. Only a client watching the cursor hears it.

field type notes
kind "Live"
cursor integer
delta TextDelta or ThinkingDelta or CallNamed or CallArgs or Retrying or ToolProgress

CursorView

One cursor as a client sees it, whole: where it is (at), whether a step is running (busy), auto-step, its open questions (oldest first), its pending items (an ItemData.Input says who wrote it: its by), and how its last step ended (ending) with the hook_error that ended it, if a cursor hook failed in it. Both are null from the start of a step until it ends, and after a reload. model is the qualified name of the model the cursor's branch is on (what its next sample uses), null if no Config on the branch names one or one is unreadable (a sample says which). shown is what each extension shows on the cursor (Cursor.show), as (extension, text) pairs in extension-name order; it is not in the log, so it is empty after a reload.

field type notes
kind "CursorView"
cursor integer
at integer
busy boolean
auto boolean
questions array of OpenQuestion
items array of Item
ending Ending or null
hook_error HookFailure or null
model string or null
shown array of [string, string]

CursorGone

Cursor cursor is closed (D17): a client drops its view of it. at is the node it was last at, for restarting (reopen). A cursor has one state event at a time: its CursorView while open, this after it closes. Labels may still name it: they are its restart record.

field type notes
kind "CursorGone"
cursor integer
at integer

Labels

Every label and the cursor it is on, in label order.

field type notes
kind "Labels"
labels array of [string, integer]

Appended

Nodes added to the tree, in id order, bodies included.

field type notes
kind "Appended"
nodes array of Node

Notice

A message for one client, or for all of them: cursor.tell (to every client unless it names one), or an input a hook refused (to its author).

field type notes
kind "Notice"
text string

Deltas

A Live event's delta is one of these, tagged by kind.

TextDelta

Text of the reply arriving.

field type notes
kind "TextDelta"
text string

ThinkingDelta

Thinking text arriving.

field type notes
kind "ThinkingDelta"
text string

CallNamed

A call begins forming: call number index in this reply, with its id and tool.

field type notes
kind "CallNamed"
index integer
id string
tool string

CallArgs

More of call index's argument text (args_raw).

field type notes
kind "CallArgs"
index integer
text string

Retrying

A provider is waiting to try the sample again (D24 section 4): this is retry attempt of attempts, after seconds, because the last try failed with reason. It is no part of the reply and is never replayed to a client that starts watching later: it says what the sample is doing now, and the next delta (or the end of the sample) replaces it.

field type notes
kind "Retrying"
attempt integer
attempts integer
seconds number
reason string

ToolProgress

A running call showing partial output: text is new output since the last ToolProgress of the same call, not the whole so far. The call is named by node, the batch's node (the Assistant node holding the call), and call_id: a server may reuse ids across batches, so the id alone does not say which call. Only the driver makes one (a tool calls its progress); a provider cannot yield one. What the call saves is its Outcome, never this.

field type notes
kind "ToolProgress"
node integer
call_id string
text string

The end

The params of the last message: the notification end. error is null when the driver stopped, else CutOff or Stopped.

field type notes
error null or Error

Values

Author

  • "Provider" or "Tools" or "Core"
  • {"Frontend": string}
  • {"Extension": string}

Body

  • {"System": string}
  • {"User": string}
  • {"Assistant": {"finish_reason"?: string or null, "meta"?: string or null, "parts": array of Part, "stop": Stop}}
  • finish_reason: The provider's own finish string, verbatim; null when it sent none (an interrupted reply, a failed sample).
  • meta: What the response carried besides its parts (model, id, usage...), as JSON object text. Opaque to core; null when the provider sent none.
  • {"Results": array of [string, Outcome, Author]}: One (call id, outcome, by) per call, in call order. by is who produced that outcome: Tools, or the extension that answered or edited it.
  • {"Config": Config}
  • {"Custom": {"data": string, "kind": string}}

Config

A config snapshot. data is opaque to core and typed by the driver.

field type notes
data string

Ending

How a step ended. Serde-encoded as the nodes are: it crosses the wire in a CursorView.

  • "Done" or "Aborted"
  • {"Halted": string}
  • {"Failed": string}

Error

A JSON-RPC error object; data holds what a row needs to rebuild its exception (ProtocolMismatch: server; UnknownCommand: name).

field type notes
code ErrorCode
message string
data object optional

Form

What a client knows of something it fills in: a command (its name, typed as /name, its description and the schema of its arguments, with the named types' "format" and each default, and the extension that owns it) or an extension's options (the name of the extension, and a schema whose defaults are the values now; extension is null, as it is for /config). A command is called by its qualified name, extension:name, which on the wire a client writes itself from the two fields. A command that yields gives its bare name up to any other command that has it (/model stays the built-in's; the yielding one is only /skills:model). Frozen, compared by value, and not hashable: the schema is a dict.

field type notes
name string
description string
schema object
extension string or null optional
yields boolean optional

HookFailure

A cursor hook of extension raised, or broke its contract, at hook point ("pre_step", "post_step", ...). error is "Type: msg", the text a post_step hook sees in Ending.Failed.

field type notes
extension string
point string
error string

Item

field type notes
data ItemData
id integer
to integer

ItemData

  • {"Input": {"by": Author, "text": string}}
  • {"Extension": {"data": string, "name": string}}

Node

field type notes
body Body
by Author
copied_from integer or null optional, The node this one repeats verbatim (a compaction or prune copy). A log written before this field existed has none.
delivers array of integer
derived_from integer or null optional, The node whose walk this one's content was computed from (a summary, a pruned transcript). A log written before this field existed has none.
id integer
parent integer or null optional
time integer
typed string or null optional, What a person typed, for a User node whose text a pre_input hook changed (the attachments extension inlines files). Set only when it differs from the text: the node's body is what the model sees, this is what to put back in an editor. A log written before this field existed has none.

OpenQuestion

A question an extension asked and nobody has answered: id (what answer names), whom it is for (to: a client id, null for anyone), the extension that asked, what it asks, and the JSON Schema of the answer.

field type notes
id integer
to string or null
extension string
text string
schema object

Outcome

  • "Interrupted"
  • {"Ok": string}
  • {"Err": string}

Parsed

A command line, read: the command form, its args (decoded JSON), and the missing required parameters, in order, which a frontend asks for. For /config <extension> the command is the extension's options form, args the options to change and extension its name; with no args the line asks for the form, which a frontend shows from Client.options. save is whether --save was typed. run makes the call.

field type notes
command Form
args object
missing array of string
extension string or null optional
save boolean optional

Part

One piece of a reply. replay is null unless the provider kept data to send back. Logs written before replay existed load as null.

  • {"Text": Prose}
  • {"Thinking": Prose}
  • {"Call": {"args_raw": string, "id": string, "replay"?: Replay, "tool": string}}

Prose

A string is plain; an object is signed. Deserialized by hand because untagged would drop the reason a bad replay was refused.

One of: string or {"replay": Replay, "text": string}

Replay

Data only the provider that wrote a part can send back (a signature, a redacted block). data is the text of a JSON object with no repeated key, kept exactly as given and opaque to core beyond that; provider names who may send it back.

field type notes
data string
provider string

Stop

One of: "End" or "Tools" or "Length" or "Interrupted" or "Error"

Welcome

What hello answers: the protocol the server speaks, its τ version, the session id it serves, the cwd that session runs in (paths complete there), and its pid.

field type notes
protocol integer
version string
session string
cwd string
pid integer

Error codes

The error table (D21 section 5).

code name RemoteClient raises
-32700 ParseError ProtocolError
-32600 InvalidRequest ProtocolError
-32601 MethodNotFound ProtocolError
-32602 InvalidParams TypeError
-32603 Internal RuntimeError
-32001 Busy Busy
-32002 NoSuchCursor NoSuchCursor
-32003 CursorClosed CursorClosed
-32004 NoSuchNode NoSuchNode
-32005 NoSuchLabel NoSuchLabel
-32006 ProtocolMismatch ProtocolMismatch
-32007 NotFound LookupError
-32008 UnknownCommand UnknownCommand
-32009 Refused ValueError
-32010 NotYours PermissionError
-32011 CommandFailed CommandFailed
-32012 ConfigError ConfigError
-32013 Stopped ConnectionError
-32014 CutOff CutOff