pub struct TypedPromptRequest<'a, T, S, M, P>where
T: JsonSchema + DeserializeOwned + WasmCompatSend,
S: PromptType,
M: CompletionModel,
P: PromptHook<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<'a, T, M, P> TypedPromptRequest<'a, T, Standard, M, P>
impl<'a, T, M, P> TypedPromptRequest<'a, T, Standard, M, P>
Sourcepub fn from_agent(
agent: &Agent<M, P>,
prompt: impl Into<Message>,
) -> TypedPromptRequest<'a, T, Standard, M, P>
pub fn from_agent( agent: &Agent<M, P>, prompt: impl Into<Message>, ) -> TypedPromptRequest<'a, T, Standard, M, P>
Create a new TypedPromptRequest from an agent.
This automatically sets the output schema based on the type parameter T.
Source§impl<'a, T, S, M, P> TypedPromptRequest<'a, T, S, M, P>where
T: JsonSchema + DeserializeOwned + WasmCompatSend,
S: PromptType,
M: CompletionModel,
P: PromptHook<M>,
impl<'a, T, S, M, P> TypedPromptRequest<'a, T, S, M, P>where
T: JsonSchema + DeserializeOwned + WasmCompatSend,
S: PromptType,
M: CompletionModel,
P: PromptHook<M>,
Sourcepub fn extended_details(self) -> TypedPromptRequest<'a, T, Extended, M, P>
pub fn extended_details(self) -> TypedPromptRequest<'a, T, Extended, M, P>
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.
Sourcepub fn max_turns(self, depth: usize) -> TypedPromptRequest<'a, T, S, M, P>
pub fn max_turns(self, depth: usize) -> TypedPromptRequest<'a, T, S, M, P>
Set the maximum number of turns for multi-turn conversations.
A given agent may require multiple turns for tool-calling before giving an answer.
If the maximum turn number is exceeded, it will return a
StructuredOutputError::PromptError wrapping a MaxTurnsError.
Sourcepub fn with_tool_concurrency(
self,
concurrency: usize,
) -> TypedPromptRequest<'a, T, S, M, P>
pub fn with_tool_concurrency( self, concurrency: usize, ) -> TypedPromptRequest<'a, T, S, M, P>
Add concurrency to the prompt request.
This will cause the agent to execute tools concurrently.
Sourcepub fn with_history(
self,
history: &'a mut Vec<Message>,
) -> TypedPromptRequest<'a, T, S, M, P>
pub fn with_history( self, history: &'a mut Vec<Message>, ) -> TypedPromptRequest<'a, T, S, M, P>
Add chat history to the prompt request.
Sourcepub fn with_hook<P2>(self, hook: P2) -> TypedPromptRequest<'a, T, S, M, P2>where
P2: PromptHook<M>,
pub fn with_hook<P2>(self, hook: P2) -> TypedPromptRequest<'a, T, S, M, P2>where
P2: PromptHook<M>,
Attach a per-request hook for tool call events.
This overrides any default hook set on the agent.