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>) -> Self
pub fn from_agent(agent: &Agent<M, P>, prompt: impl Into<Message>) -> Self
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) -> Self
pub fn max_turns(self, depth: usize) -> Self
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) -> Self
pub fn with_tool_concurrency(self, concurrency: usize) -> Self
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>) -> Self
pub fn with_history(self, history: &'a mut Vec<Message>) -> Self
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) -> Self::IntoFuture
fn into_future(self) -> Self::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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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