pub struct ChatRequest {
pub messages: Vec<ChatMessage>,
pub tools: Vec<Value>,
pub reasoning: Option<ReasoningConfig>,
pub response_format: Option<ResponseFormat>,
pub model: Option<String>,
pub cache_through: Option<usize>,
pub parallel_tool_calls: Option<bool>,
}Expand description
Unified chat request format.
Fields§
§messages: Vec<ChatMessage>Message list (supports multimodal content)
tools: Vec<Value>Available tools
reasoning: Option<ReasoningConfig>Reasoning/thinking configuration
response_format: Option<ResponseFormat>Response format configuration
model: Option<String>Optional model override.
None: Use the provider’s default modelSome(name): Use the specified model for this request
This enables multi-model routing: the application can set different models for different scenes (e.g., “lite” for sub-agents, “advanced” for architecture decisions) without creating multiple providers.
cache_through: Option<usize>Cache through message index n (inclusive): the system prompt, the
tool definitions and messages[0..=n] repeat verbatim on the next call
— a conversation appends, it does not rewrite its own prefix.
This is a claim about stability, not a protocol instruction. Each
provider exploits it as its protocol allows: Anthropic marks a
cache_control breakpoint at the last cached block, OpenAI caches
prefixes automatically and needs no marker at all, and a provider
without caching ignores this. None means the caller makes no
stability claim and nothing is cached on purpose.
Move n forward as the conversation grows (the standard shape: the
breakpoint trails the newest complete turn).
parallel_tool_calls: Option<bool>Whether the model may issue several tool calls in one response.
This is a permission, not a request for parallelism: it says the
harness can execute the calls concurrently and the caller will not be
confused by interleaved results. Each provider carries it as its
protocol allows — OpenAI sends parallel_tool_calls, Anthropic has no
such field and the model batches on its own, and a provider without it
ignores this. None makes no claim and the provider applies its own
default.
Nothing here guarantees the model will batch. It only stops the harness from forbidding it — measured on phimint session 20261115_2fbff82e, models that may batch still averaged 1.41 calls per turn, so the turn-count win is a bet, not a promise.
Implementations§
Source§impl ChatRequest
impl ChatRequest
Sourcepub fn new(messages: Vec<ChatMessage>) -> ChatRequest
pub fn new(messages: Vec<ChatMessage>) -> ChatRequest
Create a simple text request.
Sourcepub fn with_cache_through(self, n: usize) -> ChatRequest
pub fn with_cache_through(self, n: usize) -> ChatRequest
Claim that the request’s prefix repeats verbatim on the next call, and
ask the provider to cache through message index n. See the field docs
for what each protocol does with it.
Sourcepub fn with_parallel_tool_calls(self, allow: bool) -> ChatRequest
pub fn with_parallel_tool_calls(self, allow: bool) -> ChatRequest
Declare whether the model may batch tool calls in one response. See the field docs for what each protocol does with it.
Sourcepub fn with_model(self, model: impl Into<String>) -> ChatRequest
pub fn with_model(self, model: impl Into<String>) -> ChatRequest
Set model override.
Sourcepub fn with_tools(self, tools: Vec<Value>) -> ChatRequest
pub fn with_tools(self, tools: Vec<Value>) -> ChatRequest
Add tools.
Sourcepub fn with_reasoning(self, reasoning: ReasoningConfig) -> ChatRequest
pub fn with_reasoning(self, reasoning: ReasoningConfig) -> ChatRequest
Add reasoning configuration.
Sourcepub fn with_response_format(self, format: ResponseFormat) -> ChatRequest
pub fn with_response_format(self, format: ResponseFormat) -> ChatRequest
Set response format.
Trait Implementations§
Source§impl Clone for ChatRequest
impl Clone for ChatRequest
Source§fn clone(&self) -> ChatRequest
fn clone(&self) -> ChatRequest
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more