Skip to main content

attach_turn_context

Function attach_turn_context 

Source
pub fn attach_turn_context(messages: &[Message], block: &str) -> Vec<Message>
Expand description

Attach the per-turn context to the latest plain user message, at request time only.

messages is the persisted history and must stay byte-identical between turns, so this never mutates it; the returned vector is what goes to the provider. The block lands on the last user message that carries no tool blocks (the same anchor safe_compact_split uses). Everything before it is therefore a stable, cacheable prefix, tool-loop iterations within the turn only append after it, and no system role ever enters messages, which the Anthropic Messages API rejects.