Skip to main content

Item

Enum Item 

Source
pub enum Item {
    User(User),
    Assistant(Assistant),
    ToolResult(ToolResult),
    System(System),
}
Expand description

One closed transcript record.

The variant set is closed by ADR-004. Lifecycle and audit facts are deliberately not transcript items.

use reef_core::transcript::item;
let item = item::Item::System(item::System::new(
    "instruction".into(), "Be concise.".into(), item::ModelVisibility::Visible,
));
assert!(matches!(item, item::Item::System(system) if system.text() == "Be concise."));

Variants§

§

User(User)

User-authored ordered content.

§

Assistant(Assistant)

Assistant-produced ordered content.

§

ToolResult(ToolResult)

The result of one model tool call.

§

System(System)

System-authored text.

Implementations§

Source§

impl Item

Source

pub fn to_plain_text(&self) -> String

Renders this record’s text the way a reader would be shown it.

Reading a transcript is the first thing anyone does with an agent, and without this it takes a four-arm match plus a walk into Part::fields or Segment per arm — the same twenty lines every consumer writes on their first day.

use reef_core::transcript::item;
use reef_core::value::content;

let extensions = || content::SegmentExtensions::new(String::new(), None, None);
let answer = item::Item::Assistant(item::Assistant::new(
    vec![
        content::Segment::Thinking { text: "the user wants a greeting".into(), extensions: extensions() },
        content::Segment::Text { text: "Hello.".into(), extensions: extensions() },
    ],
    None,
));
assert_eq!(answer.to_plain_text(), "Hello.");

let question = item::Item::User(item::User::new(
    vec![content::Part::text("Greet me.".into())],
    item::ModelVisibility::Visible,
));
assert_eq!(question.to_plain_text(), "Greet me.");
§What each record renders as
  • User: the text of every part, in order. A part carrying an image or opaque data has no text and contributes nothing.
  • Assistant: the text of every Segment::Text. Reasoning and tool calls are not text the reader is being shown; Assistant::content has them, in provider order, and always did.
  • ToolResult: exactly what tool_call::ToolResult::to_plain_text renders, which this arm calls rather than restates. That rule prefers the output’s user_view over its model content, and it belongs to the closed result value rather than to this record: a record adds a call identity, a tool name, a visibility and item metadata, none of which the rendering reads.
  • System: its text.

Two blocks are separated by a single \n and nothing else is added, so a record with one block renders exactly that block.

§This is not a way around redaction

It is an accessor, and every byte it returns is already reachable through the typed accessor that owns it — which is precisely why ADR-018 refused an unredacted Debug: there is nothing here to hide from, only something to make convenient. What that ADR protects against is accidental disclosure, so this stays explicit at the call site. There is deliberately no Display for an Item: a Display can be interpolated into a log message by someone who never decided to print a transcript, and {item} would look like nothing at all. item.to_plain_text() cannot be written by accident.

Trait Implementations§

Source§

impl Clone for Item

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Item

Source§

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

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

impl<'de> Deserialize<'de> for Item

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 Item

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§

§

impl Freeze for Item

§

impl RefUnwindSafe for Item

§

impl Send for Item

§

impl Sync for Item

§

impl Unpin for Item

§

impl UnsafeUnpin for Item

§

impl UnwindSafe for Item

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.