Skip to main content

HistoryEntry

Struct HistoryEntry 

Source
pub struct HistoryEntry {
    pub agent: String,
    pub sender: String,
    pub auto_injected: bool,
    pub message: Message,
}
Expand description

A single conversation history entry.

The inner message is the wire-level shape sent to providers. The runtime-only fields are stripped from the wire but persisted to the session Storage for reload (except sender and auto_injected, which are session-local state that resets on reload).

Fields§

§agent: String

Which agent produced this assistant message. Empty = the conversation’s primary agent. Non-empty = a guest agent pulled in via an @ mention or guest turn. Persisted so reloads can reconstruct multi-agent state.

§sender: String

The sender identity (runtime-only, never serialized).

§auto_injected: bool

Whether this entry was auto-injected by the runtime (runtime-only). Auto-injected entries are stripped before each new run and never persisted as session steps.

§message: Message

The wire-level message sent to providers.

Implementations§

Source§

impl HistoryEntry

Source

pub fn system(content: impl Into<String>) -> Self

Create a new system entry.

Source

pub fn user(content: impl Into<String>) -> Self

Create a new user entry.

Source

pub fn user_with_sender( content: impl Into<String>, sender: impl Into<String>, ) -> Self

Create a new user entry with sender identity.

Source

pub fn assistant( content: impl Into<String>, reasoning: Option<String>, tool_calls: Option<&[ToolCall]>, ) -> Self

Create a new assistant entry.

Preserves the content: null vs empty-string discrimination:

  • assistant + non-empty tool_calls + empty content → "content": null
  • assistant + empty tool_calls + empty content → "content": ""
  • anything else → "content": "<the text>"
Source

pub fn tool( content: impl Into<String>, call_id: impl Into<String>, name: impl Into<String>, ) -> Self

Create a new tool-result entry.

Source

pub fn from_message(message: Message) -> Self

Wrap an existing crabllm_core::Message.

Source

pub fn auto_injected(self) -> Self

Mark this entry as auto-injected (chainable).

Source

pub fn role(&self) -> &Role

The role of the underlying message.

Source

pub fn text(&self) -> &str

The text content of the message, or "" if absent / empty / non-string.

Source

pub fn reasoning(&self) -> &str

The reasoning content, or empty if absent.

Source

pub fn tool_calls(&self) -> &[ToolCall]

The tool calls on this entry, or an empty slice if absent.

Source

pub fn tool_call_id(&self) -> &str

The tool call ID on this (tool) entry, or empty if absent.

Source

pub fn estimate_tokens(&self) -> usize

Estimate the number of tokens in this entry (~4 chars per token).

Source

pub fn to_wire_message(&self) -> Message

Project to a crabllm_core::Message for sending to a provider.

If this is a guest assistant message (agent non-empty and role is Assistant), wraps the content in <from agent="..."> tags so other agents can distinguish speakers in multi-agent conversations.

Trait Implementations§

Source§

impl Clone for HistoryEntry

Source§

fn clone(&self) -> HistoryEntry

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HistoryEntry

Source§

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

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

impl<'de> Deserialize<'de> for HistoryEntry

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for HistoryEntry

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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<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> 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, 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> 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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,