The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(memory): add channel field to turns and forget-by-channel support
Steven Enamakel5b4cddf7b4a8
diff --git a/crates/openhuman-core/src/core/events.rs b/crates/openhuman-core/src/core/events.rsindex 630b0f0004..008772c370 100644--- a/crates/openhuman-core/src/core/events.rs+++ b/crates/openhuman-core/src/core/events.rs@@ -70,6 +70,8 @@ pub enum DomainEvent {agent_id: Option<String>,/// The agent's working folder (`action_dir`).workspace: Option<String>,+ /// The channel the turn arrived on (`web`, `telegram`, …).+ channel: Option<String>,user_text: String,assistant_text: String,tool_calls: Vec<ConversationToolCall>,diff --git a/crates/openhuman-core/src/memory/bus.rs b/crates/openhuman-core/src/memory/bus.rsindex a289fa1c2c..bd9549c398 100644--- a/crates/openhuman-core/src/memory/bus.rs+++ b/crates/openhuman-core/src/memory/bus.rs@@ -38,6 +38,7 @@ pub fn committed_turn(event: &DomainEvent) -> Option<CommittedTurn> {thread_id,agent_id,workspace,+ channel,user_text,assistant_text,tool_calls,@@ -50,6 +51,7 @@ pub fn committed_turn(event: &DomainEvent) -> Option<CommittedTurn> {thread_id: thread_id.clone(),agent_id: agent_id.clone(),workspace: workspace.clone(),+ channel: channel.clone(),user: user_text.clone(),assistant: assistant_text.clone(),tool_calls: tool_callsdiff --git a/crates/openhuman-core/src/memory/conversations/buffer.rs b/crates/openhuman-core/src/memory/conversations/buffer.rsindex e4def27ed8..18c8861769 100644--- a/crates/openhuman-core/src/memory/conversations/buffer.rs+++ b/crates/openhuman-core/src/memory/conversations/buffer.rs@@ -20,6 +20,8 @@ pub struct CommittedTurn {pub agent_id: Option<String>,/// The agent's working folder.pub workspace: Option<String>,+ /// The channel the turn arrived on.+ pub channel: Option<String>,/// What the user said.pub user: String,/// What the assistant replied.@@ -30,6 +32,12 @@ pub struct CommittedTurn {pub at: DateTime<Utc>,}+/// The tag a conversation item from `channel` carries.+#[must_use]+pub fn channel_tag(channel: &str) -> String {+ format!("channel:{}", channel.to_ascii_lowercase())+}+/// Turns of one thread ready to be stored as one `Conversation` item.#[derive(Debug, Clone, PartialEq)]pub struct Batch {@@ -51,7 +59,8 @@ impl Batch {/// The `Conversation` item this batch stores.////// Meta carries `thread_id`, `agent_id` and `workspace` (from the latest- /// turn that has them), `turns`, and `source = conversation:<thread_id>`.+ /// turn that has them), `turns`, a `channel:<name>` tag, and+ /// `source = conversation:<thread_id>`./// Tool calls ride on each assistant turn by name and id; arguments never/// enter the item.#[must_use]@@ -64,6 +73,13 @@ impl Batch {.rev().find_map(|turn| turn.workspace.clone());let observed_at = self.turns.last().map(|turn| turn.at);+ let tags: Vec<String> = self+ .turns+ .iter()+ .rev()+ .find_map(|turn| turn.channel.as_deref())+ .map(|channel| vec![channel_tag(channel)])+ .unwrap_or_default();let mut turns = Vec::with_capacity(self.turns.len() * 2);for turn in self.turns {if !turn.user.trim().is_empty() {@@ -103,6 +119,7 @@ impl Batch {id: Some(self.thread_id),},observed_at,+ tags,..MemoryMeta::default()},}diff --git a/crates/openhuman-core/src/memory/conversations/mod.rs b/crates/openhuman-core/src/memory/conversations/mod.rsindex c67a418fc2..055098b62e 100644--- a/crates/openhuman-core/src/memory/conversations/mod.rs+++ b/crates/openhuman-core/src/memory/conversations/mod.rs@@ -230,6 +230,27 @@ async fn store_batch(config: &Config, batch: Batch) {}}+/// Forgets every conversation stored from `channel` (used when a channel is+/// disconnected with `clear_memory`). Memory off forgets nothing.+pub async fn forget_channel(config: &Config, channel: &str) -> MemoryResult<usize> {+ let bound = match engine::resolve(config).engine() {+ Ok(bound) => bound,+ Err(MemoryError::Off(_)) => return Ok(0),+ Err(error) => return Err(error),+ };+ let filter = tinymemory::MetaFilter {+ kinds: vec![tinymemory::ItemKind::Conversation],+ tags_any: vec![buffer::channel_tag(channel)],+ ..tinymemory::MetaFilter::default()+ };+ let report = bound+ .engine+ .forget(tinymemory::ForgetTarget::Filter(filter))+ .await?;+ tracing::debug!(forgotten = report.forgotten, "[memory:conversations] channel forgotten");+ Ok(report.forgotten)+}+/// `memory_conversations_get`.#[must_use]pub fn view(config: &Config) -> ConversationsView {