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
feat(embed): add Agent::approvals, scoped to that agent's requests (#7032)
oxoxDev89cc4a13df36
diff --git a/crates/openhuman-embed/src/agent/approvals.rs b/crates/openhuman-embed/src/agent/approvals.rsnew file mode 100644index 0000000000..23542db1ed--- /dev/null+++ b/crates/openhuman-embed/src/agent/approvals.rs@@ -0,0 +1,80 @@+//! One agent's view of the runtime's approval gate.+//!+//! The gate and its `pending_approvals` store are process-owned, shared by+//! every agent on the runtime. Each request records the agent that parked it,+//! and an [`Approvals`] handle lists and decides only its own agent's.++use openhuman_core::security::approval::{ApprovalError, ApprovalGate};++pub use openhuman_core::security::approval::{ApprovalDecision, PendingApproval};++/// Why an [`Approvals`] call failed.+#[derive(Debug, thiserror::Error)]+#[non_exhaustive]+pub enum ApprovalsError {+ /// The runtime runs without an approval gate, so nothing ever parks.+ #[error("the approval gate is not installed on this runtime")]+ GateNotInstalled,+ /// The request was parked by another agent.+ #[error("approval request {0} belongs to another agent")]+ WrongAgent(String),+ /// No undecided request with this id exists for the agent.+ #[error("no pending approval {0} for this agent")]+ NotFound(String),+ /// The approval store failed.+ #[error("approval store: {0}")]+ Store(String),+}++/// The pending approvals of one agent. Obtain with+/// [`Agent::approvals`](super::Agent::approvals).+#[derive(Debug, Clone)]+pub struct Approvals {+ agent_id: String,+}++impl Approvals {+ pub(crate) fn new(agent_id: &str) -> Self {+ Self {+ agent_id: agent_id.to_string(),+ }+ }++ /// The agent's undecided requests, oldest first. Empty when the runtime+ /// has no approval gate.+ pub fn pending(&self) -> Result<Vec<PendingApproval>, ApprovalsError> {+ let Some(gate) = ApprovalGate::try_global() else {+ return Ok(Vec::new());+ };+ gate.list_pending_for_agent(Some(&self.agent_id))+ .map_err(|err| ApprovalsError::Store(err.to_string()))+ }++ /// Decide one of the agent's requests and release its parked call.+ ///+ /// [`ApprovalDecision::ApproveAlwaysForTool`] approves this call only; an+ /// agent's standing grants come from+ /// [`Access::auto_approve`](crate::Access::auto_approve).+ pub fn decide(+ &self,+ request_id: &str,+ decision: ApprovalDecision,+ ) -> Result<PendingApproval, ApprovalsError> {+ let gate = ApprovalGate::try_global().ok_or(ApprovalsError::GateNotInstalled)?;+ log::debug!(+ "[embed][approvals] agent={} decide request_id={request_id} decision={}",+ self.agent_id,+ decision.as_str()+ );+ match gate.decide_for_agent(&self.agent_id, request_id, decision) {+ Ok(Some(row)) => Ok(row),+ Ok(None) => Err(ApprovalsError::NotFound(request_id.to_string())),+ Err(err) => match err.downcast_ref::<ApprovalError>() {+ Some(ApprovalError::WrongAgent { request_id }) => {+ Err(ApprovalsError::WrongAgent(request_id.clone()))+ }+ _ => Err(ApprovalsError::Store(err.to_string())),+ },+ }+ }+}diff --git a/crates/openhuman-embed/src/agent/mod.rs b/crates/openhuman-embed/src/agent/mod.rsindex b492b7319d..591beeba8d 100644--- a/crates/openhuman-embed/src/agent/mod.rs+++ b/crates/openhuman-embed/src/agent/mod.rs@@ -14,7 +14,9 @@//! loader, DomainSet gate, tool-group filter and skill discovery all read//! the ambient context.+mod approvals;mod attachments;+pub use approvals::{ApprovalDecision, Approvals, ApprovalsError, PendingApproval};pub use attachments::ToolAttachmentError;pub(crate) mod build;mod definition;@@ -155,6 +157,12 @@ impl Agent {turn}+ /// This agent's pending approvals: the requests its turns parked, and+ /// only those.+ pub fn approvals(&self) -> Approvals {+ Approvals::new(&self.inner.id)+ }+/// The agent's read/write root for acting tools.pub fn action_dir(&self) -> &Path {&self.inner.config.action_dirdiff --git a/crates/openhuman-embed/src/lib.rs b/crates/openhuman-embed/src/lib.rsindex b2d29e5855..73d2b94bfc 100644--- a/crates/openhuman-embed/src/lib.rs+++ b/crates/openhuman-embed/src/lib.rs@@ -98,8 +98,8 @@ mod turn;pub use agent::ToolAttachmentError;pub use agent::{- Agent, AgentDefinitionSpec, AgentError, AgentLayout, AgentSpec, MemoryBinding, SandboxModeSpec,- ToolScopeSpec,+ Agent, AgentDefinitionSpec, AgentError, AgentLayout, AgentSpec, ApprovalDecision, Approvals,+ ApprovalsError, MemoryBinding, PendingApproval, SandboxModeSpec, ToolScopeSpec,};pub use auth::{Auth, AuthState, Session};pub use config::{Config, RuntimeFlags};