Skip to main content

LlmRequest

Struct LlmRequest 

Source
pub struct LlmRequest {
    pub model: String,
    pub messages: Messages,
    pub system: Option<String>,
    pub max_tokens: Option<u32>,
    pub tools: Vec<ToolSpec>,
    pub effort: Option<String>,
    pub schema: Option<Value>,
}
Expand description

A model call.

Fields§

§model: String

Which model to ask, in the provider’s naming.

§messages: Messages

The conversation so far, oldest turn first.

§system: Option<String>

System prompt, kept apart from messages because providers disagree about where it goes — a system turn, a top-level field, or folded into the first user turn. The client places it at its edge.

§max_tokens: Option<u32>

Cap on generated tokens. A reply that hits it stops with StopReason::MaxTokens, which steps treat as an error, not an answer.

§tools: Vec<ToolSpec>

Tools the model may call, as JSON Schema definitions.

§effort: Option<String>

Reasoning depth, in the provider’s terms (lowmax).

§schema: Option<Value>

JSON Schema the reply must satisfy.

A request, not a guarantee: endpoints that support constrained decoding enforce it, and the rest are asked in the prompt and may still answer with prose. Whoever consumes the reply validates it — see crate::schema::Schema for the graph-level contract, which is a different thing: this constrains one model call, that one constrains an edge.

Implementations§

Source§

impl LlmRequest

Source

pub fn new(model: impl Into<String>, messages: Messages) -> Self

A request with only the essentials: a model and a conversation.

Everything else is opt-in through the with_* builders — and because unset options are skipped when the request is serialized, they are also absent from the journal key (Effect::cache_key). Growing this struct therefore never moves the keys of requests that predate the new knob.

Source

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

Set the system prompt.

Stated here once, placed by the provider client wherever this endpoint wants it — as its own turn, or prepended to the first user turn when the endpoint refuses a system role.

Source

pub fn with_max_tokens(self, n: u32) -> Self

Cap the reply at n generated tokens.

A budget, not a target: a reply that runs into it is a cut-off thought, and LlmResponse::reject_non_answers turns it into an error rather than letting the fragment flow downstream as an answer.

Source

pub fn with_tools(self, tools: Vec<ToolSpec>) -> Self

Offer the model these tools, replacing any previous set.

Offering is all this does. When the model wants one, the reply stops with StopReason::ToolUse and it is the step’s job to perform the calls — typically as Effect::Tool — and ask the model to continue with the results appended to the conversation.

Source

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

Ask for this much reasoning, in the provider’s vocabulary (lowmax).

Passed through verbatim (reasoning_effort on OpenAI-shaped endpoints); endpoints without the concept ignore the unknown field. Like every other knob it is part of the journal key — the same question at a different effort is a different request, so a replay never serves the cheaper answer.

Source

pub fn with_schema(self, schema: Value) -> Self

Ask for a reply shaped like schema.

Source

pub fn into_effect(self) -> Effect

Wrap as the effect a step awaits.

Trait Implementations§

Source§

impl Clone for LlmRequest

Source§

fn clone(&self) -> LlmRequest

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 LlmRequest

Source§

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

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

impl<'de> Deserialize<'de> for LlmRequest

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 Serialize for LlmRequest

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

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> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

The receiver as &dyn Any, ready for downcast_ref.
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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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