pub struct Message {
pub role: Role,
pub content: MessageContent,
}Fields§
§role: Role§content: MessageContentImplementations§
Source§impl Message
impl Message
pub fn new(role: Role, content: impl Into<String>) -> Self
pub fn text(&self) -> Option<&str>
Sourcepub fn estimate_tokens(&self) -> usize
pub fn estimate_tokens(&self) -> usize
Rough token estimate: bytes / 4 with a per-message overhead.
Note on accuracy: this is a coarse approximation regardless of language. For OpenAI-style BPE tokenizers it tracks reality within ~30% on mixed English+CJK code/prose. We deliberately keep the formula simple and per-content-type aware (tool args expanded, ToolResultRef counted by what’s actually sent on the wire) — small refinements to the divisor are dwarfed by tokenizer differences across providers, so anything short of a real tokenizer would be false precision.
Sourcepub fn condensed(&self, tool_name: &str) -> Message
pub fn condensed(&self, tool_name: &str) -> Message
Create a condensed version of this message for context budget savings.
Only condenses ToolResult messages (replaces full output with 1-line
summary). tool_name is looked up by the caller via the
paired ATC (see e.g. ctx::truncate::post_process_tool_results) —
pass "" when unknown and this function will default to the generic
first-line summary. ToolResultRef and other variants return as-is.
For tool_name == "read_file", emits a skeleton that keeps function
signatures + line numbers so the model can still use line-number
edit mode without re-reading. Previously this decision used a
substring heuristic on the output format, which false-positived on
bash outputs that happened to start with " N| ..." lines.
Sourcepub fn is_tool_result(&self) -> bool
pub fn is_tool_result(&self) -> bool
Returns true if this message is a tool result (either inline or ref).
Sourcepub fn tool_result_call_id(&self) -> Option<&str>
pub fn tool_result_call_id(&self) -> Option<&str>
Extract call_id from tool result variants.
Sourcepub fn tool_result_success(&self) -> Option<bool>
pub fn tool_result_success(&self) -> Option<bool>
Extract success status from tool result variants.
Sourcepub fn tool_result_output(&self) -> Option<&str>
pub fn tool_result_output(&self) -> Option<&str>
Extract the output text from tool result variants (summary for refs).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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