Skip to main content

RequestPatch

Struct RequestPatch 

Source
#[non_exhaustive]
pub struct RequestPatch { pub preamble: Option<String>, pub temperature: Option<f64>, pub max_tokens: Option<u64>, pub tool_choice: Option<ToolChoice>, pub active_tools: Option<Vec<String>>, pub additional_params: Option<Value>, pub extra_context: Vec<Document>, pub history: Option<Vec<Message>>, }
Expand description

A partial patch over the model request for a single turn, returned by a hook via Flow::PatchRequest on a StepEvent::CompletionCall event.

Every field is optional: a Some value overrides the agent’s configured value for this turn, a None value inherits it. The patch is per-turn and non-sticky — it never changes the agent’s baseline, so the next turn re-fires CompletionCall and resolves from the baseline again.

§Merge behavior

Two kinds of merge apply. When several hooks in a HookStack each return a patch, they are combined hook ⊕ hook in registration order with these per-field rules; the effective patch is then applied patch → baseline.

Fieldhook ⊕ hook (registration order)patch → baseline
extra_contextappend (earlier hooks’ docs first)append after static + dynamic context
additional_paramsshallow-merge top-level keys, later hook winsshallow-merge onto baseline params
preamblelast writer wins (warns on conflict)replaces
temperature, max_tokens, tool_choicelast writer wins (warns on conflict)replaces
active_toolsset intersection (warns when empty)narrows the advertised set
historylast writer wins (warns on conflict)replaces the messages sent this turn

active_tools intersects rather than last-writer-wins because it is an allow-list guardrail: two narrowing hooks must compose as narrowing. All last-writer-wins conflicts emit a tracing::warn! so composition stays debuggable — additive guidance belongs in extra_context documents, not in preamble concatenation.

Build one with the setters:

Flow::patch_request(
    RequestPatch::new()
        .tool_choice(ToolChoice::Required)
        .active_tools(["search"])
        .temperature(0.0),
)

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§preamble: Option<String>

Override the system prompt / preamble for this turn.

§temperature: Option<f64>

Override the sampling temperature for this turn.

§max_tokens: Option<u64>

Override the max output tokens for this turn.

§tool_choice: Option<ToolChoice>

Override the tool choice for this turn.

§active_tools: Option<Vec<String>>

Restrict the advertised tools to this allow-list (by name) for this turn. Some(vec![]) advertises no executable tools; None keeps the full set.

§additional_params: Option<Value>

Provider-passthrough params shallow-merged onto the agent’s for this turn.

§extra_context: Vec<Document>

Extra context documents appended (after static and dynamic context) for this turn only. The passive-RAG injection point.

§history: Option<Vec<Message>>

Replace the prior chat history sent to the provider this turn only. The persisted transcript and the run state are untouched, and RAG’s query text still derives from the original prompt/history — this changes only what messages are sent. None sends the real history. The enabling primitive for context-window compaction / summarization middleware.

Implementations§

Source§

impl RequestPatch

Source

pub fn new() -> Self

An empty patch — a no-op, identical to returning Flow::cont.

Source

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

Override the system prompt / preamble for this turn.

Source

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

Override the sampling temperature for this turn.

Source

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

Override the max output tokens for this turn.

Source

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

Override the tool choice for this turn.

Not every provider honors tool_choice: some in-core providers (e.g. Ollama, Hyperbolic, Mira, Perplexity) ignore it and log a warning, so forcing a tool this way is a no-op there. A choice a provider cannot represent (e.g. a multi-name ToolChoice::Specific on Anthropic, which forces a single tool) surfaces as a request error rather than being silently downgraded.

Source

pub fn active_tools<I, S>(self, names: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Restrict the advertised tools to this allow-list (by name) for this turn.

This narrows the executable tool set, so it composes with tool_choice: if the effective tool choice is a ToolChoice::Specific naming a tool that active_tools filters out (e.g. the agent’s baseline choice is inherited because this patch didn’t set its own), the request fails closed with a request error rather than silently forcing a dropped tool. When narrowing the set, set a compatible tool_choice in the same patch.

Source

pub fn additional_params(self, additional_params: Value) -> Self

Shallow-merge these provider-passthrough params onto the agent’s for this turn.

Source

pub fn extra_context<I>(self, docs: I) -> Self
where I: IntoIterator<Item = Document>,

Append extra context documents for this turn (the passive-RAG injection point). Documents are appended after the agent’s static and dynamic (vector-store) context, in the order added.

Source

pub fn context(self, doc: Document) -> Self

Append a single extra context document for this turn.

Source

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

Replace the prior chat history sent to the provider this turn only. The persisted transcript is untouched; RAG query text still derives from the original history. Use for context-window compaction / summarization.

Trait Implementations§

Source§

impl Clone for RequestPatch

Source§

fn clone(&self) -> RequestPatch

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 RequestPatch

Source§

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

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

impl Default for RequestPatch

Source§

fn default() -> RequestPatch

Returns the “default value” for a type. Read more
Source§

impl PartialEq for RequestPatch

Source§

fn eq(&self, other: &RequestPatch) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RequestPatch

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

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> CloneableStorage for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> DebuggableStorage for T
where T: Any + Send + Sync + Debug,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> 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.
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