pub struct Item {
pub id: Option<MessageId>,
pub kind: ItemKind,
pub parts: Vec<Part>,
pub metadata: MetadataMap,
pub usage: Option<Usage>,
pub finish_reason: Option<FinishReason>,
pub created_at: Option<Timestamp>,
}Expand description
A single entry in the agent transcript.
An Item represents one message or event in the conversation between
the system, user, assistant, and tools. Each item has a kind
that determines its role and a vector of Parts that carry its content.
Items are the primary unit of data flowing through the agentkit loop:
callers submit user and system items, the loop appends assistant and tool
items, and compaction strategies operate on the full Vec<Item> transcript.
§Example
use agentkit_core::{Item, ItemKind};
let user_msg = Item::text(ItemKind::User, "List the workspace crates.");
assert_eq!(user_msg.kind, ItemKind::User);
assert_eq!(user_msg.parts.len(), 1);Fields§
§id: Option<MessageId>Optional provider-assigned or user-supplied message identifier.
kind: ItemKindThe role of this item in the transcript.
parts: Vec<Part>The content parts that make up this item.
metadata: MetadataMapArbitrary key-value metadata for this item.
usage: Option<Usage>Token / cost usage produced by the model turn that emitted this item. Populated by the loop on assistant items when the provider reports it.
finish_reason: Option<FinishReason>Why the model turn that produced this item ended. Populated by the loop on assistant items.
created_at: Option<Timestamp>When this item was appended to the transcript. Populated by the loop for every appended item.
Implementations§
Source§impl Item
impl Item
Sourcepub fn new(kind: ItemKind, parts: Vec<Part>) -> Self
pub fn new(kind: ItemKind, parts: Vec<Part>) -> Self
Builds an item with the given role and parts.
Sourcepub fn notification(text: impl Into<String>) -> Self
pub fn notification(text: impl Into<String>) -> Self
Builds a ItemKind::Notification item carrying free-form text.
Adapters wrap the content in <system-reminder> and deliver it as
a user-role message so the model can react to the notification on
its next turn without violating tool_use/tool_result pairing.
Sourcepub fn with_metadata(self, metadata: MetadataMap) -> Self
pub fn with_metadata(self, metadata: MetadataMap) -> Self
Replaces the item metadata.
Sourcepub fn with_usage(self, usage: Usage) -> Self
pub fn with_usage(self, usage: Usage) -> Self
Sets the model usage that produced this item.
Sourcepub fn with_finish_reason(self, reason: FinishReason) -> Self
pub fn with_finish_reason(self, reason: FinishReason) -> Self
Sets the finish reason for the model turn that produced this item.
Sourcepub fn with_created_at(self, ts: Timestamp) -> Self
pub fn with_created_at(self, ts: Timestamp) -> Self
Sets when this item was created.