Implement conversation browser and safe deletion (#138)
Some checks failed
CI / rust-skia (Rust only) (push) Has been cancelled
CI / required (push) Has been cancelled

This commit is contained in:
2026-08-23 19:49:42 +02:00
parent 360203d647
commit 096911a156
13 changed files with 1513 additions and 60 deletions

View File

@@ -415,6 +415,14 @@ impl Agent {
self.memory.transcript()
}
/// Clears active and archived transcript entries while preserving the
/// agent identity, configuration, and long-term memory namespace.
/// Clears active and archived working transcript state while preserving
/// this agent's identity and durable long-term-memory namespace.
pub fn clear_transcript(&mut self) -> Result<(), RuntimeError> {
self.memory.clear_transcript()
}
/// The transcript entry the next turn will continue from.
pub fn leaf(&self) -> Option<&crate::transcript::EntryId> {
self.transcript().leaf()

View File

@@ -165,6 +165,15 @@ impl AgentMemory {
&self.history_cache
}
pub fn clear_transcript(&mut self) -> Result<(), RuntimeError> {
self.state.transcript = AgentTranscript::default();
self.state.pending_turn = None;
self.state.resumable_user_message = None;
self.state.run = None;
self.sync_history_cache();
self.persist()
}
pub fn revision(&self) -> u64 {
self.state.revision
}

View File

@@ -5,6 +5,7 @@ use serde_json::json;
use crate::{
AgentTranscript, ContentBlock, Message, TranscriptKind,
memory::journal::{AgentMemory, AgentMemoryState, CompactionOutcome, PendingTurnState},
memory::{MemoryRecord, MemoryRecordKind, MemoryStore},
runtime::VolatileRuntimeStore,
};
@@ -42,6 +43,42 @@ fn begin_run_commit_and_finish_persist_memory_state() {
assert!(memory.resumable_user_message().is_none());
}
#[test]
fn clear_transcript_persists_an_empty_history() {
let store = Arc::new(VolatileRuntimeStore::new());
let mut memory = AgentMemory::new("agent-clear", store.clone(), AgentMemoryState::default());
store
.upsert_records(&[MemoryRecord {
record_id: "fact:kept".into(),
agent_id: "agent-clear".into(),
kind: MemoryRecordKind::Fact,
content: "durable preference".into(),
source_revision: 1,
created_at: 1,
metadata_json: "{}".into(),
source: None,
pinned: true,
score: None,
}])
.unwrap();
memory
.append_message(Message::user(ContentBlock::text("private turn")))
.unwrap();
memory.clear_transcript().unwrap();
assert!(memory.transcript().is_empty());
assert!(memory.history().is_empty());
assert!(
memory.revision() >= 2,
"clear is persisted as a new revision"
);
assert!(
store
.get_record("agent-clear", "fact:kept")
.unwrap()
.is_some()
);
}
#[test]
fn rollback_and_compaction_update_memory_state() {
let store = Arc::new(VolatileRuntimeStore::new());