Skip to main content

Module completion

Module completion 

Source
Expand description

Runtime errors for the classic agent runtime, plus the portable completion contracts.

use rig_agent::completion::StructuredOutputError;
let error = StructuredOutputError::EmptyResponse;
assert!(error.provider_response_body().is_none());

Re-exports§

pub use crate::run::response::PromptError;

Modules§

handle
Serializable model labels resolved to live handles by a runtime.
history
Shaping a conversation for the model it is sent to. adapt is the one place history meets its target: a turn the same model produced keeps its provider items, any other turn replays from its canonical fields, failed turns are skipped, and every tool call gets an answer.
message
options
Portable generation options: provider-neutral knobs a request sets once and every completion wire maps to its own JSON, or refuses. They hold only what CompletionRequest has no field for, so temperature, max_tokens, tool_choice and output_schema stay on the request.
prompt
A system prompt as data: a role and named sections, rendered into one system message only when the request is sent, so a layer in between can read, change or move a section by its tag.
provider_options
Typed per-provider request options and reply extras. A provider’s ProviderExtension marker names its key, its serialize-only Options and its Extras view of a reply. ProviderOptions holds entries for several providers at once, and each wire reads only the entry named by its own provider.
request
Completion requests, normalized responses, and provider model contracts.

Structs§

Accepts
What a model reads, as replay sees it.
AssistantMessage
One assistant turn.
CompletionRequest
A completion request to any provider’s model.
CompletionResponse
Assistant content and normalized completion metadata. The choice may be empty, including for truncated or filtered turns. Provider-specific data is available through Self::raw without retaining a concrete model type.
ContextUse
The context a conversation’s next request sends, against the model’s input limit.
Cost
What one or more turns cost, in USD. total is what was charged, or when Self::is_complete is false, a lower bound of it.
Document
A document sent with a request as context, rendered before the chat history.
GenerationOptions
Provider-neutral generation knobs for one request. An unset field leaves the provider’s default. A field the wire or model cannot honour is reported through Self::unsupported_policy, never silently dropped.
ModelRef
Model label serialized as a string. Equality compares labels without provider interpretation; resolving a label to a live handle is the runtime’s responsibility.
ProviderCapabilities
Model capabilities used by runtimes when preparing requests. Defaults are conservative; construct through Self::new and setters.
ProviderOptions
Typed options for several providers, one entry per provider key. Each wire reads only the entry named by its own provider. Equality and the serialized form are the entries’ sections. A deserialized entry has no typed options behind it, so its fields are sent as written: inserting the typed options again restores their refusal check.
ProviderToolDefinition
Provider-native tool definition.
ResponseIdentity
Distinct response and transport identifiers for one model call. Unreported identifiers remain None.
Section
A named part of a SystemPrompt.
SystemPrompt
A system prompt in parts: the role, then each non-empty section between <tag> and </tag>, sent as one system message.
ToolAnnotations
What calling a tool does to the world, as the Model Context Protocol’s tool annotations state it, and spelled as they are on its wire (readOnlyHint, …), so an MCP tool’s annotations read straight into one. Each is a hint a tool’s author gives: a host’s policies read them (approval, plan mode, which calls run side by side), never trusting a tool it does not trust for them. A hint left unset takes the protocol’s default, which the accessors apply: not read-only, destructive, not idempotent, open world.
ToolDefinition
A tool the model may call: its name, description and argument schema, sent to the model, and what the tool does to the world (ToolAnnotations), which stays with the host.
UnsupportedOption
An option the wire or model cannot honour. Carried by ProviderError::UnsupportedOption.
Usage
The token usage a provider reported for one completion.
UsageTotals
Many calls’ Usage summed for a running account: the token counters, the known cost, and how many calls the sum holds and how many of them were not fully priced.

Enums§

AssistantContent
One block of an assistant turn: one provider output item. Deserialization requires the lowercase type tag.
CachePoint
A point in a CompletionRequest that ends a stable prefix, for CompletionRequest::cache_points. Prefixes run in the order a request is sent: tools, then the system prompt, then the messages.
CacheRetention
How long the provider keeps the prompt prefix cached.
CheckError
Why a dry run of a completion request failed: what DynModel::check returns.
Effort
A portable reasoning effort level, lowest first.
FinishReason
Normalized generation ending. Unmapped provider values remain in Self::Other. Failure statuses may accompany parseable output; callers must decide whether such output is usable rather than treating every response as successful.
LaterSystem
Where a target takes the system messages that come after the conversation begins (ReplayTarget::later_system).
Media
One media part, as ReplayTarget::encodes sees it. Raw bytes are already base64, and an inline image already has the media type its bytes name.
Message
A provider-agnostic chat message.
OnUnsupported
What happens to an option the wire or model cannot honour.
OptionsError
Why a provider’s options cannot be stored.
Pairing
Which side of a hosted-tool pair an opaque item is.
Place
Where an image sits in a history.
Reasoning
How much the model reasons before answering.
Replay
What an encoder sends for one assistant block.
ServiceTier
The processing tier a request asks for.
StructuredOutputError
Why a typed run produced no value.
Verbosity
How long the answer should be.

Constants§

SHARED
The section every route of a provider reads.

Traits§

ExtensionOptions
A provider’s request options. Serialize-only: the body keys they write are their only output. They are plain data, Send + Sync on every target, since a request carrying them may be held in shared host state, and unwind safe, so a request holding them stays unwind safe.
ProviderExtension
A provider’s typed request options and reply extras.
ReplayTarget
The model a request is sent to, as replay sees it. Every completion wire implements it.
ReplyExtras
A typed view of a reply’s provider document.

Functions§

adapt
history shaped for target.
tokens_label
A token count in at most four characters plus a unit: 999, 1.2k, 45k, 1.2M.