Skip to content

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

docs(agent-registry): add README and user scopes integration

Steven Enamakel78dd5b61cf16
diff --git a/crates/openhuman-core/src/agent/registry/README.md b/crates/openhuman-core/src/agent/registry/README.md
index 0cf0f41d4c..bb4f4b5c30 100644
--- a/crates/openhuman-core/src/agent/registry/README.md
+++ b/crates/openhuman-core/src/agent/registry/README.md
@@ -63,7 +63,7 @@ model, tool scope, sandbox mode, iteration cap, tier, `omit_*` flags, parsed
directly into `AgentDefinition`), a `prompt.md` holding the static archetype
body, and a `prompt.rs` that `include_str!`s that body and exposes
`pub fn build(&PromptContext) -> anyhow::Result<String>`, appending
-runtime-dependent sections (rendered tool list, user files, workspace) to it.
+runtime-dependent sections (rendered tool list, workspace) to it.
Every archetype currently uses `AgentGraph::Default`; an archetype that needs a
bespoke `AgentGraph` adds a `graph.rs` and sets `BuiltinAgent::graph_fn`. The per-archetype contract is
documented on [`agents/mod.rs`](agents/mod.rs).
diff --git a/crates/openhuman-core/src/agent/registry/agents/mod.rs b/crates/openhuman-core/src/agent/registry/agents/mod.rs
index cedd4fc9e5..9500571a6b 100644
--- a/crates/openhuman-core/src/agent/registry/agents/mod.rs
+++ b/crates/openhuman-core/src/agent/registry/agents/mod.rs
@@ -12,7 +12,7 @@
//! `include_str!`; nothing else reads it.
//! * `prompt.rs` — exposes `pub fn build(&PromptContext) ->
//! anyhow::Result<String>`, which appends runtime-dependent sections
-//! (rendered tool list, user files, workspace) to the `prompt.md` body.
+//! (rendered tool list, workspace) to the `prompt.md` body.
//! [`BUILTINS`] installs it as `PromptSource::Dynamic` on the parsed
//! definition. Most archetypes keep a `prompt_tests.rs` beside it.
//!
diff --git a/crates/openhuman-core/src/integrations/composio/ops/user_scopes.rs b/crates/openhuman-core/src/integrations/composio/ops/user_scopes.rs
index 35a7a53298..847a7c0743 100644
--- a/crates/openhuman-core/src/integrations/composio/ops/user_scopes.rs
+++ b/crates/openhuman-core/src/integrations/composio/ops/user_scopes.rs
@@ -1,104 +1,47 @@
-//! Per-toolkit agent scope preferences, read and written through the bound
-//! memory driver.
+//! Per-toolkit agent scope preferences, stored in
+//! `<workspace>/integrations/composio_user_scopes.json` through
+//! [`crate::integrations::composio::file_store`].
//!
-//! # Why this is host code now
-//!
-//! The two `composio.{get,set}_user_scopes` handlers used to reach
-//! `tinymemory_core::sync::composio::providers::user_scopes::{load_or_default,
-//! save}` — engine functions taking a `&MemoryClientRef`, resolved from the
-//! host's in-process `global` slot. openhuman#5560 deletes that second engine,
-//! so both calls had to move. Neither is a capability a second memory driver
-//! would answer differently: they are two rows in the driver's key/value tier,
-//! which the contract already exposes as [`MemoryGraph`]. So the *policy* came
-//! home and the *storage* went over the bus, exactly as `memory::safety` and
-//! `util::redact` did — no contract member was added.
-//!
-//! # The storage shape is the engine's, byte for byte
-//!
-//! The namespace, the key derivation and the serialised value below are copied
-//! from `tinymemory-core`'s `user_scopes.rs` rather than re-invented, because
-//! **this host is not the only reader**. Engine code still consults the same
-//! rows to gate tool calls by scope, and it now runs inside the loaded module.
-//! A key this host lower-cased differently, or a namespace one character off,
-//! would not fail — it would read as "no preference stored" and silently hand
-//! the agent the default (`read+write`, no `admin`) while the user's saved
-//! choice sat one key away. `user_scopes_storage_shape_matches_the_engine`
-//! pins the three constants against that.
+//! The file maps a normalised toolkit slug to its [`UserScopePref`]. The
+//! `composio.{get,set}_user_scopes` handlers, the agent's visible tool list
+//! and the flows capability gate all read through [`load_or_default`].
-use serde_json::Value;
+use std::collections::BTreeMap;
use crate::config::Config;
+use crate::integrations::composio::file_store::{self, USER_SCOPES_FILE};
-/// The stored type, still the engine's.
-///
-/// Named through `integrations::composio::providers` — the host's re-export of
-/// the engine's provider vocabulary — rather than redeclared here. `ToolScope`
-/// gating, the catalogue and the RPC reply all read this exact struct, and a
-/// host-side twin would be a second serde shape over one row. It is the wire
-/// shape of both handlers' replies, so it must not be swapped for a look-alike.
+/// The stored type: the contract's scope pref, which is also the wire shape of
+/// both handlers' replies.
pub(crate) use crate::integrations::composio::providers::UserScopePref;
-/// KV namespace holding one row per toolkit.
-///
-/// `tinymemory-core`'s `user_scopes::KV_NAMESPACE`. Deliberately distinct from
-/// `composio-sync-state`, so prefs and sync cursors never collide.
-const KV_NAMESPACE: &str = "composio-user-scopes";
+/// The stored map: normalised toolkit slug → pref.
+type ScopeFile = BTreeMap<String, UserScopePref>;
-/// The row key for a toolkit — trimmed and ASCII-lowercased.
-///
-/// `tinymemory-core`'s `user_scopes::kv_key`. Both RPC handlers reach here
-/// through `read_required_non_empty`, which has already rejected an
-/// all-whitespace toolkit, so the empty-key arm those engine functions carry
-/// cannot be reached from the RPC surface; it is still handled rather than
-/// assumed away, because a future caller need not come through that helper.
+/// The row key for a toolkit — trimmed and ASCII-lowercased, so `"GitHub"`,
+/// `" github "` and `"github"` reach one row.
fn kv_key(toolkit: &str) -> String {
toolkit.trim().to_ascii_lowercase()
}
/// The scope pref stored for `toolkit`, or the default when none is.
///
-/// **This read fails open, and that is inherited behaviour, not a new
-/// decision.** The engine's `load` documented it: "the agent should always be
-/// able to use connected integrations productively, even if pref storage is
-/// temporarily unavailable". Every failure mode — no driver, no `Graph` family,
-/// a backend error, a row that will not deserialise — lands on the same default
-/// (`read+write`, no `admin`) that a user who has never opened the toggle gets.
-/// Each is logged with its own reason so "defaulted because nothing is stored"
-/// stays distinguishable from "defaulted because the store is down".
-///
-/// The opposite choice would be worse: a failed read is not evidence that the
-/// user revoked anything, and refusing every integration on a transient KV
-/// error would break a working app to protect a preference it could not see.
-/// The **write** below does not fail open — see [`save`].
+/// **This read fails open**: an unreadable file lands on the same default
+/// (`read+write`, no `admin`) a user who never opened the toggle gets. A failed
+/// read is not evidence the user revoked anything, and refusing every
+/// integration on a transient I/O error would break a working app. The
+/// failure is logged so "defaulted because nothing is stored" stays
+/// distinguishable from "defaulted because the store is unreadable". The
+/// **write** below does not fail open — see [`save`].
pub(crate) async fn load_or_default(config: &Config, toolkit: &str) -> UserScopePref {
let key = kv_key(toolkit);
if key.is_empty() {
return UserScopePref::default();
}
-
- let binding = match crate::memory::binding::for_config(config) {
- Ok(binding) => binding,
- Err(error) => {
- tracing::warn!(
- toolkit = %key,
- %error,
- "[composio][scopes] memory driver unavailable, using default pref (read+write)"
- );
- return UserScopePref::default();
- }
- };
- let Some(graph) = binding.provider().as_graph() else {
- tracing::warn!(
- toolkit = %key,
- driver = binding.driver_id(),
- "[composio][scopes] driver does not serve Graph, using default pref (read+write)"
- );
- return UserScopePref::default();
- };
-
- match graph.kv_get(Some(KV_NAMESPACE), &key).await {
- Ok(Some(record)) => match serde_json::from_value::<UserScopePref>(record.value) {
- Ok(pref) => {
+ let path = file_store::path(config, USER_SCOPES_FILE);
+ match file_store::load::<ScopeFile>(&path).await {
+ Ok(mut prefs) => match prefs.remove(&key) {
+ Some(pref) => {
tracing::debug!(
toolkit = %key,
read = pref.read,
@@ -108,27 +51,19 @@ pub(crate) async fn load_or_default(config: &Config, toolkit: &str) -> UserScope
);
pref
}
- Err(error) => {
- tracing::warn!(
+ None => {
+ tracing::debug!(
toolkit = %key,
- %error,
- "[composio][scopes] pref deserialize failed, falling back to default"
+ "[composio][scopes] no pref stored, using default (read+write)"
);
UserScopePref::default()
}
},
- Ok(None) => {
- tracing::debug!(
- toolkit = %key,
- "[composio][scopes] no pref stored, using default (read+write)"
- );
- UserScopePref::default()
- }
Err(error) => {
tracing::warn!(
toolkit = %key,
%error,
- "[composio][scopes] kv_get failed, falling back to default"
+ "[composio][scopes] pref store unreadable, falling back to default"
);
UserScopePref::default()
}
@@ -139,14 +74,11 @@ pub(crate) async fn load_or_default(config: &Config, toolkit: &str) -> UserScope
///
/// **This one fails closed.** A write that reported success without storing
/// anything would leave the user looking at a toggle they just moved while the
-/// agent kept the old permissions — and the next read, which fails open, would
-/// confirm the stale value rather than contradict it. Every failure is an
-/// `Err` the RPC surfaces.
+/// agent kept the old permissions. Every failure is an `Err` the RPC surfaces.
///
/// # Errors
///
-/// An empty toolkit, an unresolvable driver, a driver with no `Graph` family,
-/// or a backend write failure.
+/// An empty toolkit, or the scope file cannot be read or written.
pub(crate) async fn save(
config: &Config,
toolkit: &str,
@@ -156,29 +88,17 @@ pub(crate) async fn save(
if key.is_empty() {
return Err("user_scopes: toolkit must not be empty".to_string());
}
- let value: Value = serde_json::to_value(pref)
- .map_err(|e| format!("[composio][scopes] serialize failed: {e}"))?;
-
- let binding = crate::memory::binding::for_config(config)
- .map_err(|e| format!("[composio][scopes] memory driver unavailable: {e}"))?;
- let Some(graph) = binding.provider().as_graph() else {
- return Err(format!(
- "[composio][scopes] driver '{}' does not serve Graph, cannot persist pref",
- binding.driver_id()
- ));
- };
-
- graph
- .kv_put(Some(KV_NAMESPACE), &key, value)
- .await
- .map_err(|e| format!("[composio][scopes] kv_put failed: {e}"))?;
+ let path = file_store::path(config, USER_SCOPES_FILE);
+ let _guard = file_store::lock().await;
+ let mut prefs: ScopeFile = file_store::load(&path).await?;
+ prefs.insert(key.clone(), pref);
+ file_store::save(&path, &prefs).await?;
tracing::info!(
toolkit = %key,
read = pref.read,
write = pref.write,
admin = pref.admin,
- driver = binding.driver_id(),
"[composio][scopes] pref saved"
);
Ok(())