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(session-host): let a builder caller stamp its own agent definition
sanil-23fd204f373122
diff --git a/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs b/crates/openhuman-core/src/agent/session_host/builder/builder_build.rsindex 0bbc2b8afb..5f447e1e12 100644--- a/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs+++ b/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs@@ -285,6 +285,21 @@ impl SessionHostBuilder {);#[cfg(not(test))]let definitions = crate::agent::harness::AgentDefinitionRegistry::global_arc();+ // A caller that brought its own definition is the authority for this+ // session, so it does not need a process registry to exist before it+ // may run a turn. The stand-in is deliberately *empty* rather than+ // `builtins_only()`: such a caller has not asked for OpenHuman's+ // agents, and materialising them would make `orchestrator` and every+ // other built-in id silently resolvable in a host that never declared+ // one. The session's own definition outranks whichever registry this+ // is, so where a process registry does exist nothing about its+ // resolution changes.+ let session_definition = self.session_definition;+ let definitions = definitions.or_else(|| {+ session_definition+ .is_some()+ .then(|| Arc::new(crate::agent::harness::AgentDefinitionRegistry::default()))+ });let hosted_base = definitions.map(|definitions| {Arc::new(crate::agent::tinyagents::host::OpenHumanHostBase {security_policy: Arc::new(crate::security::SecurityPolicy::from_config(@@ -296,9 +311,11 @@ impl SessionHostBuilder {definitions,memory: Arc::clone(&memory),post_turn_hooks: self.post_turn_hooks.clone(),- // This path names a registry id; it never carries a- // caller-supplied definition.- session_definition: None,+ // Usually this path names a registry id, and carries no+ // definition of its own. A caller that supplied one with+ // `agent_definition` is stamped with it here, the way+ // `build_session_agent_inner` stamps the one it resolved.+ session_definition: session_definition.clone(),})});diff --git a/crates/openhuman-core/src/agent/session_host/builder/builder_tests.rs b/crates/openhuman-core/src/agent/session_host/builder/builder_tests.rsindex e84e285c48..f6e9c9d170 100644--- a/crates/openhuman-core/src/agent/session_host/builder/builder_tests.rs+++ b/crates/openhuman-core/src/agent/session_host/builder/builder_tests.rs@@ -48,6 +48,8 @@ fn builtin_def(id: &str) -> crate::agent::harness::definition::AgentDefinition {mod explicit_definition_tests;#[path = "builder_tests_memory_write_instruction_tests.rs"]mod memory_write_instruction_tests;+#[path = "builder_tests_session_definition_tests.rs"]+mod session_definition_tests;#[path = "builder_tests_tool_exposure_tests.rs"]mod tool_exposure_tests;#[path = "builder_tests_tool_spec_views_tests.rs"]diff --git a/crates/openhuman-core/src/agent/session_host/builder/builder_tests_session_definition_tests.rs b/crates/openhuman-core/src/agent/session_host/builder/builder_tests_session_definition_tests.rsnew file mode 100644index 0000000000..ec71c795cf--- /dev/null+++ b/crates/openhuman-core/src/agent/session_host/builder/builder_tests_session_definition_tests.rs@@ -0,0 +1,142 @@+//! `agent_definition`: a direct builder caller can be its own catalogue.+//!+//! Every session turn is a hosted root invocation that resolves its agent id+//! against the host catalogue before it composes a message, and refuses the+//! turn when the id is not there. `from_config_with_definition` already+//! stamps a caller's definition on the session for that reason; a direct+//! builder caller had no equivalent, and fell back to the process registry.+//! These tests pin the route that closes that gap.++use crate::agent::harness::definition::{AgentDefinition, AgentDefinitionRegistry, ToolScope};+use crate::agent::tinyagents::host::OpenHumanDefinitionRegistry;+use std::sync::Arc;+use tinyagents_definition::DefinitionRegistry;++/// An id no built-in definition uses, so a hit can only have come from the+/// caller's own definition.+const SEAT: &str = "library-host--seat";++fn definition(id: &str, tools: Vec<&str>) -> Arc<AgentDefinition> {+ let mut def = AgentDefinitionRegistry::builtins_only()+ .get("orchestrator")+ .cloned()+ .expect("built-in orchestrator");+ def.id = id.to_string();+ def.display_name = Some("Library host seat".to_string());+ def.when_to_use = "a seat a library host built and owns".to_string();+ def.tools = ToolScope::Named(tools.into_iter().map(str::to_string).collect());+ def.disallowed_tools.clear();+ Arc::new(def)+}++fn seat(+ definition: Option<Arc<AgentDefinition>>,+) -> crate::agent::session_host::types::OpenHumanSessionHost {+ let model: Arc<dyn tinyinference_llm::model::ChatModel<()>> =+ Arc::new(tinyagents_harness::testkit::ScriptedModel::new(Vec::new()));+ let mut builder = crate::agent::SessionHostBuilder::new()+ .chat_model(model)+ .tools(Vec::new())+ .memory(crate::memory::test_support::noop_memory())+ .tool_dispatcher(Box::new(tinytools_agent::dialect::XmlDialect))+ .agent_definition_name(SEAT);+ if let Some(definition) = definition {+ builder = builder.agent_definition(definition);+ }+ builder+ .build()+ .expect("a library host seat is a legal build")+}++/// The catalogue a turn is resolved against, assembled the way+/// `OpenHumanHostBundleFactory::build` assembles it.+fn catalogue(+ agent: &crate::agent::session_host::types::OpenHumanSessionHost,+) -> OpenHumanDefinitionRegistry {+ let base = agent+ .hosted_base+ .as_ref()+ .expect("a caller that brought its own definition has a hosted authority");+ let mut catalogue = OpenHumanDefinitionRegistry::new(Arc::clone(&base.definitions))+ .with_config(Arc::clone(&base.config));+ if let Some(definition) = base.session_definition.as_ref() {+ catalogue = catalogue.with_session_definition(Arc::clone(definition));+ }+ catalogue+}++#[tokio::test]+async fn a_definition_the_builder_was_given_resolves_for_the_turn() {+ let agent = seat(Some(definition(SEAT, vec!["desk_say", "publish_artifact"])));++ let resolved = catalogue(&agent)+ .resolve(SEAT)+ .await+ .expect("resolution never errors")+ .expect("the caller's own definition answers the lookup");++ assert_eq!(resolved.id, SEAT);+ assert_eq!(resolved.name, "Library host seat");+ assert!(+ resolved.is_valid(),+ "a hosted turn refuses an invalid definition: {:?}",+ resolved.diagnostics()+ );+}++#[tokio::test]+async fn the_definition_carries_the_belt_the_turn_is_allowed_to_call() {+ // The resolved definition's tool list *is* the turn's allow-list, so a+ // seat whose belt it does not name cannot call it. A definition that+ // names nothing denies everything rather than allowing everything.+ let agent = seat(Some(definition(SEAT, vec!["desk_say", "publish_artifact"])));++ let resolved = catalogue(&agent)+ .resolve(SEAT)+ .await+ .expect("resolution never errors")+ .expect("resolves");++ assert_eq!(resolved.tools, vec!["desk_say", "publish_artifact"]);+}++#[tokio::test]+async fn the_sessions_own_definition_outranks_a_registry_entry_sharing_its_id() {+ // A library host may reuse an id the process registry also knows. Its own+ // definition must win, or the host silently runs someone else's agent.+ let _ = AgentDefinitionRegistry::init_global_builtins();+ let agent = seat(Some(definition("orchestrator", vec!["desk_say"])));++ let resolved = catalogue(&agent)+ .resolve("orchestrator")+ .await+ .expect("resolution never errors")+ .expect("resolves");++ assert_eq!(resolved.name, "Library host seat");+ assert_eq!(resolved.tools, vec!["desk_say"]);+}++#[tokio::test]+async fn without_a_definition_the_same_id_is_still_unknown() {+ // The counterpart, and the reason this route had to exist: nothing else+ // the builder takes can put an id in the catalogue.+ let agent = seat(None);+ let Some(base) = agent.hosted_base.as_ref() else {+ // No catalogue at all, which is the "unknown" this test asserts.+ return;+ };+ assert!(base.session_definition.is_none());++ let catalogue = OpenHumanDefinitionRegistry::new(Arc::clone(&base.definitions))+ .with_config(Arc::clone(&base.config));++ assert!(+ catalogue+ .resolve(SEAT)+ .await+ .expect("resolution never errors")+ .is_none(),+ "the id must not resolve without the caller's definition"+ );+}diff --git a/crates/openhuman-core/src/agent/session_host/builder/setters.rs b/crates/openhuman-core/src/agent/session_host/builder/setters.rsindex 4d208194ec..5a883449ed 100644--- a/crates/openhuman-core/src/agent/session_host/builder/setters.rs+++ b/crates/openhuman-core/src/agent/session_host/builder/setters.rs@@ -37,6 +37,7 @@ impl SessionHostBuilder {event_session_id: None,event_channel: None,agent_definition_name: None,+ session_definition: None,session_parent_prefix: None,session_history_locator: None,omit_profile: None,@@ -294,6 +295,48 @@ impl SessionHostBuilder {self}+ /// Give this session its own agent definition, rather than a registry id+ /// for it to be looked up by.+ ///+ /// Every session turn is a hosted root invocation: it resolves its agent+ /// id against the host catalogue before composing a message, and refuses+ /// the turn outright when the id is not there.+ /// [`OpenHumanSessionHost::from_config_with_definition`] already stamps a+ /// caller's definition on the session for that reason. A direct builder+ /// caller had no equivalent, so the only catalogue it could be resolved+ /// against was the process-wide registry, read once from+ /// `<workspace>/agents/*.toml` at startup and never refreshed.+ ///+ /// That left a library host — one already supplying its own tools, tool+ /// policy, memory, prompt and model through this same builder — writing+ /// TOML into a directory so the runtime could read back what the host+ /// already knew, and unable to add an agent or widen one's tools without+ /// restarting the process.+ ///+ /// The definition outranks the registry for this session's own id (see+ /// [`OpenHumanDefinitionRegistry::with_session_definition`]), so a host+ /// that brings its own agents is not shadowed by a built-in that happens+ /// to share an id. Set+ /// [`agent_definition_name`](Self::agent_definition_name) to the same id,+ /// or the definition is unresolvable by the id the session was stamped+ /// with.+ ///+ /// Note that the resolved definition's tool list *is* the turn's+ /// allow-list, intersected with the tools the session was built with, and+ /// that the hosted allow-list is fail-closed: a definition declaring no+ /// tools denies every call rather than allowing all of them. A caller+ /// must name the belt it built the session with.+ ///+ /// [`OpenHumanSessionHost::from_config_with_definition`]: crate::agent::OpenHumanSessionHost::from_config_with_definition+ /// [`OpenHumanDefinitionRegistry::with_session_definition`]: crate::agent::tinyagents::host::OpenHumanDefinitionRegistry::with_session_definition+ pub fn agent_definition(+ mut self,+ definition: Arc<crate::agent::harness::definition::AgentDefinition>,+ ) -> Self {+ self.session_definition = Some(definition);+ self+ }+/// Set the parent session-key chain for a sub-agent. Passing/// `Some("1713000000_orchestrator")` produces a sub-agent whose/// transcript filename is prefixed with the parent's session key,diff --git a/crates/openhuman-core/src/agent/session_host/types.rs b/crates/openhuman-core/src/agent/session_host/types.rsindex f39d6a84b9..ebd0b7a5c3 100644--- a/crates/openhuman-core/src/agent/session_host/types.rs+++ b/crates/openhuman-core/src/agent/session_host/types.rs@@ -519,6 +519,25 @@ pub struct SessionHostBuilder {pub(super) event_session_id: Option<String>,pub(super) event_channel: Option<String>,pub(super) agent_definition_name: Option<String>,+ /// The session's own definition, when the caller has one rather than a+ /// registry id to name.+ ///+ /// A hosted root invocation resolves its agent id against the host+ /// catalogue before it composes a message, and refuses the turn when the+ /// id is not there. `from_config_with_definition` stamps a caller's+ /// definition on the session for exactly that reason; a direct builder+ /// caller had no equivalent, so its only catalogue was the process-wide+ /// [`AgentDefinitionRegistry`] — read once from `<workspace>/agents/*.toml`+ /// at startup, with no refresh.+ ///+ /// Set here it becomes+ /// [`OpenHumanHostBase::session_definition`](crate::agent::tinyagents::host::OpenHumanHostBase::session_definition),+ /// which outranks the registry for this session's own id.+ ///+ /// `None` (the default) leaves every existing caller as it was.+ ///+ /// [`AgentDefinitionRegistry`]: crate::agent::harness::definition::AgentDefinitionRegistry+ pub(super) session_definition: Option<Arc<crate::agent::harness::definition::AgentDefinition>>,/// Directory chain of parent session keys for a sub-agent. `None`/// (default) means this is a root session — its transcript lands/// flat in `session_raw/DDMMYYYY/{session_key}.jsonl`. Populateddiff --git a/docs/TEST-COVERAGE-MATRIX.md b/docs/TEST-COVERAGE-MATRIX.mdindex 515b0d56dc..6c22b90656 100644--- a/docs/TEST-COVERAGE-MATRIX.md+++ b/docs/TEST-COVERAGE-MATRIX.md@@ -226,6 +226,7 @@ End-to-end coverage of the agent harness via the web-chat RPC surface against an| 4.4.13 | Grounded Close (no final text / breaker halt) | RU | `crates/openhuman-core/src/agent/session_host/turn_final_reply_grounding_tests.rs`, `crates/openhuman-core/src/agent/session_host/turn_checkpoint_tests.rs` | ✅ | Tool-records wrap-up, check rejects intent narration / contradicted claims, fallback quotes failure messages; breaker stop note never shown verbatim (#6278, #6279) || 4.4.14 | Session todo list (the `todo` tool) | RI+VU+WD | `tests/agent_harness_e2e.rs`, `crates/openhuman-core/src/agent/tools/todo_tests.rs`, `vendor/tinyagents/crates/tinyagents-graph/src/todos/test.rs`, `app/src/features/conversations/utils/harnessState.test.ts`, `app/src/features/conversations/components/TodoChecklist.test.tsx`, `app/src/features/conversations/hooks/useThreadHarnessState.test.ts`, `app/test/e2e/specs/chat-todos-goals.spec.ts` | ✅ | Whole-list write per call (Claude/Codex shape), single-`in_progress` invariant, per-session scoping; five items ticked off across turns, live on the socket, persisted in the turn state, and rendered as the chat pane's checklist || 4.4.15 | Thread goal (`goal_set` / `goal_get` / `goal_complete`) | RI+RU+VU+WD | `tests/agent_harness_e2e.rs`, `crates/openhuman-core/src/agent/goals/{tools_tests.rs,runtime_tests.rs,continuation_tests.rs}`, `vendor/tinyagents/crates/tinyagents-graph/src/goals/test.rs`, `app/src/features/conversations/utils/harnessState.test.ts`, `app/src/features/conversations/components/GoalBanner.test.tsx`, `app/src/features/conversations/hooks/useThreadHarnessState.test.ts`, `app/test/e2e/specs/chat-todos-goals.spec.ts` | ✅ | Objective + token budget set, read back across turns, and completed; structured `{goal, text}` payload drives the chat pane's goal banner. Budget accounting and the budget-limit stop hook are unit-covered (the scripted e2e upstream reports no usage) |+| 4.4.16 | Builder-supplied session definition (library host) | RU | `crates/openhuman-core/src/agent/session_host/builder/builder_tests_session_definition_tests.rs` | ✅ | `SessionHostBuilder::agent_definition` stamps a caller's own `AgentDefinition` on the session, so a hosted root invocation resolves an id the process registry never held; it outranks a registry entry sharing its id, it carries the turn's tool allow-list, and without it the same id stays unknown |---