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
chore: files changed src/openhuman/memory/tools.rs,src/openhuman/memory/tools/goals.rs,src/openhuman
Steven Enamakelcbb46b3bfe33
diff --git a/src/openhuman/memory/tools.rs b/src/openhuman/memory/tools.rsindex 05388e0f92..b193209c88 100644--- a/src/openhuman/memory/tools.rs+++ b/src/openhuman/memory/tools.rs@@ -31,6 +31,6 @@ pub use store::MemoryStoreTool;// The tools that came back from the extracted crate, re-exported flat so// `openhuman::tools`'s glob keeps every historical name in scope — the// registration sites in `tools/ops.rs` name them unqualified.-pub use goals::{GoalsAddTool, GoalsDeleteTool, GoalsEditTool, GoalsListTool};+pub use goals::GoalsTool;pub use raw_store::{MemoryStoreKindsTool, MemoryStoreRawChunksTool, MemoryStoreRawSearchTool};pub use search::{MemoryChunkContextTool, MemoryHybridSearchTool, MemoryVectorSearchTool};diff --git a/src/openhuman/memory/tools/goals.rs b/src/openhuman/memory/tools/goals.rsindex 5f778583bd..42f431c9c6 100644--- a/src/openhuman/memory/tools/goals.rs+++ b/src/openhuman/memory/tools/goals.rs@@ -1,9 +1,28 @@-//! Agent-facing tools for the long-term goals list.+//! The agent-facing tool for the long-term goals list.//!-//! These are the tools the background `goals_agent` (and, when allowed, the-//! main agent) uses to read and mutate the goals list over multiple turns.+//! This is what the background `goals_agent` (and, when allowed, the main+//! agent) uses to read and mutate the goals list over multiple turns.//!-//! # They are wrappers around [`goals::ops`], not around a store (#5560)+//! # One tool with an `op`, not four tools (#5316-adjacent)+//!+//! It was four — `goals_list` / `goals_add` / `goals_edit` / `goals_delete` —+//! and they differed only in which [`ops`] function they called. Four schemas+//! is four copies of the same `{"type":"object", …}` preamble charged on every+//! provider call of every turn, for one family the model touches rarely. The+//! shape here follows [`todo`](crate::openhuman::agent::tools::todo): an `op`+//! enum carrying no description of its own, flat optional siblings whose+//! descriptions name the ops that need them, and a `match` on `op`.+//!+//! Permission is **per op**, not flat, which is why+//! [`Tool::permission_level_with_args`] is implemented: `list` is `ReadOnly`+//! and the three mutations are `Write`, and collapsing them to a single flat+//! `Write` would put an approval prompt in front of reading the list. The+//! pattern is+//! [`git_operations`](crate::openhuman::tools::impl_tools)'s — resolve the+//! discriminator from the args and answer for that branch, with the arg-less+//! accessor reporting the ceiling rather than guessing low.+//!+//! # It wraps [`goals::ops`], not a store (#5560)//!//! Each tool used to call `tinycortex::memory::goals::store` against a//! `workspace_dir` captured at construction. Both halves of that changed:@@ -21,9 +40,9 @@//! they are the same one, and a goal added by the agent is validated,//! capped and reported exactly as a goal added over RPC.//!-//! The constructors still take a `workspace_dir` and it is still what-//! `tools::ops` passes: it is the sandbox identity these tools were built with,-//! and dropping it would change four public signatures in the agent's tool+//! The constructor still takes a `workspace_dir` and it is still what+//! `tools::ops` passes: it is the sandbox identity this tool was built with,+//! and dropping it would change a public signature in the agent's tool//! registry for no behavioural gain. It is unused for storage — the goals//! document is workspace-wide on the driver's side too, so the tool and the//! ambient binding name the same file.@@ -52,215 +71,122 @@ async fn goals_guard() -> Result<std::sync::Arc<MemoryGuard>, String> {Ok(guard)}-/// `goals_list` — read the current long-term goals list.-pub struct GoalsListTool {- workspace_dir: PathBuf,-}--impl GoalsListTool {- pub fn new(workspace_dir: PathBuf) -> Self {- Self { workspace_dir }- }-}--#[async_trait]-impl Tool for GoalsListTool {- fn name(&self) -> &str {- "goals_list"- }-- fn description(&self) -> &str {- "List the user's current long-term goals. Returns each goal's id and \- text. Always call this before adding/editing/deleting so you address \- the right ids and avoid duplicates."- }-- fn parameters_schema(&self) -> serde_json::Value {- json!({ "type": "object", "properties": {} })- }-- fn permission_level(&self) -> PermissionLevel {- PermissionLevel::ReadOnly- }-- async fn execute(&self, _args: serde_json::Value) -> anyhow::Result<ToolResult> {- log::debug!("[memory_goals] tool=goals_list");- let guard = match goals_guard().await {- Ok(guard) => guard,- Err(e) => return Ok(ToolResult::error(e)),- };- let goals = guard.as_goals().expect("checked in goals_guard");- match ops::list(goals).await {- // `render()` is the contract type's own markdown, so the bytes the- // agent reads are unchanged.- Ok(outcome) => Ok(ToolResult::success(outcome.value.render())),- Err(e) => Ok(ToolResult::error(e)),- }- }+/// The op named in `args`, lowercased for the permission and dispatch lookups.+fn requested_op(args: &serde_json::Value) -> Option<&str> {+ args.get("op").and_then(|v| v.as_str())}-/// `goals_add` — add a new long-term goal.-pub struct GoalsAddTool {+/// `goals` — read and mutate the user's long-term goals list.+pub struct GoalsTool {workspace_dir: PathBuf,}-impl GoalsAddTool {+impl GoalsTool {pub fn new(workspace_dir: PathBuf) -> Self {Self { workspace_dir }}}#[async_trait]-impl Tool for GoalsAddTool {+impl Tool for GoalsTool {fn name(&self) -> &str {- "goals_add"+ "goals"}fn description(&self) -> &str {- "Add a new long-term goal (one concise sentence describing a durable \- objective for working with the user). Returns the assigned goal id."+ "Read and edit the user's long-term goals: durable objectives for \+ working with them, not this thread's task list (that is `todo`). \+ Start with `op: \"list\"` so you address the right ids and avoid \+ duplicates."}fn parameters_schema(&self) -> serde_json::Value {json!({"type": "object",- "required": ["text"],+ "required": ["op"],"properties": {- "text": { "type": "string", "description": "The goal text — one concise sentence." }+ "op": { "type": "string", "enum": ["list", "add", "edit", "delete"] },+ "id": { "type": "string", "description": "Goal id, as returned by `list` (required for edit/delete)." },+ "text": { "type": "string", "description": "One concise sentence (required for add/edit)." }}})}+ /// The ceiling. Nothing here says which op is being asked for, so reporting+ /// `ReadOnly` would admit a write on a channel that refuses one.fn permission_level(&self) -> PermissionLevel {PermissionLevel::Write}- async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {- let Some(text) = args.get("text").and_then(|v| v.as_str()) else {- return Ok(ToolResult::error("Missing 'text' parameter"));- };- log::debug!("[memory_goals] tool=goals_add");- let guard = match goals_guard().await {- Ok(guard) => guard,- Err(e) => return Ok(ToolResult::error(e)),- };- let goals = guard.as_goals().expect("checked in goals_guard");- match ops::add(goals, text).await {- Ok(outcome) => Ok(ToolResult::success(format!(- "Added goal '{}'.",- outcome.value.id- ))),- Err(e) => Ok(ToolResult::error(e)),+ fn permission_level_with_args(&self, args: &serde_json::Value) -> PermissionLevel {+ match requested_op(args) {+ Some("list") => PermissionLevel::ReadOnly,+ // Every other op mutates, and an absent or unknown one fails the+ // call anyway — report the ceiling rather than a permissive guess.+ _ => PermissionLevel::Write,}}-}--/// `goals_edit` — replace the text of an existing goal.-pub struct GoalsEditTool {- workspace_dir: PathBuf,-}--impl GoalsEditTool {- pub fn new(workspace_dir: PathBuf) -> Self {- Self { workspace_dir }- }-}--#[async_trait]-impl Tool for GoalsEditTool {- fn name(&self) -> &str {- "goals_edit"- }-- fn description(&self) -> &str {- "Edit an existing long-term goal by id, replacing its text. Use \- goals_list first to find the id."- }-- fn parameters_schema(&self) -> serde_json::Value {- json!({- "type": "object",- "required": ["id", "text"],- "properties": {- "id": { "type": "string", "description": "The goal id to edit (e.g. 'g1')." },- "text": { "type": "string", "description": "The new goal text." }- }- })- }-- fn permission_level(&self) -> PermissionLevel {- PermissionLevel::Write- }async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {- let Some(id) = args.get("id").and_then(|v| v.as_str()) else {- return Ok(ToolResult::error("Missing 'id' parameter"));- };- let Some(text) = args.get("text").and_then(|v| v.as_str()) else {- return Ok(ToolResult::error("Missing 'text' parameter"));+ let Some(op) = requested_op(&args) else {+ return Ok(ToolResult::error(+ "Missing 'op' parameter (list, add, edit or delete)",+ ));};- log::debug!("[memory_goals] tool=goals_edit id={id}");+ log::debug!("[memory_goals] tool=goals op={op}");+let guard = match goals_guard().await {Ok(guard) => guard,Err(e) => return Ok(ToolResult::error(e)),};let goals = guard.as_goals().expect("checked in goals_guard");- match ops::edit(goals, id, text).await {- Ok(_) => Ok(ToolResult::success(format!("Edited goal '{id}'."))),- Err(e) => Ok(ToolResult::error(e)),- }- }-}--/// `goals_delete` — remove a goal by id.-pub struct GoalsDeleteTool {- workspace_dir: PathBuf,-}--impl GoalsDeleteTool {- pub fn new(workspace_dir: PathBuf) -> Self {- Self { workspace_dir }- }-}--#[async_trait]-impl Tool for GoalsDeleteTool {- fn name(&self) -> &str {- "goals_delete"- }- fn description(&self) -> &str {- "Delete a long-term goal by id (e.g. when it is completed or no longer \- relevant). Use goals_list first to find the id."- }-- fn parameters_schema(&self) -> serde_json::Value {- json!({- "type": "object",- "required": ["id"],- "properties": {- "id": { "type": "string", "description": "The goal id to delete (e.g. 'g1')." }+ let text = args.get("text").and_then(|v| v.as_str());+ let id = args.get("id").and_then(|v| v.as_str());++ match op {+ "list" => match ops::list(goals).await {+ // `render()` is the contract type's own markdown, so the bytes+ // the agent reads are unchanged.+ Ok(outcome) => Ok(ToolResult::success(outcome.value.render())),+ Err(e) => Ok(ToolResult::error(e)),+ },+ "add" => {+ let Some(text) = text else {+ return Ok(ToolResult::error("Missing 'text' parameter for op 'add'"));+ };+ match ops::add(goals, text).await {+ Ok(outcome) => Ok(ToolResult::success(format!(+ "Added goal '{}'.",+ outcome.value.id+ ))),+ Err(e) => Ok(ToolResult::error(e)),+ }}- })- }-- fn permission_level(&self) -> PermissionLevel {- PermissionLevel::Write- }-- async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {- let Some(id) = args.get("id").and_then(|v| v.as_str()) else {- return Ok(ToolResult::error("Missing 'id' parameter"));- };- log::debug!("[memory_goals] tool=goals_delete id={id}");- let guard = match goals_guard().await {- Ok(guard) => guard,- Err(e) => return Ok(ToolResult::error(e)),- };- let goals = guard.as_goals().expect("checked in goals_guard");- match ops::delete(goals, id).await {- Ok(_) => Ok(ToolResult::success(format!("Deleted goal '{id}'."))),- Err(e) => Ok(ToolResult::error(e)),+ "edit" => {+ let Some(id) = id else {+ return Ok(ToolResult::error("Missing 'id' parameter for op 'edit'"));+ };+ let Some(text) = text else {+ return Ok(ToolResult::error("Missing 'text' parameter for op 'edit'"));+ };+ match ops::edit(goals, id, text).await {+ Ok(_) => Ok(ToolResult::success(format!("Edited goal '{id}'."))),+ Err(e) => Ok(ToolResult::error(e)),+ }+ }+ "delete" => {+ let Some(id) = id else {+ return Ok(ToolResult::error("Missing 'id' parameter for op 'delete'"));+ };+ match ops::delete(goals, id).await {+ Ok(_) => Ok(ToolResult::success(format!("Deleted goal '{id}'."))),+ Err(e) => Ok(ToolResult::error(e)),+ }+ }+ other => Ok(ToolResult::error(format!(+ "Unknown op '{other}'. Expected one of: list, add, edit, delete"+ ))),}}}diff --git a/src/openhuman/tools/ops.rs b/src/openhuman/tools/ops.rsindex 0c491ffc44..978f833f25 100644--- a/src/openhuman/tools/ops.rs+++ b/src/openhuman/tools/ops.rs@@ -696,24 +696,13 @@ pub fn all_tools_with_runtime(security.clone(),)));- // Long-term goals list tools. Used primarily by the background- // `goals_agent` (which filters to these via its `[tools] named`- // allowlist); also available to the main agent for explicit edits.- {- let goals_dir = root_config.workspace_dir.clone();- tools.push(Box::new(- crate::openhuman::memory::tools::goals::GoalsListTool::new(goals_dir.clone()),- ));- tools.push(Box::new(- crate::openhuman::memory::tools::goals::GoalsAddTool::new(goals_dir.clone()),- ));- tools.push(Box::new(- crate::openhuman::memory::tools::goals::GoalsEditTool::new(goals_dir.clone()),- ));- tools.push(Box::new(- crate::openhuman::memory::tools::goals::GoalsDeleteTool::new(goals_dir),- ));- }+ // Long-term goals list tool. Used primarily by the background+ // `goals_agent` (which filters to it via its `[tools] named` allowlist);+ // also available to the main agent for explicit edits. One `op`-dispatched+ // tool, not four — see the module docs on `memory::tools::goals`.+ tools.push(Box::new(+ crate::openhuman::memory::tools::goals::GoalsTool::new(root_config.workspace_dir.clone()),+ ));// Thread-level goal tools (Codex-style per-thread completion contract).// Visible only to agents that allowlist them (orchestrator). The target