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.

Starting and finding sessions

What a frontend does before it has a client: start or reopen a session, list the others, export one.

Names: ForkedFrom, Opened, PickSession, SessionFlags, SessionInfo, Started, SystemText, UnknownSession, cli.extension_flags, cli.main, cli.option_flags, cli.session_flags, find_session, first_cursor_node, list_sessions, open_client, rename_session, start_session, to_markdown

ForkedFrom

@dataclass(frozen=True)
class ForkedFrom
    session: str
    node: int

Where a forked session's walk was copied from: the source's session id and the node of its tree the copy ends at.

Opened

@dataclass
class Opened
    client: Client
    cursor: int
    snapshot: tuple[Event, ...]
    welcome: Welcome | None
    started: Started | None
    socket: Path | None
    me: str

A session opened for a client: the client, the first cursor, the snapshot (every event the client's stream held up to and including its first Labels, and for a reopened cursor the events up to its view), the welcome (the server's if attached; for a local start one built from it, None for a session kept in memory, which has no id) and the started session (None when attached: the server owns it). Attached, socket is the address in the server's record and me the client id, so reconnect can dial again; client is always the client to use now.

Opened.warnings

property warnings: tuple[str, ...]

What the start's config names that it lacks (Started.warnings); none when attached, where the server said them.

Opened.reconnect

async def reconnect(self) -> Client

A new client of the server this session is attached to, with the same id: after a stream ended in ConnectionError. It replaces client (the old one is closed). OSError if nothing answers at the server's address; ConnectionError for a session this process runs, which has no server to dial.

Opened.close

async def close(self) -> None

Close the client; for a session this process started, then Started.stop.

PickSession

PickSession = Callable[[Sequence[SessionInfo], Sequence[SessionInfo]], SessionInfo]

What -r asks of a frontend: given the rows of the working directory and all rows (newest first), the one to open.

SessionFlags

@dataclass(frozen=True)
class SessionFlags
    directory: Path | None = None
    continue_last: bool = False
    resume: bool = False
    session: str | None = None
    fork: str | None = None
    no_session: bool = False
    name: str | None = None
    system_prompt: str | None = None
    append_system_prompt: tuple[str, ...] = ()
    no_context_files: bool = False

What the session flags say, as tau.cli.session_flags parses them: directory (--session-dir), continue_last (-c), resume (-r), session and fork (REFs), no_session and name (-n), and the prompt flags (D20): system_prompt (--system-prompt), append_system_prompt (--append-system-prompt, in order) and no_context_files (-nc). A name (-n) is stripped and cannot be empty or hold a / or a :. At most one of the first five choices; no_session takes none of the others; a session that already has its prompt (-c, -r, --session, --fork) takes neither --system-prompt nor --append-system-prompt. ConfigError otherwise.

SessionFlags.of

@classmethod
def of(cls, args: object, cwd: Path) -> 'SessionFlags'

The flags session_flags() parsed into args, with --session-dir and a path REF made absolute against cwd, the directory they were typed in.

SessionInfo

@dataclass(frozen=True)
class SessionInfo
    id: str
    path: Path
    cwd: str | None
    name: str | None
    forked_from: ForkedFrom | None
    updated: float | None
    first: str | None
    error: str | None

One row of the catalog. id and path locate the session; cwd is its working directory, name its name, forked_from its source; updated is the log's modification time in seconds since the epoch (every synced write moves it); first is the text of its first User node, read only when it has no name and only when asked for. A row that is not a readable session has an error saying why, and no other field can be relied on.

SessionInfo.title

property title: str

What a frontend shows for it: the name, else the first message, on one line (cut to 80 characters), else (no messages).

Started

@dataclass
class Started
    session: Session
    driver: Driver
    providers: Mapping[str, Provider]
    loaded: LoadedConfig
    model: str
    cwd: Path
    directory: Path | None
    created: bool
    sources: tuple[ExtensionSource, ...]
    warnings: tuple[str, ...]
    prompt: SystemPrompt | None

A running session: its session and driver (started), the providers the program closes through stop, the loaded config and the model (selected for a new session, else the one recorded at the first cursor), the session's working directory cwd (the process is in it), the session's directory (None: in memory) and whether this run created it (a new session or a fork). sources are the extension sources the start planned, one per row of tau ext list, warnings what the config names that this start lacks (one line each; frontends print them), and prompt the parts of the system prompt it assembled (None: the session already had one, or the program supplied the text). A session named during the run counts as used.

Started.never_used

property never_used: bool

This run created the session and it still has only the nodes it was created with, no pending item and the name it was created with.

Started.stop

async def stop(self) -> None

Stop the driver; delete the session's directory if it was never used (while the lease is still held); release the lease; close the providers.

SystemText

SystemText = Callable[[Path, LoadedConfig], str]

What a new session's System node says: given the session's working directory and the loaded config. Called once, for a new session only.

UnknownSession

class UnknownSession(LookupError)

A ref that names no session, or a name or id prefix that names several. The message lists the candidates with their cwd and age.

tau.cli.extension_flags

def extension_flags() -> argparse.ArgumentParser

A parser (add_help=False, for parents=) with the flags that choose extensions: -e VALUE (repeatable; a path, or the key of a source: a discovered one or a built-in) and --no-extensions. tau.start_session reads them from the parsed args.

tau.cli.main

def main(
    argv: Sequence[str] | None = None,
    *,
    stdin: TextIO | None = None,
    stdout: TextIO | None = None,
    stderr: TextIO | None = None,
    environ: Mapping[str, str] | None = None,
    cwd: Path | None = None,
) -> int

Run tau with argv (default sys.argv[1:]); the other arguments default to the process's streams, environment, and working directory. Returns the exit status.

The process's streams may be missing or go away, as any Unix program's may. A closed standard input (<&-) reads as empty; a closed standard error says nothing; a closed standard output is an error (status 1, said on standard error); and a standard output whose reader has gone (tau -p ... | head -1) ends the run quietly with status 141, 128 plus SIGPIPE, as a program killed by that signal would.

tau.cli.option_flags

def option_flags() -> argparse.ArgumentParser

A parser (add_help=False, for parents=) with --set EXTENSION.FIELD=VALUE (repeatable): the config's command-line layer, for this run only (D22). A value is read as /config reads it; tau.start_session applies and checks them against the loaded extensions' options.

tau.cli.session_flags

def session_flags() -> argparse.ArgumentParser

A parser (add_help=False, for parents=) with the flags that choose the session (D18 section 5): -c/--continue, -r/--resume, --session REF, --fork REF and --no-session (at most one), -n/--name NAME and --session-dir DIR; and the prompt flags of a new session (D20): --system-prompt TEXT, --append-system-prompt TEXT (repeatable) and -nc/--no-context-files. Pass the parsed arguments to start_session, which makes paths absolute and rejects combinations.

find_session

def find_session(sessions: Path, session: str, *, first: bool = False) -> SessionInfo

The session session names, tried in this order: a path (it contains /), an id, an exact name, a unique id prefix. The whole of sessions is searched. A name or prefix of several sessions, or of none, is UnknownSession. With first, the row also has first.

first_cursor_node

def first_cursor_node(session: Session) -> int

The node a frontend would show, without writing: the open cursor with the lowest id's at, else the closed cursor with the lowest id's last node. What a fork or an export of a session with no node given copies. LookupError for a session with no cursor.

list_sessions

def list_sessions(sessions: Path, *, cwd: Path | None = None) -> list[SessionInfo]

The rows of sessions, newest updated first; those whose cwd equals cwd (resolved) exactly, or all with cwd=None. A directory that is not a readable session is a row with an error and is listed either way. Reads info.json and stats log per session, and the start of the log of a session with no name (its first). Anything that is not a directory is ignored.

open_client

async def open_client(
    args: object,
    *,
    client: str,
    environ: Mapping[str, str],
    cwd: Path,
    system: SystemText | None = None,
    prompts: Prompts | None = None,
    pick_session: PickSession | None = None,
    own: Sequence[Extension] = (),
    model: str | None = None,
    clock: Clock | None = None,
) -> Opened

Open the session args choose (see start_session for the arguments and what it raises) and a client named client of it, as the module says: attached to the tau serve that holds it, else started here. ConfigError when attached and -e, --no-extensions, --set, -n, own or --model ask for what the server's loaded session cannot take; Leased for a session another process holds that is no server; LookupError for a session with no cursor. Close the result with Opened.close.

rename_session

def rename_session(path: Path, name: str) -> None

Give the session in path the name name (stripped); an empty name removes it. No lease is taken: the file is replaced whole, and the last of two renames wins. ConfigError for a name with a / or a : in it (a ref could not name the session by it), ValueError if info.json is not readable.

start_session

async def start_session(
    args: object,
    *,
    environ: Mapping[str, str],
    cwd: Path,
    system: SystemText | None = None,
    prompts: Prompts | None = None,
    pick_session: PickSession | None = None,
    own: Sequence[Extension] = (),
    model: str | None = None,
    clock: Clock | None = None,
) -> Started

Start the session args (the parsed session_flags() and extension_flags()) choose, for a program started in cwd with environ, as the module says. own are the program's own extensions, ahead of the loaded ones; model is --model; prompts ask a person to trust a project or to pick a model; pick_session is what -r asks; system is the text of a new session's System node (default: D20's tau.system_prompt, from the prompt flags in args).

Raises what the steps raise: ConfigError, TrustError, ExtensionLoadError, UnknownSession, Leased, FileNotFoundError for a session whose working directory is gone. Nothing is created when a step before the session's fails, and a session this call created is removed if a later step fails.

to_markdown

def to_markdown(
    nodes: Iterable[Node],
    *,
    thinking: bool = False,
    of: SessionInfo | None = None,
) -> str

nodes (a walk, root first) as Markdown. With of, the session's row, the document starts with the header tau export writes: the title, of's id and cwd, the node exported (the walk's last) and forked_from. LookupError for a Results node whose call no earlier Assistant node in nodes made.