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.
Configuration and context¶
Models, the config files, trust, extension loading, the system prompt.
Names: Ask, ConfigError, ConfigProblem, ContextFileError, DotenvError, ExtensionLoadError, ExtensionSource, Layer, LayerText, LoadedConfig, ModelCatalog, ModelConfig, Origin, Pick, Price, PromptSource, Prompts, ResolvedModel, Severity, SourceKind, SourceState, SystemPrompt, TrustError, Trusted, UntrustedProject, UserConfig, check_config, list_extensions, load_config, load_extensions, model_config, prompts, read_models, select_model, system_prompt
Ask¶
Ask = Callable[[str], bool]
A yes-or-no question put to the person: takes the question, returns the answer.
ConfigError¶
class ConfigError(ValueError)
A Config's data that does not name a model, a model that is not in the config, an
invalid resolved model, a key that cannot be read, or options that do not fit their
extension: an extension with none, an unknown option, a wrong type, a missing required
one, or a refusal by the options type's own __post_init__.
ConfigProblem¶
@dataclass(frozen=True)
class ConfigProblem
severity: Severity
message: str
source: str | None = None
path: str = ''
line: int | None = None
column: int | None = None
One thing wrong (or suspicious) in the config layers.
source is the file path or "session"; path the dotted location inside it
(models.free_tokens.models.gpt-6-sol.modle); line and column are set
for JSON syntax errors. The message never holds an API key.
ContextFileError¶
class ContextFileError(ConfigError)
A context file that was found and cannot be used. The message names the path and the cause, and says how to start without context files.
DotenvError¶
class DotenvError(ValueError)
A .env line that is not KEY=value; the message names the file and line, not the value.
ExtensionLoadError¶
class ExtensionLoadError(ImportError)
One or more extension sources did not load: the message is every failure (what failed,
its source, the underlying error, and the command that gets past it), and sources their
ExtensionSource records. The first underlying exception is __cause__.
ExtensionLoadError.init¶
def __init__(self, message: str, sources: Sequence['ExtensionSource'] = ()) -> None
ExtensionSource¶
@dataclass(frozen=True)
class ExtensionSource
key: str
state: SourceState
kind: SourceKind
origin: str
detail: str | None = None
extensions: tuple[str, ...] = ()
commands: tuple[str, ...] = ()
tools: tuple[str, ...] = ()
One row of tau ext list: the source's key, its state (always: tau and
session_name; on; off; shadowed, by what; failed; untrusted), its kind
(built-in, package, user, project, explicit for -e, or load for a load key
that no source has), origin (where it is) and detail (why it is off, shadowed, untrusted
or failed). extensions are the names of the extensions it provides, commands their
commands' qualified names and tools their tools' names; all empty unless it is on.
Layer¶
Layer = Path | LayerText
One config layer: the Path of a file, or a LayerText already read.
LayerText¶
@dataclass(frozen=True)
class LayerText
source: str
text: str
A layer already read: its text and the source (file path) problems name.
Accepted wherever a layer takes a Path, so a caller that read and showed the
text reads exactly that text.
LoadedConfig¶
@dataclass(frozen=True)
class LoadedConfig
catalog: ModelCatalog
environ: Mapping[str, str]
project: Trusted | None
home: Path
user: UserConfig
The result of load_config: the catalog of models, environ (the shell
environment over a trusted project's .env; where keys are read from), the trusted
project (None: there is none), home (TAU_HOME), and the user config: the
layers read again after τ writes the user's file (Driver(user_config=)).
ModelCatalog¶
@dataclass(frozen=True)
class ModelCatalog
models: Mapping[str, ResolvedModel]
default_model: str | None
warnings: tuple[ConfigProblem, ...]
extensions: Mapping[str, Mapping[str, object]] = field(default_factory=lambda: {})
extension_sources: Mapping[str, str] = field(default_factory=lambda: {})
load: Mapping[str, bool] = field(default_factory=lambda: {})
load_sources: Mapping[str, str] = field(default_factory=lambda: {})
system_prompt: str | None = None
system_prompt_source: str | None = None
tui: Mapping[str, str] = field(default_factory=lambda: {})
Every model the merged layers define, plus default_model, any warnings, and the
extensions options the layers set ({"step_limit": {"limit": 10}}, merged per option;
D16 section 4). Which options an extension has is its own to say (check_config).
load is the merged top-level load (source key to on or off; D19 section 3) and
load_sources the layer (file path) that set each key: what the extension loader reads.
extension_sources the layer that set each extension's options (NAME) and each option
(NAME.FIELD), for the problems found in them.
system_prompt is the merged top-level key of that name (D20: the nearest layer's base text;
None: no layer sets one, so the built-in text is used) and system_prompt_source the layer
that set it (CLI for --system-prompt). tui is the merged tui
object (D23: theme; only the user's file and the command line set it, a project's is an
error).
ModelCatalog.names¶
def names(self) -> tuple[str, ...]
All qualified names, in file order.
ModelCatalog.find¶
def find(self, name: str) -> tuple[str, ...]
Qualified names matching name. A name with : is an exact qualified name;
one without is a bare search over last segments (top-level y and g:y
both match y). The caller decides on 0, 1, or many.
ModelCatalog.resolve¶
def resolve(self, qualified: str) -> ModelConfig
The model named exactly qualified; ConfigError if there is none.
ModelCatalog.explain¶
def explain(self, qualified: str) -> tuple[Origin, ...]
The layer and group each value of qualified came from.
ModelConfig¶
@dataclass(frozen=True)
class ModelConfig
model: str
base_url: str | None = None
api_key_env: str | None = None
provider: str = 'openai'
literal_api_key: str | None = field(default=None, repr=False)
max_tokens: int | None = None
options: Mapping[str, object] = field(default_factory=lambda: {})
context_window: int | None = None
price: Price | None = None
A resolved model: which model to ask, where (base_url, optional: a provider that
needs one says so in its check), the name of the variable holding its API key,
max_tokens (optional, positive), and options: a JSON object only the named provider
reads, which the config loader never looks inside (D15). context_window (optional,
positive) is the model's context size in tokens and price (optional) what it costs:
extensions read them (D24); no provider does. The driver builds it from the catalog at
each sample; no node holds it.
The key itself is never a field: it is read from the environment at sample
time (api_key) and so never reaches a node or the log.
ModelConfig.api_key¶
def api_key(self, environ: Mapping[str, str]) -> str | None
The key in environ named by api_key_env; None if no variable is named.
A literal api_key from a config file wins. Raises ConfigError if a
variable is named and is unset or empty, or if the key has a character outside
visible ASCII (it could not travel in an HTTP header). The error never holds the key.
Origin¶
@dataclass(frozen=True)
class Origin
key: str
source: str
group: str | None
Where one resolved value came from: the layer (file path or "session") and
the qualified name of the group that set it (None: the model itself).
Pick¶
Pick = Callable[[tuple[str, ...]], str]
A choice put to the person: takes the qualified model names, returns one of them.
Price¶
@dataclass(frozen=True)
class Price
input: Decimal
output: Decimal
cache_read: Decimal
cache_write: Decimal
What a model costs, in USD per million tokens: input (prompt tokens neither read from
nor written to the cache), output, cache_read and cache_write. All four are required:
a model that writes no cache repeats its input price for cache_write (D24 ruling 6).
Amounts are Decimal, so a total of many replies has no float drift. ConfigError for a
number below 0, or one that is not a number.
Price.of¶
@classmethod
def of(cls, fields: object) -> 'Price'
The price a config's price object says. ConfigError unless it is an object with
exactly the four fields, each a number of at least 0.
PromptSource¶
@dataclass(frozen=True)
class PromptSource
origin: str
size: int
One part of a system prompt: origin is "base" (the built-in text), "config" (a
config file's system_prompt), "flag" (--system-prompt or an appended section) or a
context file's absolute path; size is the bytes of text it contributes (a file's, after
its BOM is dropped).
Prompts¶
@dataclass(frozen=True)
class Prompts
ask: Ask | None
pick: Pick | None
What a person can be asked: ask (trust a project) and pick (one of several
models). Both are None unless stdin and stdout are terminals.
ResolvedModel¶
@dataclass(frozen=True)
class ResolvedModel
name: str
config: ModelConfig
origins: tuple[Origin, ...]
A model by qualified name: its ModelConfig and the Origin of each key.
Severity¶
Severity = Literal['error', 'warning']
How bad a ConfigProblem is: an error fails the check, a warning does not.
SourceKind¶
SourceKind = Literal['built-in', 'package', 'user', 'project', 'explicit', 'load']
Where a source comes from: built-in, package, user, project, explicit (-e), or
load (a load key no source has).
SourceState¶
SourceState = Literal['always', 'on', 'off', 'shadowed', 'failed', 'untrusted']
Whether a source's extensions are loaded: always (tau and session_name), on, off,
shadowed by another source, failed, or untrusted.
SystemPrompt¶
@dataclass(frozen=True)
class SystemPrompt
text: str
sources: tuple[PromptSource, ...]
An assembled prompt: the text of the System node, and its sources in order.
TrustError¶
class TrustError(PermissionError)
A project directory tau cannot or will not trust, with the reason. where is the
path the refusal is about (None: the project as a whole).
TrustError.init¶
def __init__(self, message: str, where: Path | None = None) -> None
Trusted¶
@dataclass(frozen=True)
class Trusted
root: Path
config_text: str | None
env_text: str | None
extension_files: Mapping[str, bytes] | None
system_md: bytes | None
prompt_files: Mapping[str, bytes]
A trusted project: its root, and the exact .tau/config.json and .env text that
was approved (None: no such file). extension_files is every file under
.tau/extensions/ as approved (path relative to it, with /, to bytes; None: there is no
such directory), which the extension loader imports from and never re-reads; system_md the
bytes of .tau/SYSTEM.md as approved (None: no such file), which the prompt's assembly
reads. prompt_files are the approved prompts/NAME.md and skills/NAME/SKILL.md (path
relative to .tau/, with /, to bytes), which the skills extension reads. Use layer(),
read_models() and project_environment rather than re-reading the files.
Trusted.layer¶
def layer(self) -> LayerText | None
The project config layer for read_models, or None if there is no file.
Trusted.read_models¶
def read_models(
self,
user: Path | LayerText | None = None,
cli: Mapping[str, object] | None = None,
) -> ModelCatalog
read_models(user, <the approved project config>, cli): the project layer is
the text that was approved, not whatever the file says now.
UntrustedProject¶
class UntrustedProject(TrustError)
The project is not trusted (or its config or .env changed). The message says what it
sets and what is wrong with .tau/, and the command that trusts it unless it has errors
to fix first; layer is the config it holds (None: no file), for showing its problems.
UntrustedProject.init¶
def __init__(self, root: Path, message: str, layer: LayerText | None) -> None
UserConfig¶
@dataclass(frozen=True)
class UserConfig
home: Path
project: LayerText | None = None
cli: Mapping[str, object] | None = None
The layers a frontend loaded: the user's file under home (TAU_HOME), the approved
project layer over it and the cli overrides over that, as load_config read them.
save_options writes the user layer and reads all three again, so the catalog it returns is
what load_config would return now. The file is what every session reads; a Config node is
one branch's.
UserConfig.save_options¶
def save_options(
self,
changes: Mapping[str, Mapping[str, object]],
check: Callable[[ModelCatalog], None],
) -> ModelCatalog
Set extensions.<name>.<field> in the user's file for each field of changes
(extension, then field, to JSON value); the file's other content stays. check is
given the catalog the layers make with the change, before anything is written, and
raises ConfigError for options it refuses. Writes atomically, creating the file (and
home, private) if absent; a symlink is followed, so the file it names is replaced and
the link stays (a dangling one is a ConfigError naming it). Returns the catalog;
nothing is written if any step raised. The read-change-write has no await, so on the
event loop calls do not interleave; it is not safe against another τ process saving at
once, or sync commands saving at once from worker threads (the last write wins).
ConfigError for a file or a result the loader refuses, TrustError for a disk that
refuses.
UserConfig.save_load¶
def save_load(self, key: str, on: bool) -> ModelCatalog
Set load.<key> to on in the user's file (D19 section 3; tau ext enable and
disable): whether the extension source key is loaded at start. The file's other
content stays; it is written as save_options writes: atomically, a symlink followed,
nothing written if a step raised. Returns the catalog the layers make now, whose load
shows whether a nearer layer overrules the value. This does not know the sources: whether
key names one is for the caller. ConfigError for a file the loader refuses,
TrustError for a disk that refuses.
UserConfig.save_theme¶
def save_theme(self, name: str) -> None
Set tui.theme to name in the user's file (D23 ruling 3): the theme every later tau
opens in, unless --theme says otherwise for one run. The file's other content stays; it
is written as save_options writes: atomically, a symlink followed, nothing written if
a step raised. This does not know the themes: whether name is one is for the caller.
ConfigError for a file the loader refuses, TrustError for a disk that refuses.
UserConfig.saved¶
def saved(self, extension: str) -> dict[str, object]
extensions.<extension> as the user's file itself holds it: the fields it sets, as
JSON values, and none of the project's, the overrides' or a node's ({} if the file
sets none, or there is no file). ConfigError for a file the loader refuses.
check_config¶
def check_config(
user: Layer | None = None,
project: Layer | None = None,
cli: Mapping[str, object] | None = None,
environ: Mapping[str, str] | None = None,
*,
providers: Mapping[str, Provider],
extensions: Sequence[object] = (),
) -> tuple[ConfigProblem, ...]
Every problem in the layers, not just the first. Layers: user < project < cli.
providers is the driver's map of name to provider: a model may name exactly those, and
each provider's check(model) problems for the models naming it are added (D15).
extensions are those a program loads: an option the layers set for one that its options
type does not have, one that does not fit, or a required one nobody set is a problem.
Options for an extension not given are not looked at (it may be loaded elsewhere).
With environ, a model whose api_key_env names an unset variable is a
warning. An empty result means the layers are sound.
list_extensions¶
def list_extensions(
cwd: Path,
environ: Mapping[str, str],
*,
explicit: Sequence[str] = (),
discover: bool = True,
) -> list[ExtensionSource]
One ExtensionSource per source in load order, tau and session_name first: what a start
in cwd would import (it imports the same, and shows a failure as a row instead of raising
it). It
never asks about trust: a project that is not trusted shows its sources as untrusted.
ConfigError or TrustError for config or trust files the loader refuses.
load_config¶
def load_config(
cwd: Path,
environ: Mapping[str, str],
*,
ask: Ask | None,
cli: Mapping[str, object] | None = None,
) -> LoadedConfig
The layers for a frontend started in cwd: user config, the project's if trusted,
then cli overrides.
ask is the live terminal's approval question (prompts(...).ask); without one an
untrusted project raises UntrustedProject. ConfigError and TrustError propagate
unchanged. The returned environ is environ over the trusted project's .env.
load_extensions¶
def load_extensions(
loaded: LoadedConfig,
*,
explicit: Sequence[str] = (),
discover: bool = True,
) -> list[Extension]
The extensions to run, in hook order (the driver puts tau first; a program adds
session_name, D18, after this returns).
The sources are the built-ins that load leaves on and, with discover, the installed
packages and the user's and the trusted project's drop-ins that it leaves on; then
explicit (-e values: paths, or the keys of sources, discovered or built-in, which load
whatever load says; relative paths are taken against the working directory, see
absolute_explicit). Without discover (--no-extensions) the packages and drop-ins are
skipped, explicit still loads, and the built-ins (base_tools, step_limit) stay as load
says. base_tools is built when this runs and roots its tools at the process's working
directory then, so a program that calls this must change directory first, as start_session
does.
ExtensionLoadError naming every source that failed, with the one command that gets past
each: nothing is started or written by then.
model_config¶
def model_config(
model: str | None = None,
extensions: Mapping[str, Mapping[str, object]] | None = None,
) -> Config
The Config node body that sets model (a catalog's qualified name; it holds that name
and nothing resolved from the file) and/or the options in extensions
({"step_limit": {"limit": 10}}), from this node on, and nothing else. ConfigError if
it sets neither.
prompts¶
def prompts(stdin: TextIO, stdout: TextIO) -> Prompts
The Prompts for these streams.
read_models¶
def read_models(
user: Layer | None = None,
project: Layer | None = None,
cli: Mapping[str, object] | None = None,
) -> ModelCatalog
Merge the layers (user < project < cli; each may be absent) and resolve.
Raises ConfigError listing every error; warnings ride on the catalog.
select_model¶
def select_model(catalog: ModelCatalog, requested: str | None = None, *, pick: Pick | None) -> str
The qualified name to use: requested (--model), else the catalog's default_model.
A name with : must be exactly a qualified name. A bare name with one match is that
match; with several, pick (a live terminal) chooses among the qualified names and
without one ConfigError lists them. No match is a ConfigError with close names.
system_prompt¶
def system_prompt(
cwd: Path,
loaded: LoadedConfig,
*,
append: Sequence[str] = (),
context_files: bool = True,
) -> SystemPrompt
The prompt for a session in cwd (resolved here), given the loaded config: its base text,
append (--append-system-prompt, in order) and, if context_files, the files as the module
says. A part with no text is left out. ContextFileError for a file found and unusable.