Skip to content

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

chore: files changed crates/openhuman-core/src/memory/lifecycle/mod.rs,crates/openhuman-core/src/mem

Steven Enamakelfeee914eddf8
diff --git a/crates/openhuman-core/src/memory/lifecycle/mod.rs b/crates/openhuman-core/src/memory/lifecycle/mod.rs
index 2a9eebef92..4ab1602104 100644
--- a/crates/openhuman-core/src/memory/lifecycle/mod.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/mod.rs
@@ -17,6 +17,7 @@
pub mod hooks;
pub mod jobs;
+pub mod views;
use std::sync::Arc;
diff --git a/crates/openhuman-core/src/memory/schemas/defs.rs b/crates/openhuman-core/src/memory/schemas/defs.rs
index faa1088628..daf538c16a 100644
--- a/crates/openhuman-core/src/memory/schemas/defs.rs
+++ b/crates/openhuman-core/src/memory/schemas/defs.rs
@@ -4,10 +4,13 @@
use crate::core::{ControllerSchema, FieldSchema, TypeSchema};
/// Every function of the namespace, in spec order.
-pub const FUNCTIONS: [&str; 24] = [
+pub const FUNCTIONS: [&str; 30] = [
"engines_list",
"engine_get",
"engine_set",
+ "policy_get",
+ "policy_set",
+ "pack_preview",
"recall",
"fetch",
"learn",
@@ -15,20 +18,23 @@ pub const FUNCTIONS: [&str; 24] = [
"items_list",
"explore",
"items_get",
- "conversations_get",
- "conversations_set",
+ "agents_list",
"conversations_backfill_status",
"conversations_backfill_start",
+ "brain_sources",
+ "brain_search",
+ "brain_ingest",
+ "brain_forget",
"sources_list",
"sources_add",
"sources_remove",
"sources_sync",
- "context_get",
- "context_refresh",
- "context_set",
+ "jobs_list",
+ "jobs_run",
"import_scan",
"import_start",
"import_status",
+ "status",
];
fn field(name: &'static str, ty: TypeSchema, comment: &'static str, required: bool) -> FieldSchema {
@@ -80,14 +86,6 @@ fn reach() -> FieldSchema {
)
}
-fn namespace() -> FieldSchema {
- opt(
- "namespace",
- TypeSchema::String,
- "Memory node, e.g. `agent:researcher` or `team:acme/agent:writer`; the root when omitted.",
- )
-}
-
fn path() -> FieldSchema {
opt(
"path",
@@ -199,35 +197,59 @@ pub fn schema(function: &str) -> ControllerSchema {
inputs: vec![req("ids", TypeSchema::Array(Box::new(TypeSchema::String)), "Item ids (1 to 200)."), reach()],
outputs: out("{items: Hit[]}"),
},
- "conversations_get" => ControllerSchema {
+ "policy_get" => ControllerSchema {
namespace: "memory",
- function: "conversations_get",
- description: "Conversation ingestion settings and the latest stored batches.",
+ function: "policy_get",
+ description: "The memory lifecycle's policy: turn logging, the per-turn pack and its budgets, and the root and agent id work outside an agent resolves to.",
inputs: vec![],
- outputs: out("{enabled, batch_turns, idle_secs, recent}"),
+ outputs: out("{log_conversations, recall: {enabled, budget_tokens, learnings_limit, brain_limit, history_limit, team_limit, build_beliefs_every, pre_turn_timeout_ms, compaction_timeout_ms, build_delay_secs}, root, agent_id, host_bound}"),
},
- "conversations_set" => ControllerSchema {
+ "policy_set" => ControllerSchema {
namespace: "memory",
- function: "conversations_set",
- description: "Change conversation ingestion settings.",
+ function: "policy_set",
+ description: "Change the memory lifecycle's policy.",
inputs: vec![
- opt("enabled", TypeSchema::Bool, "Store conversations."),
- opt("batch_turns", TypeSchema::BoundedU64 { min: 1, max: 100 }, "Turns per stored batch."),
- opt("idle_secs", TypeSchema::BoundedU64 { min: 1, max: 86_400 }, "Idle seconds before a partial batch is stored."),
- ],
- outputs: out("Same as memory_conversations_get."),
+ opt("log_conversations", TypeSchema::Bool, "Log every turn to the acting agent's conversations."),
+ opt("recall_enabled", TypeSchema::Bool, "Give every turn a memory pack."),
+ opt("budget_tokens", TypeSchema::BoundedU64 { min: 100, max: 16_000 }, "The pack's size in tokens."),
+ opt("learnings_limit", TypeSchema::BoundedU64 { min: 0, max: 50 }, "Learnings and built beliefs per pack."),
+ opt("brain_limit", TypeSchema::BoundedU64 { min: 0, max: 50 }, "Brain documents per pack."),
+ opt("history_limit", TypeSchema::BoundedU64 { min: 0, max: 50 }, "This agent's earlier turns per pack."),
+ opt("team_limit", TypeSchema::BoundedU64 { min: 0, max: 50 }, "Other agents' turns per pack; 0 leaves them out."),
+ opt("build_beliefs_every", TypeSchema::BoundedU64 { min: 0, max: 1000 }, "Turns between belief builds; 0 turns them off."),
+ opt("pre_turn_timeout_ms", TypeSchema::BoundedU64 { min: 100, max: 30_000 }, "How long a turn waits for its pack."),
+ ],
+ outputs: out("Same as memory_policy_get."),
+ },
+ "pack_preview" => ControllerSchema {
+ namespace: "memory",
+ function: "pack_preview",
+ description: "The memory pack a turn would be given (with a query) or a session would start with (without one). Reads only.",
+ inputs: vec![
+ opt("query", TypeSchema::String, "What the turn says; omit to preview a session start."),
+ opt("thread_id", TypeSchema::String, "Session start: the thread being resumed."),
+ opt("agent_id", TypeSchema::String, "The memory agent to preview as; the default agent when omitted."),
+ ],
+ outputs: out("{agent_id, root, mode: turn|session, pack: {markdown, tokens, refs, sections, skipped, engine}}"),
+ },
+ "agents_list" => ControllerSchema {
+ namespace: "memory",
+ function: "agents_list",
+ description: "The agents with logged conversations under the memory root, and how many turns each.",
+ inputs: vec![],
+ outputs: out("{root, agents: {agent_id, turns}[]}"),
},
"conversations_backfill_status" => ControllerSchema {
namespace: "memory",
function: "conversations_backfill_status",
- description: "Progress of storing past chats, and how many threads and turns from before automatic ingestion are still unstored.",
+ description: "Progress of storing past chats, and how many threads and turns from before turn logging are still unstored.",
inputs: vec![],
outputs: out("{state: {phase, threads_total, threads_done, turns_stored, items_stored, error?, finished_at?}, pending_threads, pending_turns}"),
},
"conversations_backfill_start" => ControllerSchema {
namespace: "memory",
function: "conversations_backfill_start",
- description: "Store past chats (turns from before automatic ingestion) as conversation memory, in the background. Uploads chat history to the selected engine, so it requires consent: true.",
+ description: "Store past chats (turns from before turn logging) as the main agent's conversations, in the background. Uploads chat history to the selected engine, so it requires consent: true.",
inputs: vec![req("consent", TypeSchema::Bool, "The user agreed to upload past chats to the engine.")],
outputs: out("Same as memory_conversations_backfill_status."),
},
@@ -247,7 +269,7 @@ pub fn schema(function: &str) -> ControllerSchema {
req("target", TypeSchema::String, "Path, URL, owner/repo, feed URL or Composio toolkit."),
opt("label", TypeSchema::String, "Display label (default: the target)."),
opt("schedule_mins", TypeSchema::BoundedU64 { min: 15, max: u64::from(u32::MAX) }, "Minutes between scheduled syncs; omit for on demand only."),
- opt("namespace", TypeSchema::String, "Memory node to store the documents at, e.g. `agent:researcher`; the root (shared by every agent) when omitted."),
+ opt("namespace", TypeSchema::String, "Layout root to file the documents under, e.g. `team:acme`; the configured root (shared by every agent) when omitted."),
],
outputs: out("{source: Source}"),
},
@@ -268,30 +290,56 @@ pub fn schema(function: &str) -> ControllerSchema {
inputs: vec![opt("id", TypeSchema::String, "Source id; every source when omitted.")],
outputs: out("{started: string[]}"),
},
- "context_get" => ControllerSchema {
+ "brain_sources" => ControllerSchema {
namespace: "memory",
- function: "context_get",
- description: "The compiled context.md of one memory node (the root by default) and its settings.",
- inputs: vec![namespace()],
- outputs: out("{namespace, markdown, tokens, generated_at, interval_mins, budget_tokens, enabled}"),
+ function: "brain_sources",
+ description: "The brain's sources (pdf, markdown, notion, github, web, …) and how many documents each holds.",
+ inputs: vec![],
+ outputs: out("{root, sources: {source, documents}[], unfiled}"),
},
- "context_refresh" => ControllerSchema {
+ "brain_search" => ControllerSchema {
namespace: "memory",
- function: "context_refresh",
- description: "Recompile one memory node's context.md now (the root by default).",
- inputs: vec![namespace()],
- outputs: out("Same as memory_context_get."),
+ function: "brain_search",
+ description: "Search the brain's documents, all sources or one.",
+ inputs: vec![
+ req("query", TypeSchema::String, "What to search for."),
+ opt("source", TypeSchema::String, "One source's documents only."),
+ limit(),
+ ],
+ outputs: out("{hits: Hit[]}"),
},
- "context_set" => ControllerSchema {
+ "brain_ingest" => ControllerSchema {
namespace: "memory",
- function: "context_set",
- description: "Change context.md settings.",
+ function: "brain_ingest",
+ description: "File a document in the brain: a local file (converted, its source picked from its format) or text. Queues the source's belief build.",
inputs: vec![
- opt("enabled", TypeSchema::Bool, "Compile and inject context.md."),
- opt("interval_mins", TypeSchema::BoundedU64 { min: 5, max: u64::from(u32::MAX) }, "Minutes between recompiles."),
- opt("budget_tokens", TypeSchema::BoundedU64 { min: 100, max: 32_000 }, "Token budget."),
- ],
- outputs: out("Same as memory_context_get."),
+ opt("path", TypeSchema::String, "A local file to read."),
+ opt("text", TypeSchema::String, "Text to file."),
+ opt("source", TypeSchema::String, "The source to file under (default: from the format, markdown for text)."),
+ opt("title", TypeSchema::String, "A title."),
+ ],
+ outputs: out("{id, source, replayed}"),
+ },
+ "brain_forget" => ControllerSchema {
+ namespace: "memory",
+ function: "brain_forget",
+ description: "Forget every document of one brain source.",
+ inputs: vec![req("source", TypeSchema::String, "The source.")],
+ outputs: out("{forgotten: number}"),
+ },
+ "jobs_list" => ControllerSchema {
+ namespace: "memory",
+ function: "jobs_list",
+ description: "Memory's background job queue (belief builds, deferred ingests) and its latest runs.",
+ inputs: vec![],
+ outputs: out("{pending: QueuedJob[], history: JobRun[]}"),
+ },
+ "jobs_run" => ControllerSchema {
+ namespace: "memory",
+ function: "jobs_run",
+ description: "Run queued background jobs now: one by id, or every pending one.",
+ inputs: vec![opt("id", TypeSchema::String, "One job; every pending job when omitted.")],
+ outputs: out("{runs: JobRun[]}"),
},
"import_scan" => ControllerSchema {
namespace: "memory",
@@ -314,6 +362,13 @@ pub fn schema(function: &str) -> ControllerSchema {
inputs: vec![],
outputs: out("{state: ImportState}"),
},
+ "status" => ControllerSchema {
+ namespace: "memory",
+ function: "status",
+ description: "Whether memory is on, with what engine, and what the lifecycle is doing: the policy, pending jobs and the last run.",
+ inputs: vec![],
+ outputs: out("{on, engine?, reason?, policy, pending_jobs, last_run?}"),
+ },
_ => ControllerSchema {
namespace: "memory",
function: "unknown",
diff --git a/crates/openhuman-core/src/memory/types.rs b/crates/openhuman-core/src/memory/types.rs
index fedeceadea..a695c2530a 100644
--- a/crates/openhuman-core/src/memory/types.rs
+++ b/crates/openhuman-core/src/memory/types.rs
@@ -206,44 +206,6 @@ pub struct ItemsListView {
pub next_cursor: Option<String>,
}
-/// One recently stored conversation batch.
-#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
-pub struct RecentConversation {
- /// The thread it came from.
- pub thread_id: String,
- /// How many turns the batch held.
- pub turns: u32,
- /// When it was stored.
- pub stored_at: DateTime<Utc>,
-}
-
-/// `memory_conversations_get` / `_set` result.
-#[derive(Debug, Clone, Serialize)]
-pub struct ConversationsView {
- /// Whether conversations are stored.
- pub enabled: bool,
- /// Turns per stored batch.
- pub batch_turns: u32,
- /// Idle seconds before a partial batch is stored.
- pub idle_secs: u64,
- /// The latest stored batches, newest first.
- pub recent: Vec<RecentConversation>,
-}
-
-/// `memory_conversations_set` params.
-#[derive(Debug, Clone, Default, Deserialize)]
-pub struct ConversationsSetParams {
- /// New `enabled`.
- #[serde(default)]
- pub enabled: Option<bool>,
- /// New `batch_turns` (≥ 1).
- #[serde(default)]
- pub batch_turns: Option<u32>,
- /// New `idle_secs` (≥ 1).
- #[serde(default)]
- pub idle_secs: Option<u64>,
-}
-
/// A source's sync status.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
@@ -348,64 +310,6 @@ pub struct SourcesSyncView {
pub started: Vec<String>,
}
-/// `memory_context_*` result.
-#[derive(Debug, Clone, Serialize)]
-pub struct ContextView {
- /// The memory node the document is about (`root` for the shared one).
- pub namespace: String,
- /// The compiled document (empty when none).
- pub markdown: String,
- /// Its estimated tokens.
- pub tokens: usize,
- /// When it was compiled.
- pub generated_at: Option<DateTime<Utc>>,
- /// Minutes between scheduled recompiles.
- pub interval_mins: u32,
- /// Token budget.
- pub budget_tokens: u32,
- /// Whether compilation and injection are on.
- pub enabled: bool,
-}
-
-/// `memory_context_get` / `memory_context_refresh` params.
-#[derive(Debug, Clone, Default, Deserialize)]
-pub struct ContextNodeParams {
- /// The memory node; the root when omitted.
- #[serde(default)]
- pub namespace: Option<String>,
-}
-
-impl ContextNodeParams {
- /// The node named, checked.
- ///
- /// # Errors
- ///
- /// A malformed namespace.
- pub fn node(&self) -> Result<tinymemory_api::Namespace, String> {
- self.namespace
- .as_deref()
- .unwrap_or_default()
- .parse()
- .map_err(|error: tinymemory_api::Error| {
- String::from(super::error::MemoryError::invalid(error.to_string()))
- })
- }
-}
-
-/// `memory_context_set` params.
-#[derive(Debug, Clone, Default, Deserialize)]
-pub struct ContextSetParams {
- /// New `enabled`.
- #[serde(default)]
- pub enabled: Option<bool>,
- /// New `interval_mins` (≥ 5).
- #[serde(default)]
- pub interval_mins: Option<u32>,
- /// New `budget_tokens` (≥ 100).
- #[serde(default)]
- pub budget_tokens: Option<u32>,
-}
-
/// Item counts a legacy store would import.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct ImportCounts {