Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(memory): cover per-agent turn citations (#7032)

oxoxDev7885d3f20bbf
diff --git a/crates/openhuman-core/src/memory/tools.rs b/crates/openhuman-core/src/memory/tools.rs
index 566dc3f51b..2bcd837163 100644
--- a/crates/openhuman-core/src/memory/tools.rs
+++ b/crates/openhuman-core/src/memory/tools.rs
@@ -388,3 +388,6 @@ impl Tool for MemoryTool {
#[path = "tools_tests.rs"]
mod tests;
+#[cfg(test)]
+#[path = "tools_agent_tests.rs"]
+mod agent_tests;
diff --git a/crates/openhuman-core/src/memory/tools_agent_tests.rs b/crates/openhuman-core/src/memory/tools_agent_tests.rs
new file mode 100644
index 0000000000..1c577e7f17
--- /dev/null
+++ b/crates/openhuman-core/src/memory/tools_agent_tests.rs
@@ -0,0 +1,54 @@
+use super::*;
+use crate::core::runtime::{context::CoreContext, ContextOverlay, DomainSet};
+use crate::tools::toolpacks::ToolGroups;
+
+fn agent(parent: &Arc<CoreContext>, id: &str) -> Arc<CoreContext> {
+ parent.derive_with(
+ ContextOverlay::new(
+ crate::config::Config::default(),
+ DomainSet::kernel(),
+ ToolGroups::none(),
+ )
+ .session_agent(id),
+ )
+}
+
+fn citation(id: &str) -> TurnCitation {
+ TurnCitation {
+ id: id.to_string(),
+ key: "learning".to_string(),
+ namespace: None,
+ score: None,
+ timestamp: String::new(),
+ snippet: String::new(),
+ }
+}
+
+#[tokio::test]
+async fn turn_citations_stay_with_the_agent_that_recorded_them() {
+ let root = CoreContext::for_test(DomainSet::full(), None);
+ let alpha = agent(&root, "alpha");
+ let beta = agent(&root, "beta");
+ let thread = "shared-thread";
+
+ CoreContext::scope(Arc::clone(&alpha), async {
+ record_pack_citations(thread, vec![citation("alpha-cite")]);
+ })
+ .await;
+ CoreContext::scope(Arc::clone(&beta), async {
+ record_pack_citations(thread, vec![citation("beta-cite")]);
+ })
+ .await;
+
+ let from_beta = CoreContext::scope(beta, async { take_turn_citations(thread) }).await;
+ let from_alpha = CoreContext::scope(alpha, async { take_turn_citations(thread) }).await;
+
+ assert_eq!(
+ from_alpha.iter().map(|c| c.id.as_str()).collect::<Vec<_>>(),
+ ["alpha-cite"]
+ );
+ assert_eq!(
+ from_beta.iter().map(|c| c.id.as_str()).collect::<Vec<_>>(),
+ ["beta-cite"]
+ );
+}