Skip to content

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

feat(embed): give each agent its own policy, auto-approve list and approval switch (#7032)

oxoxDeva1d45e6b4809
diff --git a/crates/openhuman-embed/src/agent/build.rs b/crates/openhuman-embed/src/agent/build.rs
index 425ca494c6..24f57c4865 100644
--- a/crates/openhuman-embed/src/agent/build.rs
+++ b/crates/openhuman-embed/src/agent/build.rs
@@ -164,19 +164,29 @@ pub(crate) fn instantiate(runtime: &Runtime, spec: AgentSpec) -> Result<AgentInn
user_skill_roots: parts.include_user_skills,
// A host session store keeps each agent's conversations apart by id.
session_agent: Some(id.to_string()),
- agent_policy: None,
- approvals_disabled: false,
+ agent_policy: Some(std::sync::Arc::new(
+ openhuman_core::security::SecurityPolicy::from_config(
+ &config.autonomy,
+ &config.workspace_dir,
+ &config.action_dir,
+ )
+ .with_privacy_mode(config.privacy.mode),
+ )),
+ approvals_disabled: !access.approval_gate_enabled(),
definitions: None,
};
let ctx = runtime.core_runtime().context().derive_with(overlay);
+ openhuman_core::core::runtime::AgentContextRegistry::register(&id, &ctx);
log::debug!(
"[embed][agent] instantiated id={id} action_dir={} routed={} access_origin={} \
- user_skills={}",
+ user_skills={} tier={:?} approval_gate={}",
config.action_dir.display(),
provider.is_routed(),
access.turn_origin().is_some(),
- parts.include_user_skills
+ parts.include_user_skills,
+ config.autonomy.level,
+ access.approval_gate_enabled()
);
Ok(AgentInner {
diff --git a/crates/openhuman-embed/src/agent/mod.rs b/crates/openhuman-embed/src/agent/mod.rs
index 2362cdc2ec..b492b7319d 100644
--- a/crates/openhuman-embed/src/agent/mod.rs
+++ b/crates/openhuman-embed/src/agent/mod.rs
@@ -99,6 +99,12 @@ pub(crate) struct AgentInner {
pub(crate) host_tools: Option<openhuman_core::agent::HostTools>,
}
+impl Drop for AgentInner {
+ fn drop(&mut self) {
+ openhuman_core::core::runtime::AgentContextRegistry::deregister(&self.id, &self.ctx);
+ }
+}
+
/// A handle to one agent on a runtime.
///
/// Cheap to clone; every clone drives the same agent. The id is released for
diff --git a/crates/openhuman-embed/src/harness/access.rs b/crates/openhuman-embed/src/harness/access.rs
index e6136000ac..eef341e68f 100644
--- a/crates/openhuman-embed/src/harness/access.rs
+++ b/crates/openhuman-embed/src/harness/access.rs
@@ -33,6 +33,8 @@ pub struct Access {
trusted_roots: Vec<TrustedRoot>,
allow_tool_install: bool,
approval_gate: bool,
+ auto_approve: Option<Vec<String>>,
+ auto_approve_all: Option<bool>,
}
impl Default for Access {
@@ -55,6 +57,8 @@ impl Access {
trusted_roots: Vec::new(),
allow_tool_install: false,
approval_gate: true,
+ auto_approve: None,
+ auto_approve_all: None,
}
}
@@ -70,6 +74,8 @@ impl Access {
trusted_roots: Vec::new(),
allow_tool_install: false,
approval_gate: true,
+ auto_approve: None,
+ auto_approve_all: None,
}
}
@@ -94,6 +100,8 @@ impl Access {
trusted_roots: Vec::new(),
allow_tool_install: false,
approval_gate: false,
+ auto_approve: None,
+ auto_approve_all: None,
}
}
@@ -120,6 +128,36 @@ impl Access {
self
}
+ /// Tools this agent runs without asking, replacing the runtime's
+ /// "Always allow" list for this agent only.
+ pub fn auto_approve<I, S>(mut self, tools: I) -> Self
+ where
+ I: IntoIterator<Item = S>,
+ S: Into<String>,
+ {
+ self.auto_approve = Some(tools.into_iter().map(Into::into).collect());
+ self
+ }
+
+ /// Approve every gated call for this agent without asking, or (`false`)
+ /// withdraw a blanket approval the runtime config carries.
+ ///
+ /// An unlabelled turn origin is still denied.
+ pub fn auto_approve_all(mut self, enabled: bool) -> Self {
+ self.auto_approve_all = Some(enabled);
+ self
+ }
+
+ /// Turn the interactive approval gate on or off for this agent.
+ ///
+ /// Off, gated calls run without parking at this agent's tier, while
+ /// other agents on the runtime keep parking. Forced approvals and an
+ /// unlabelled origin are still refused.
+ pub fn approval_gate(mut self, enabled: bool) -> Self {
+ self.approval_gate = enabled;
+ self
+ }
+
/// Override the turn origin.
///
/// The presets pick one for you. Reach for this when the harness is driving
@@ -156,6 +194,12 @@ impl Access {
config.autonomy.level = self.level;
config.autonomy.allow_tool_install = self.allow_tool_install;
config.autonomy.trusted_roots = self.trusted_roots.clone();
+ if let Some(tools) = &self.auto_approve {
+ config.autonomy.auto_approve = tools.clone();
+ }
+ if let Some(enabled) = self.auto_approve_all {
+ config.autonomy.auto_approve_all = enabled;
+ }
// `auto_approve_all` is deliberately NOT set for `full()`. The origin
// is the correct instrument — it says *who is calling*, which the gate
// can reason about — whereas `auto_approve_all` is a blanket bypass