pub struct TypedPromptRequest<'a, T, M, P>{ /* 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
§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, M, P>
impl<'a, T, M, P> TypedPromptRequest<'a, T, M, P>
Sourcepub fn from_agent(
agent: &Agent<M, P>,
prompt: impl Into<Message>,
) -> TypedPromptRequest<'a, T, M, P>
pub fn from_agent( agent: &Agent<M, P>, prompt: impl Into<Message>, ) -> TypedPromptRequest<'a, T, M, P>
Create a new TypedPromptRequest from an agent.
This automatically sets the output schema based on the type parameter T.
Sourcepub fn max_turns(self, depth: usize) -> TypedPromptRequest<'a, T, M, P>
pub fn max_turns(self, depth: usize) -> TypedPromptRequest<'a, T, 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, M, P>
pub fn with_tool_concurrency( self, concurrency: usize, ) -> TypedPromptRequest<'a, T, 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, M, P>
pub fn with_history( self, history: &'a mut Vec<Message>, ) -> TypedPromptRequest<'a, T, M, P>
Add chat history to the prompt request.
Sourcepub fn with_hook<P2>(self, hook: P2) -> TypedPromptRequest<'a, T, M, P2>where
P2: PromptHook<M>,
pub fn with_hook<P2>(self, hook: P2) -> TypedPromptRequest<'a, T, M, P2>where
P2: PromptHook<M>,
Attach a per-request hook for tool call events.
This overrides any default hook set on the agent.
Trait Implementations§
Source§impl<'a, T, M, P> IntoFuture for TypedPromptRequest<'a, T, M, P>where
T: JsonSchema + DeserializeOwned + WasmCompatSend + 'a,
M: CompletionModel + 'a,
P: PromptHook<M> + 'static,
impl<'a, T, M, P> IntoFuture for TypedPromptRequest<'a, T, M, P>where
T: JsonSchema + DeserializeOwned + WasmCompatSend + 'a,
M: CompletionModel + 'a,
P: PromptHook<M> + 'static,
Source§type Output = Result<T, StructuredOutputError>
type Output = Result<T, StructuredOutputError>
The output that the future will produce on completion.
Source§type IntoFuture = Pin<Box<dyn Future<Output = <TypedPromptRequest<'a, T, M, P> as IntoFuture>::Output> + Send + 'a>>
type IntoFuture = Pin<Box<dyn Future<Output = <TypedPromptRequest<'a, T, M, P> as IntoFuture>::Output> + Send + 'a>>
Which kind of future are we turning this into?
Source§fn into_future(
self,
) -> <TypedPromptRequest<'a, T, M, P> as IntoFuture>::IntoFuture
fn into_future( self, ) -> <TypedPromptRequest<'a, T, M, P> as IntoFuture>::IntoFuture
Creates a future from a value. Read more
Auto Trait Implementations§
impl<'a, T, M, P> Freeze for TypedPromptRequest<'a, T, M, P>where
P: Freeze,
impl<'a, T, M, P> !RefUnwindSafe for TypedPromptRequest<'a, T, M, P>
impl<'a, T, M, P> Send for TypedPromptRequest<'a, T, M, P>
impl<'a, T, M, P> Sync for TypedPromptRequest<'a, T, M, P>where
T: Sync,
impl<'a, T, M, P> Unpin for TypedPromptRequest<'a, T, M, P>
impl<'a, T, M, P> UnsafeUnpin for TypedPromptRequest<'a, T, M, P>where
P: UnsafeUnpin,
impl<'a, T, M, P> !UnwindSafe for TypedPromptRequest<'a, T, M, P>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more