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.
Providers¶
The model APIs: the contract a provider keeps, and the three hosted providers (the mock one is builtin_providers()["mock"]).
Names: AnthropicProvider, Finish, GeminiProvider, OpenAIProvider, Provider, ProviderClosed, RetryProvider, SampleError, builtin_providers, replay_for
AnthropicProvider¶
class AnthropicProvider
Samples the Anthropic Messages API (/v1/messages) for the ModelConfig the driver
resolved. base_url is the API's root, https://api.anthropic.com when unset (a proxy
that speaks the same API may be named; give no /v1).
One client serves every sample (see Connection). transport replaces the network (a
test's httpx.MockTransport); environ is where api_key_env is looked up, at sample
time.
check requires a key (api_key_env) and max_tokens (the API requires it; there is no
default), and reads the options in _OPTIONS, refusing any other: thinking (an object as
the API takes it: type a string, budget_tokens for enabled, display; the API judges
the values, and check refuses only what needs a beta header this provider cannot send),
effort (a string, sent as output_config.effort),
temperature, top_p (numbers), top_k (an integer), prompt_caching (a boolean,
default true: mark the system text and the last message for caching), and extra_body (an
object merged into the request body last; it may not set model, messages, system,
stream, tools, max_tokens, thinking, or a key the model's settings set).
AnthropicProvider.init¶
def __init__(
self,
transport: httpx.AsyncBaseTransport | None = None,
environ: Mapping[str, str] | None = None,
timeout: httpx.Timeout | None = None,
) -> None
AnthropicProvider.name¶
property name: str
"anthropic": what a model's provider setting calls it.
AnthropicProvider.check¶
def check(self, model: ModelConfig) -> list[str]
Problems with the model's settings as this provider reads them.
AnthropicProvider.aclose¶
async def aclose(self) -> None
Close the client and its connections. Later samples fail.
AnthropicProvider.sample¶
async def sample(
self,
walk: Sequence[Node],
model: ModelConfig,
tools: Sequence[Tool],
) -> AsyncGenerator[Part | Finish | Delta, None]
Yield deltas as they arrive and each part once complete (before the first delta of
whatever follows it), then the Finish. A failure raises SampleError (with status
and retry_after for an HTTP error, and a status for an error event of a known
type) after yielding every part the stream had finished. Once stop_reason has arrived
the reply is done: the stream is still read for the final usage, and a reset, an
error event, or malformed SSE after it costs only the usage not yet received.
Finish¶
@dataclass(frozen=True)
class Finish
stop: Stop
reason: str | None = None
meta: str | None = None
The end of a reply: the normalised stop, and the provider's own finish string
(None if it has none to report), and meta: what the response carried besides its
parts, as the text of a JSON object (None if it carried nothing). Anything else raises
ValueError here.
GeminiProvider¶
class GeminiProvider
Samples Gemini's streamGenerateContent (?alt=sse) for the ModelConfig the driver
resolved.
One client serves every sample (see Connection). transport replaces the network (a
test's httpx.MockTransport); environ is where api_key_env is looked up, at sample
time.
Settings: base_url defaults to the official endpoint; a proxy sets it. A key is required
(api_key_env or api_key) and goes in the x-goog-api-key header. max_tokens is
maxOutputTokens, which Gemini counts thinking into. Options (check refuses any other):
temperature, top_p, top_k (numbers); thinking, an object of include_thoughts (bool:
ask for thought summaries, which arrive as Thinking; without it none are requested),
budget (integer, -1 dynamic, 0 off: Gemini 2.5) or level (a string: Gemini 3), not both;
safety_settings, a list of {category, threshold} passed through, one per category; and
extra_body, an object merged into the request last, for what the API has that these do
not (it may not set contents, systemInstruction or tools, nor a key the model's
settings set; its generationConfig merges into ours).
GeminiProvider.init¶
def __init__(
self,
transport: httpx.AsyncBaseTransport | None = None,
environ: Mapping[str, str] | None = None,
timeout: httpx.Timeout | None = None,
) -> None
GeminiProvider.name¶
property name: str
"gemini": what a model's provider setting calls it.
GeminiProvider.check¶
def check(self, model: ModelConfig) -> list[str]
Problems with the model's settings: no key named, an unknown or ill-typed option. An
unset api_key_env variable is not one: tau config check warns of it, sampling fails.
GeminiProvider.aclose¶
async def aclose(self) -> None
Close the client and its connections. Later samples fail.
GeminiProvider.sample¶
async def sample(
self,
walk: Sequence[Node],
model: ModelConfig,
tools: Sequence[Tool],
) -> AsyncGenerator[Part | Finish | Delta, None]
Yield deltas as they arrive and each part once complete (before the first delta of
whatever follows it), then the Finish. A failure raises SampleError (with status
and retry_after for an HTTP error or an error event) after yielding every part the
stream had finished or begun; it carries the meta that had arrived. Once finishReason
has arrived the reply is done: the stream is still read for usageMetadata, and a failure
after it costs only the meta not yet received. A prompt the API blocked (promptFeedback
with a blockReason) ends as End, the reason in finish_reason and the block in
meta.
OpenAIProvider¶
class OpenAIProvider
Samples an OpenAI-compatible /chat/completions endpoint for the ModelConfig the
driver resolved.
One client serves every sample (see Connection). transport replaces the network (a
test's httpx.MockTransport); environ is where api_key_env is looked up, at sample
time.
Options (check refuses any other): temperature and top_p (numbers),
reasoning_effort (a string), include_usage (a boolean, default true: ask the server for
token counts in the stream; some reject it), and extra_body (an object merged into the
request body last, for a server's own parameters such as llama.cpp's cache_prompt; it may
not set model, messages, stream, or tools).
OpenAIProvider.init¶
def __init__(
self,
transport: httpx.AsyncBaseTransport | None = None,
environ: Mapping[str, str] | None = None,
timeout: httpx.Timeout | None = None,
) -> None
OpenAIProvider.name¶
property name: str
"openai": what a model's provider setting calls it.
OpenAIProvider.check¶
def check(self, model: ModelConfig) -> list[str]
This provider needs a base_url, and reads the options in _OPTIONS.
OpenAIProvider.aclose¶
async def aclose(self) -> None
Close the client and its connections. Later samples fail.
OpenAIProvider.sample¶
async def sample(
self,
walk: Sequence[Node],
model: ModelConfig,
tools: Sequence[Tool],
) -> AsyncGenerator[Part | Finish | Delta, None]
Yield deltas as they arrive and each part once complete (before the first delta of
whatever follows it), then the Finish. A failure raises SampleError (with status
and retry_after for an HTTP error) after yielding every part the stream had finished
or begun; it carries the meta fields that had arrived. Once finish_reason has arrived the
reply is done: the stream is
still read for usage, but content and tool-call deltas after it are ignored, and an
error chunk, a reset, malformed SSE, or a missing [DONE] after it costs only the
meta not yet received, never the reply. A refusal delta is text.
Provider¶
class Provider(Protocol)
One API family, long-lived: the program that builds it closes it (D15). Owes the
driver model.md section 10 (the parts of it built so far).
Provider.name¶
property name: str
What a model's provider setting calls it.
Provider.check¶
def check(self, model: ModelConfig) -> list[str]
Problems with the model's settings as this provider reads them: a missing
base_url it needs, one it has no use for, an unknown or ill-typed option, a model
whose provider is not its own. Empty if the model is fine. tau config check
calls it for every model that names the provider.
Provider.sample¶
def sample(
self,
walk: Sequence[Node],
model: ModelConfig,
tools: Sequence['Tool'],
) -> AsyncGenerator[Part | Finish | Delta, None]
model is the session's named model, resolved by the driver at this sample. Yield,
interleaved: deltas as text arrives (TextDelta, ThinkingDelta, CallNamed then
CallArgs), each whole part as it finishes, then the Finish, then end. The driver
saves only the parts and forwards the deltas. A part is yielded before the first delta
of the next part; a delta that breaks this fails the sample. tools are the driver's,
offered to the model for this sample only; they are never recorded.
sample assumes check(model) returned no problems: the driver calls it first, for
every sample, and fails the sample with the problems listed if it returns any, so
sample does not re-check. It closes the generator when it stops reading.
Raise SampleError to fail; parts yielded before it are kept. Any other Exception
(from check or from sample) fails this sample the same way, with its message as
Type: message and internal: true in meta.error, and its traceback on stderr: a
bug in a provider costs one sample, never the driver. If the sample is cancelled or
fails, the driver saves the text or thinking whose deltas arrived but whose part never
did. A part yielded while deltas are open must be the part
those deltas were building (same kind, same text), and Finish may not come with deltas
open.
Provider.aclose¶
async def aclose(self) -> None
Close what the provider holds open (connections).
ProviderClosed¶
class ProviderClosed(SampleError)
A sample on a provider whose aclose() has been called, or one cut off by it. Not a
transient failure: a retry cannot succeed, so a retrying wrapper passes it on.
RetryProvider¶
class RetryProvider
inner, with up to 3 retries per sample (the module docstring). sleep is how it waits
(seconds); a test passes its own.
RetryProvider.init¶
def __init__(
self,
inner: Provider,
*,
sleep: Callable[[float], Awaitable[None]] = asyncio.sleep,
) -> None
RetryProvider.name¶
property name: str
The inner provider's name.
RetryProvider.check¶
def check(self, model: ModelConfig) -> list[str]
The inner provider's check.
RetryProvider.aclose¶
async def aclose(self) -> None
Close the inner provider.
RetryProvider.sample¶
async def sample(
self,
walk: Sequence[Node],
model: ModelConfig,
tools: Sequence[Tool],
) -> AsyncGenerator[Part | Finish | Delta, None]
The inner provider's sample, tried again as the module says.
SampleError¶
class SampleError(Exception)
A sample that failed: an HTTP error, a reset connection, a conversion error. meta is
what the response had already said about itself (as on Finish), kept on the failed reply.
status is the HTTP status of an error response (None for a failure with none, such as a
refused connection); retry_after is the seconds the server asked to wait (None if it
did not say). A retrying wrapper provider reads both (D15).
SampleError.init¶
def __init__(
self,
message: str = '',
meta: str | None = None,
*,
status: int | None = None,
retry_after: float | None = None,
) -> None
builtin_providers¶
def builtin_providers(environ: Mapping[str, str]) -> dict[str, Provider]
The built-in providers by name ("openai", "anthropic", "gemini", "mock"), ready
to hand to Driver and check_config. environ is where the hosted providers look up API
keys. The caller closes them (await p.aclose()).
replay_for¶
def replay_for(part: Part, provider: str) -> dict[str, object] | None
The replay data provider may send back for part, parsed: the JSON object in
part.replay.data when the part carries replay tagged with provider; None for a part
with none, or with another provider's, which the caller treats as unsigned (model.md
10.4). The exact text is part.replay.data: string values parse back exactly, but numbers
and escapes may not re-serialize to the same bytes. Raises TypeError for a non-Part.