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(agent): add agent definition module
Steven Enamakelc0e08fa0cc53
diff --git a/crates/openhuman-embed/src/agent/definition.rs b/crates/openhuman-embed/src/agent/definition.rsindex 02d2deadb2..04efdfee28 100644--- a/crates/openhuman-embed/src/agent/definition.rs+++ b/crates/openhuman-embed/src/agent/definition.rs@@ -25,7 +25,17 @@ pub enum ToolScopeSpec {Wildcard,/// Exactly these tool names; unknown names are dropped at build time.Named(Vec<String>),- /// Only the tools the host supplies, and nothing else.+ /// The host's tools and nothing else.+ ///+ /// For an agent that must never act — a reviewer reading an untrusted+ /// diff. The registry the model sees is built from the tools the host+ /// supplies ([`AgentSpec::tools`](super::AgentSpec::tools),+ /// [`Agent::attach_tools`](super::Agent::attach_tools)) alone: no+ /// config-derived, delegation, memory, skill or MCP tool, and a+ /// deny-by-default gate refuses any other name the model calls. The agent+ /// also runs read-only (access tier and sandbox) whatever+ /// [`Access`](crate::Access) it was given. Host tools should themselves be+ /// read-only: host-only bounds *which* tools exist, not what they do.HostOnly,}@@ -45,6 +55,8 @@ pub enum SandboxModeSpec {#[derive(Debug, Clone, Default)]pub struct AgentDefinitionSpec {system_prompt: Option<String>,+ /// The prompt is the whole system prompt, with nothing composed around it.+ bare_prompt: bool,tools: Option<ToolScopeSpec>,disallowed_tools: Vec<String>,sandbox: SandboxModeSpec,@@ -66,15 +78,28 @@ impl AgentDefinitionSpec {/// carries are kept around it; only the body changes.pub fn system_prompt(mut self, prompt: impl Into<String>) -> Self {self.system_prompt = Some(prompt.into());+ self.bare_prompt = false;self}- /// Use exactly `prompt` as the system prompt.+ /// Make `prompt` the whole system prompt, verbatim.+ ///+ /// Unlike [`system_prompt`](Self::system_prompt), no orchestrator+ /// identity, safety, tools, workspace or memory section is composed+ /// around it, and no memory context is injected into a new session. The+ /// host owns every byte the model is told. Tool schemas still travel in+ /// the request's `tools` field.pub fn bare_prompt(mut self, prompt: impl Into<String>) -> Self {self.system_prompt = Some(prompt.into());+ self.bare_prompt = true;self}+ /// Whether this is a [`ToolScopeSpec::HostOnly`] definition.+ pub(crate) fn is_host_only(&self) -> bool {+ matches!(self.tools, Some(ToolScopeSpec::HostOnly))+ }+/// Restrict which tools the agent may call.pub fn tools(mut self, scope: ToolScopeSpec) -> Self {self.tools = Some(scope);@@ -133,20 +158,43 @@ impl AgentDefinitionSpec {if let Some(text) = self.when_to_use {def.when_to_use = text;}- if let Some(prompt) = self.system_prompt {- def.system_prompt = PromptSource::Inline(prompt);+ let host_only = self.is_host_only();+ match self.system_prompt {+ Some(prompt) if self.bare_prompt => {+ def.system_prompt = PromptSource::Verbatim(prompt);+ def.omit_identity = true;+ def.omit_safety_preamble = true;+ def.omit_memory_context = true;+ }+ Some(prompt) => def.system_prompt = PromptSource::Inline(prompt),+ // The orchestrator's dynamic prompt describes a delegation and+ // memory surface a host-only agent does not have.+ None if host_only => {+ return Err(AgentError::Invalid(+ "a HostOnly agent needs its own prompt: set bare_prompt or system_prompt"+ .to_string(),+ ));+ }+ None => {}}def.tools = match self.tools.unwrap_or(ToolScopeSpec::Wildcard) {ToolScopeSpec::Wildcard => ToolScope::Wildcard,ToolScopeSpec::Named(names) => ToolScope::Named(names),- ToolScopeSpec::HostOnly => ToolScope::Wildcard,+ // Zero tools; the host's names join at session build.+ ToolScopeSpec::HostOnly => ToolScope::Named(Vec::new()),};def.disallowed_tools.extend(self.disallowed_tools);def.sandbox_mode = match self.sandbox {+ _ if host_only => SandboxMode::ReadOnly,SandboxModeSpec::None => SandboxMode::None,SandboxModeSpec::ReadOnly => SandboxMode::ReadOnly,SandboxModeSpec::Sandboxed => SandboxMode::Sandboxed,};+ if host_only {+ def.subagents.clear();+ def.extra_tools.clear();+ def.deferred_tools.clear();+ }if let Some(n) = self.max_iterations {def.max_iterations = n;}@@ -159,6 +207,7 @@ impl AgentDefinitionSpec {PromptSource::Inline(_) => "inline",PromptSource::File { .. } => "file",PromptSource::Dynamic(_) => "dynamic",+ PromptSource::Verbatim(_) => "verbatim",},def.tools,def.sandbox_mode,diff --git a/crates/openhuman-embed/src/agent/definition_tests.rs b/crates/openhuman-embed/src/agent/definition_tests.rsindex adbbf034cb..d1e6c59f30 100644--- a/crates/openhuman-embed/src/agent/definition_tests.rs+++ b/crates/openhuman-embed/src/agent/definition_tests.rs@@ -34,3 +34,45 @@ fn setters_override_one_aspect_each() {assert_eq!(def.temperature, 0.1);assert_eq!(def.display_name(), "Alpha");}++#[test]+fn bare_prompt_is_verbatim_with_nothing_composed_around_it() {+ let def = AgentDefinitionSpec::new()+ .bare_prompt("Review.")+ .into_core("alpha")+ .expect("definition");+ assert!(matches!(def.system_prompt, PromptSource::Verbatim(ref p) if p == "Review."));+ assert!(def.omit_identity && def.omit_safety_preamble && def.omit_memory_context);+}++#[test]+fn system_prompt_after_bare_prompt_is_wrapped_again() {+ let def = AgentDefinitionSpec::new()+ .bare_prompt("Review.")+ .system_prompt("Be terse.")+ .into_core("alpha")+ .expect("definition");+ assert!(matches!(def.system_prompt, PromptSource::Inline(ref p) if p == "Be terse."));+}++#[test]+fn host_only_is_an_empty_read_only_belt_that_cannot_delegate() {+ let def = AgentDefinitionSpec::new()+ .bare_prompt("Review.")+ .tools(ToolScopeSpec::HostOnly)+ .sandbox(SandboxModeSpec::None)+ .into_core("alpha")+ .expect("definition");+ assert!(matches!(def.tools, ToolScope::Named(ref names) if names.is_empty()));+ assert_eq!(def.sandbox_mode, SandboxMode::ReadOnly);+ assert!(def.subagents.is_empty());+}++#[test]+fn host_only_without_a_prompt_is_refused() {+ let err = AgentDefinitionSpec::new()+ .tools(ToolScopeSpec::HostOnly)+ .into_core("alpha")+ .expect_err("the orchestrator prompt does not describe a host-only agent");+ assert!(matches!(err, AgentError::Invalid(_)));+}