Expand description
Core transcript, content, usage, and cancellation primitives for agentkit.
This crate provides the foundational data model shared by every crate in the agentkit workspace. It defines:
- Transcript items (
Item,ItemKind) – the messages exchanged between system, user, assistant, and tools. - Content parts (
Part,TextPart,ToolCallPart, etc.) – the multimodal pieces that make up each item. - Streaming deltas (
Delta) – incremental updates emitted while a model turn is in progress. - Usage tracking (
Usage,TokenUsage,CostUsage) – token counts and cost accounting reported by providers. - Cancellation (
CancellationController,CancellationHandle,TurnCancellation) – cooperative interruption of running turns. - Typed identifiers (
SessionId,TurnId,ToolCallId, etc.) – lightweight newtypes that prevent accidental ID mix-ups. - Error types (
NormalizeError,ProtocolError,AgentError) – shared error variants used across the workspace.
§Example
use agentkit_core::{Item, ItemKind};
// Build a minimal transcript to feed into the agent loop.
let transcript = vec![
Item::text(ItemKind::System, "You are a coding assistant."),
Item::text(ItemKind::User, "What files are in this repo?"),
];
assert_eq!(transcript[0].kind, ItemKind::System);Structs§
- Approval
Id - Identifies a pending tool-use approval request.
- Artifact
Id - Identifies a binary or text artifact stored externally.
- Cancellation
Controller - Owner-side handle for broadcasting cancellation to running turns.
- Cancellation
Handle - Read-only view of cancellation state, cheaply cloneable.
- Cost
Usage - Monetary cost for a single model turn.
- Custom
Part - A provider-specific content part that does not fit the standard variants.
- File
Part - A file attachment within an
Item. - Item
- A single entry in the agent transcript.
- Media
Part - Binary or encoded media content (image, audio, video).
- Message
Id - Identifies a transcript
Item. - PartId
- Identifies a content part within a streaming
Deltasequence. - Provider
Message Id - Provider-assigned identifier for a message.
- Reasoning
Part - Model reasoning or chain-of-thought output.
- Session
Id - Identifies an agent session.
- Structured
Part - Structured JSON content, optionally paired with a JSON Schema for validation.
- TaskId
- Identifies a task tracked by a task manager.
- Text
Part - Plain text content within an
Item. - Token
Usage - Token counts broken down by direction and special categories.
- Tool
Call Id - Identifies a tool call emitted by the model.
- Tool
Call Part - A tool invocation request emitted by the model.
- Tool
Result Id - Identifies a tool result.
- Tool
Result Part - The result of executing a tool, sent back to the model.
- Turn
Cancellation - A snapshot of the cancellation generation at the start of a turn.
- TurnId
- Identifies a single turn within a session.
- Usage
- Token and cost usage reported by a model provider for a single turn.
Enums§
- Agent
Error - Top-level error type that unifies normalisation and protocol errors.
- DataRef
- A reference to content data that may live inline, at a URI, or in an artifact store.
- Delta
- An incremental update emitted while a model turn is streaming.
- Finish
Reason - The reason a model turn ended.
- Item
Kind - The role of an
Itemin the transcript. - Modality
- The kind of media carried by a
MediaPart. - Normalize
Error - Error returned when content cannot be normalised into the agentkit data model.
- Part
- A content part within an
Item. - Part
Kind - Discriminant for
Partvariants, used in streamingDeltas. - Protocol
Error - Error indicating an invalid state in the provider protocol.
- Tool
Output - The payload returned by a tool execution.
Traits§
Type Aliases§
- Metadata
Map - A map of arbitrary key-value metadata attached to items, parts, and other structures.