Skip to main content

TypedPromptRequest

Struct TypedPromptRequest 

Source
pub struct TypedPromptRequest<T, S, M>{ /* private fields */ }
Expand description

A builder for creating typed prompt requests that return deserialized structured output.

This struct wraps a standard PromptRequest and adds:

  • Automatic JSON schema generation from the target type T
  • Automatic deserialization of the response into T

The type parameter S represents the state of the request (Standard or Extended). Use .extended_details() to transition to Extended state for usage tracking.

§Example

let forecast: WeatherForecast = agent
    .prompt_typed("What's the weather in NYC?")
    .max_turns(3)
    .await?;

Implementations§

Source§

impl<T, M> TypedPromptRequest<T, Standard, M>

Source

pub fn from_agent(agent: &Agent<M>, prompt: impl Into<Message>) -> Self

Create a new TypedPromptRequest from an agent.

This automatically sets the output schema based on the type parameter T.

Source§

impl<T, S, M> TypedPromptRequest<T, S, M>

Source

pub fn extended_details(self) -> TypedPromptRequest<T, Extended, M>

Enable returning extended details for responses (includes aggregated token usage).

Note: This changes the type of the response from .send() to return a TypedPromptResponse<T> struct instead of just T. This is useful for tracking token usage across multiple turns of conversation.

Source

pub fn max_turns(self, max_turns: usize) -> Self

Set the total model-call budget, including the initial call and every retry or continuation. Zero emits no model calls; one permits only the initial call. Exceeding the budget returns a StructuredOutputError::PromptError wrapping a MaxTurnsError.

Source

pub fn add_hook<H>(self, hook: H) -> Self
where H: AgentHook + 'static,

Append a hook to this request’s hook stack (on top of any the agent already carries).

Source

pub fn tool_context(self, context: ToolContext) -> Self

Attach a per-call ToolContext for this request.

Every tool the agent executes during this request can read the caller-provided values (auth tokens, session IDs, conversation state, …) through the tool’s ToolContext, without the model ever seeing them.

Source

pub fn history<H, Item>(self, history: H) -> Self
where H: IntoIterator<Item = Item>, Item: Into<Message>,

Add chat history to the prompt request.

Source

pub fn preamble(self, preamble: impl Into<String>) -> Self

Override the agent preamble for this request.

Source

pub fn without_preamble(self) -> Self

Remove the agent’s configured preamble for this request.

Source

pub fn document(self, document: Document) -> Self

Append one static context document for this request.

Source

pub fn documents(self, documents: impl IntoIterator<Item = Document>) -> Self

Append static context documents for this request.

Source

pub fn temperature(self, temperature: f64) -> Self

Override the model temperature for this request.

Source

pub fn without_temperature(self) -> Self

Remove the agent’s configured temperature for this request.

Source

pub fn max_tokens(self, max_tokens: u64) -> Self

Override the maximum completion token count for this request.

Source

pub fn without_max_tokens(self) -> Self

Remove the agent’s configured maximum token count for this request.

Source

pub fn merge_additional_params(self, params: Map<String, Value>) -> Self

Shallow-merge object fields into the provider-specific parameters for this request. Later fields win.

Source

pub fn replace_additional_params(self, params: Value) -> Self

Replace all provider-specific parameters for this request.

Source

pub fn without_additional_params(self) -> Self

Remove the agent’s configured provider-specific parameters for this request.

Source

pub fn tool_choice(self, tool_choice: ToolChoice) -> Self

Override the tool-choice policy for this request.

Source

pub fn without_tool_choice(self) -> Self

Remove the agent’s configured tool-choice policy for this request.

Source

pub fn record_content_telemetry(self, enabled: bool) -> Self

Opt in or out of recording sensitive request, response, and tool content on GenAI telemetry spans for this request.

Defaults to the agent’s setting, which defaults to false. Enabling this can expose prompts, retrieved context, tool results, model responses, and other sensitive or high-cardinality data through OpenTelemetry span attributes, which can increase observability backend storage and query costs. Only enable it when content telemetry is acceptable for this request. Structural metadata and token usage remain available when disabled.

Source

pub fn conversation(self, id: impl Into<String>) -> Self

Set the conversation id used to load and persist memory for this request.

Overrides any default conversation id set on the agent. If memory is not configured on the agent, this has no effect.

Source

pub fn without_memory(self) -> Self

Disable conversation memory for this request.

History will neither be loaded from nor saved to the agent’s memory backend.

Source

pub fn max_invalid_tool_call_retries(self, retries: usize) -> Self

Set the retry budget for invalid tool-call recovery.

Invalid tool-call retries also consume the total model-call budget.

Source

pub fn tool_concurrency(self, concurrency: usize) -> Self

Execute up to concurrency of a turn’s tool calls at once.

See AgentRunner::tool_concurrency for ordering guarantees: the tool batch commits and surfaces atomically, so persisted history and streamed tool results are both in tool-call order (results are surfaced only after the whole batch settles successfully).

Trait Implementations§

Source§

impl<T, M> IntoFuture for TypedPromptRequest<T, Standard, M>
where T: JsonSchema + DeserializeOwned + WasmCompatSend + 'static, M: CompletionModel + 'static,

Source§

type Output = Result<T, StructuredOutputError>

The output that the future will produce on completion.
Source§

type IntoFuture = Pin<Box<dyn Future<Output = <TypedPromptRequest<T, Standard, M> as IntoFuture>::Output> + Send>>

Which kind of future are we turning this into?
Source§

fn into_future(self) -> Self::IntoFuture

Creates a future from a value. Read more
Source§

impl<T, M> IntoFuture for TypedPromptRequest<T, Extended, M>
where T: JsonSchema + DeserializeOwned + WasmCompatSend + 'static, M: CompletionModel + 'static,

Source§

type Output = Result<TypedPromptResponse<T>, StructuredOutputError>

The output that the future will produce on completion.
Source§

type IntoFuture = Pin<Box<dyn Future<Output = <TypedPromptRequest<T, Extended, M> as IntoFuture>::Output> + Send>>

Which kind of future are we turning this into?
Source§

fn into_future(self) -> Self::IntoFuture

Creates a future from a value. Read more

Auto Trait Implementations§

§

impl<T, S, M> !RefUnwindSafe for TypedPromptRequest<T, S, M>

§

impl<T, S, M> !UnwindSafe for TypedPromptRequest<T, S, M>

§

impl<T, S, M> Freeze for TypedPromptRequest<T, S, M>

§

impl<T, S, M> Send for TypedPromptRequest<T, S, M>
where S: Send,

§

impl<T, S, M> Sync for TypedPromptRequest<T, S, M>
where T: Sync, S: Sync,

§

impl<T, S, M> Unpin for TypedPromptRequest<T, S, M>
where T: Unpin, S: Unpin,

§

impl<T, S, M> UnsafeUnpin for TypedPromptRequest<T, S, M>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,

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
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