Skip to main content

TranscriptObserver

Trait TranscriptObserver 

Source
pub trait TranscriptObserver: Send + Sync {
    // Required method
    fn on_item_appended(&self, item: &Item);
}
Expand description

Receives full Items as they are appended to the driver’s transcript.

While LoopObserver surfaces operational events (deltas, tool calls, lifecycle, telemetry), it can’t be reconstructed back into a faithful transcript on its own — content deltas span partial parts and don’t carry their parent-Item identity, and historically tool results were pushed into the transcript with no observer event at all. A TranscriptObserver is the loss-free counterpart: it fires once per Item appended, with the full Item shape ready for persistence, replication, or audit.

Observers are called synchronously from inside the driver, in the same order items land in the transcript. Compaction-driven transcript rewrites do not fire on_item_appended — those are signaled by [AgentEvent::CompactionFinished] instead.

Register via AgentBuilder::transcript_observer; multiple observers may be registered and are called in registration order.

§Example

use agentkit_core::Item;
use agentkit_loop::TranscriptObserver;
use std::sync::atomic::{AtomicUsize, Ordering};

struct CountingObserver { items: AtomicUsize }

impl TranscriptObserver for CountingObserver {
    fn on_item_appended(&self, _item: &Item) {
        self.items.fetch_add(1, Ordering::Relaxed);
    }
}

Required Methods§

Source

fn on_item_appended(&self, item: &Item)

Called synchronously every time an Item is appended to the driver’s transcript, in transcript order. Observers store mutable state behind interior mutability so the driver can share an Arc<dyn TranscriptObserver>.

Implementors§