Skip to main content

Module llm

Module llm 

Source
Expand description

One provider-neutral API layer for the assistant (design: docs/src/research/agent-interface.md).

This module knows nothing about TeamCraft (no Actor, no mcp): it holds the neutral conversation types, the pure Provider trait (encode a request, decode a reply, map an error – no I/O, so recorded provider bodies test it directly) and the Transport trait with its one HTTP implementation in http. The wire formats live in one file each (anthropic).

The tool loop in crate::assistant only sees these types.

Modules§

anthropic
The Anthropic Messages API: request encoding (prompt caching, the server-side fallback beta), reply decoding and the error table.
http
The one HTTP client of the LLM layer: timeouts, no redirects (a 3xx is an error, so the API key never goes to a second host), the key only in its request header.
openai
Chat Completions (POST {base}/chat/completions), the format OpenAI, Azure OpenAI (v1), Mistral, OpenRouter, Groq, Ollama, vLLM and LM Studio speak. Stateless like the Messages API, so the loop stays the same.

Structs§

HttpCall
A request ready to send: the path below the base URL, headers (without the API key) and the JSON body.
HttpResponse
An HTTP answer.
Reply
A decoded model reply.
Request
One model call.
ToolCall
One tool call of the model.
ToolResult
The result of one tool call, handed back to the model.
ToolSpec
A tool the model may call. schema is the JSON Schema of the input.
Usage
Token counts of one call. input means all prompt tokens (cached ones included).

Enums§

AuthStyle
How the API key is sent.
LlmError
Why a model call failed.
Stop
Why the model stopped.
Turn
One entry of the conversation.

Traits§

Provider
One wire format. Pure: no network, no clock, no database.
Transport
Sends one HTTP call and returns the response as it is (any status).

Functions§

complete
One model call, one attempt: encode, send, map errors, decode.
cut
Cuts s to at most max bytes at a character boundary.
error_message
The error.message of a JSON error body, cut short.
retry_after
retry-after in seconds (the HTTP-date form is not used by the APIs).
status_error
The one error table of all providers (design page): 401/403 are an authentication error, 402 and a billing-quota 429 a quota error (no retry), other 429s are rate limits with their retry-after, 5xx (also 529) an overloaded service, a context-length rejection its own error, everything else a rejected request.