#[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.
| Field | hook ⊕ hook (registration order) | patch → baseline |
|---|---|---|
extra_context | append (earlier hooks’ docs first) | append after static + dynamic context |
additional_params | shallow-merge top-level keys, later hook wins | shallow-merge onto baseline params |
preamble | last writer wins (warns on conflict) | replaces |
temperature, max_tokens, tool_choice | last writer wins (warns on conflict) | replaces |
active_tools | set intersection (warns when empty) | narrows the advertised set |
history | last 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
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
impl RequestPatch
Sourcepub fn new() -> Self
pub fn new() -> Self
An empty patch — a no-op, identical to returning Flow::cont.
Sourcepub fn preamble(self, preamble: impl Into<String>) -> Self
pub fn preamble(self, preamble: impl Into<String>) -> Self
Override the system prompt / preamble for this turn.
Sourcepub fn temperature(self, temperature: f64) -> Self
pub fn temperature(self, temperature: f64) -> Self
Override the sampling temperature for this turn.
Sourcepub fn max_tokens(self, max_tokens: u64) -> Self
pub fn max_tokens(self, max_tokens: u64) -> Self
Override the max output tokens for this turn.
Sourcepub fn tool_choice(self, tool_choice: ToolChoice) -> Self
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.
Sourcepub fn active_tools<I, S>(self, names: I) -> Self
pub fn active_tools<I, S>(self, names: I) -> Self
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.
Sourcepub fn additional_params(self, additional_params: Value) -> Self
pub fn additional_params(self, additional_params: Value) -> Self
Shallow-merge these provider-passthrough params onto the agent’s for this turn.
Sourcepub fn extra_context<I>(self, docs: I) -> Selfwhere
I: IntoIterator<Item = Document>,
pub fn extra_context<I>(self, docs: I) -> Selfwhere
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.
Sourcepub fn context(self, doc: Document) -> Self
pub fn context(self, doc: Document) -> Self
Append a single extra context document for this turn.
Sourcepub fn history<I>(self, history: I) -> Selfwhere
I: IntoIterator<Item = Message>,
pub fn history<I>(self, history: I) -> Selfwhere
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
impl Clone for RequestPatch
Source§fn clone(&self) -> RequestPatch
fn clone(&self) -> RequestPatch
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RequestPatch
impl Debug for RequestPatch
Source§impl Default for RequestPatch
impl Default for RequestPatch
Source§fn default() -> RequestPatch
fn default() -> RequestPatch
Source§impl PartialEq for RequestPatch
impl PartialEq for RequestPatch
impl StructuralPartialEq for RequestPatch
Auto Trait Implementations§
impl Freeze for RequestPatch
impl RefUnwindSafe for RequestPatch
impl Send for RequestPatch
impl Sync for RequestPatch
impl Unpin for RequestPatch
impl UnsafeUnpin for RequestPatch
impl UnwindSafe for RequestPatch
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
fn clone_storage(&self) -> Box<dyn CloneDebuggableStorage>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
impl<T> DebuggableStorage for T
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>
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>
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