Skip to main content

Completion

Struct Completion 

Source
pub struct Completion {
    pub text: String,
    pub model: Option<String>,
    pub tool_calls: Vec<ToolCall>,
    pub usage: Usage,
    pub stop_reason: Option<String>,
    pub truncated: bool,
    pub structured: Option<Value>,
    pub continuation: Option<ProviderContinuation>,
    pub reasoning: Option<String>,
    pub commentary: Option<String>,
    pub compacted: Option<Compacted>,
    pub stopped: bool,
}
Expand description

What came back.

Fields§

§text: String§model: Option<String>

The model that actually answered, as the provider reported it.

Not the model that was asked for — that is on the effect’s descriptor and in its provenance source, and it is hashed into the effect key. This is the provider’s own word about which weights served the request, and the two differ whenever an alias resolves (claude-opus-latest), a deployment is moved under a pinned name, or a gateway routes elsewhere. Without it a run’s evidence says only which model was requested, and a substitution is invisible to the party the journal exists to convince.

None where the wire does not say. Bedrock’s Converse response is the shipped case: it carries no model field, and reporting the requested one here would hide exactly the substitution this field exists to expose.

§tool_calls: Vec<ToolCall>

Tools the model asked to call.

Empty for an ordinary answer, and empty for the forced-tool path used to obtain structured output: that tool is this crate’s mechanism for “answer in this shape”, not a request for the runtime to do anything, and surfacing it would make every schema-shaped completion look like a tool invocation.

Filled identically by the buffered and streaming paths. Streaming is the default, so a field populated only when buffering would be silently empty in most deployments — which is worse than absent, because callers would build loops on it and see them never fire.

§usage: Usage§stop_reason: Option<String>

Why generation stopped, in the provider’s words.

Passed through unnormalised on purpose: end_turn, max_tokens, incomplete:max_output_tokens and stop mean subtly different things to the providers that emit them, and flattening them into a shared vocabulary would lose exactly the detail a caller debugging a truncated answer needs. The one thing a caller must not have to parse out of it is whether the answer is complete — see truncated.

§truncated: bool

Whether the answer was cut short.

A typed field rather than a string a caller has to recognise, and its own field rather than an error, for the same reason the worklist reports truncated beside its page: a partial answer returned as a whole one is a silent truncation, which this crate refuses everywhere else (P7).

It is not an error because a cut-off answer is often still useful — prose that stops early is readable, and the caller is the only one who knows whether they were parsing JSON. What they must not be able to do is overlook it, and a bool in the struct they already destructure is harder to overlook than a stop reason they have to compare against a provider-specific string.

§structured: Option<Value>

The answer parsed as JSON, when a schema was asked for.

None when no schema was declared. When one was, this is the parsed value and text still holds the raw string.

Provider constrained decoding prevents malformed output before tokens are emitted; this crate then validates the parsed value locally as defense in depth. Provider bugs and forced-tool best-effort behavior are therefore loud, metered Unusable responses rather than malformed data reaching downstream code. External schema references are not resolved: validation performs no hidden file or network I/O.

§continuation: Option<ProviderContinuation>

Provider-owned response items required to continue this exact turn.

This is deliberately opaque to the runtime. OpenAI uses complete Responses output items (including encrypted reasoning); Anthropic uses the complete assistant content blocks (including signed thinking). The next request returns the value only to the provider that issued it. Keeping it in the journal makes continuation independent of expiring provider-side conversation state and reproducible on replay.

§reasoning: Option<String>

The provider’s readable summary of how the model reasoned, when the call asked for one and the provider gave one.

The model’s own account, and only that: never the signed, encrypted or redacted reasoning the continuation carries, which stays the provider’s to read. It is part of the answer, so it is journaled and replayed with it and carries its label — a summary of reasoning over hostile input is as untrusted as the text beside it.

None when the call did not ask, and when it asked and the provider summarised nothing this turn — a short answer often has no summary.

§commentary: Option<String>

What the model said beside its calls, where the wire marks it apart from the answer.

Responses sends a model’s narration on its way to a tool call as a message in the commentary phase, and text leaves it out so a schema-bearing answer still parses. Every other wire marks no phase, so the same words are in text and this is None. Part of the answer: journaled, replayed and labelled with it.

§compacted: Option<Compacted>

The provider compacted the conversation during this call, when the call asked it to.

The compaction itself lives in continuation, which the next call sends back; this says that it happened, so a reader of the journal knows the model worked from a summary from here on.

§stopped: bool

The call was stopped while it streamed.

text is what arrived before the stop, and usage is what the wire had reported by then — a floor, since most providers report output tokens only at the end. A half-sent tool call is not a request, so tool_calls is empty, and there is no continuation: the turn did not finish.

Implementations§

Source§

impl Completion

Source

pub fn stopped(usage: Usage) -> Self

A streamed call stopped, having been billed usage so far. The text is the one streamed, which the call keeps.

Trait Implementations§

Source§

impl Clone for Completion

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Completion

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Completion

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Completion

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Completion

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Completion

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Completion

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more