Skip to content

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

feat(agent): add host definition support for subagent sessions

Steven Enamakel1f533bf718f8
diff --git a/crates/openhuman-core/src/agent/harness/host_definition.rs b/crates/openhuman-core/src/agent/harness/host_definition.rs
index 68be9c9781..a415349324 100644
--- a/crates/openhuman-core/src/agent/harness/host_definition.rs
+++ b/crates/openhuman-core/src/agent/harness/host_definition.rs
@@ -108,14 +108,28 @@ fn same_definition(a: &AgentDefinition, b: &AgentDefinition) -> bool {
}
}
-/// The prompt builder behind a `PromptSource::Dynamic(())` marker.
-pub fn dynamic_prompt_builder(def: &AgentDefinition) -> Result<PromptBuilder> {
- def.extensions.prompt_builder.ok_or_else(|| {
- anyhow::anyhow!(
- "agent `{}` declares a dynamic prompt but has no builder",
- def.id
- )
- })
+/// Host accessors on the portable [`AgentDefinition`].
+pub trait AgentDefinitionExt {
+ /// The concrete TokenJuice policy (see [`AgentExt::effective_tokenjuice_compression`]).
+ fn effective_tokenjuice_compression(&self) -> AgentTokenjuiceCompression;
+ /// The prompt builder behind a `PromptSource::Dynamic(())` marker.
+ fn prompt_fn(&self) -> Result<PromptBuilder>;
+}
+
+impl AgentDefinitionExt for AgentDefinition {
+ fn effective_tokenjuice_compression(&self) -> AgentTokenjuiceCompression {
+ self.extensions
+ .effective_tokenjuice_compression(&self.model)
+ }
+
+ fn prompt_fn(&self) -> Result<PromptBuilder> {
+ self.extensions.prompt_builder.ok_or_else(|| {
+ anyhow::anyhow!(
+ "agent `{}` declares a dynamic prompt but has no builder",
+ self.id
+ )
+ })
+ }
}
/// Re-check the spawn-hierarchy contract over a slice of definitions.
diff --git a/crates/openhuman-core/src/agent/session_host/builder/factory.rs b/crates/openhuman-core/src/agent/session_host/builder/factory.rs
index 3af005e3d7..aadbe6eba5 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/factory.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/factory.rs
@@ -4,7 +4,7 @@ use super::dispatcher::{resolve_dispatcher_kind, DispatcherKind};
use super::host_tools::derive_turn_workspace_descriptor;
use super::should_synthesize_delegation_tools;
use crate::agent::harness::host_definition::{
- dynamic_prompt_builder, AgentDefinitionRegistry, NO_TOOLS_SENTINEL,
+ AgentDefinitionExt, AgentDefinitionRegistry, NO_TOOLS_SENTINEL,
};
use crate::agent::host_runtime;
use crate::agent::prompts::SystemPromptBuilder;
@@ -345,9 +345,7 @@ impl OpenHumanSessionHost {
// body and get wrapped by [`SystemPromptBuilder::for_subagent`].
let prompt_builder = match target_def {
Some(def) => match &def.system_prompt {
- PromptSource::Dynamic(()) => {
- SystemPromptBuilder::from_dynamic(dynamic_prompt_builder(def)?)
- }
+ PromptSource::Dynamic(()) => SystemPromptBuilder::from_dynamic(def.prompt_fn()?),
PromptSource::Verbatim(text) => SystemPromptBuilder::verbatim(text.clone()),
PromptSource::Inline(text) => SystemPromptBuilder::for_subagent(
text.clone(),
@@ -671,7 +669,7 @@ impl OpenHumanSessionHost {
.map(|def| def.extensions.omit_memory_context)
.unwrap_or(false);
let effective_tokenjuice_compression = target_def
- .map(|def| def.extensions.effective_tokenjuice_compression(&def.model))
+ .map(|def| def.effective_tokenjuice_compression())
.unwrap_or(tinyjuice_bus::types::AgentTokenjuiceCompression::Full);
// Stamp the resolved agent definition id onto the OpenHumanSessionHost via the
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
index c31fadf3dd..d19f2c5796 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
@@ -11,7 +11,9 @@ use std::time::Instant;
use crate::agent::harness::artifact_offload::{new_artifact_offload, offload_oversized_result};
use crate::agent::harness::fork_context::ParentExecutionContext;
-use crate::agent::harness::host_definition::{AgentDefinition, AgentDefinitionRegistry};
+use crate::agent::harness::host_definition::{
+ AgentDefinition, AgentDefinitionExt, AgentDefinitionRegistry,
+};
use crate::agent::prompts::{
render_subagent_system_prompt_with_format, PromptContext, SubagentRenderOptions,
};
@@ -945,9 +947,7 @@ async fn run_typed_mode(
// own channel in per-thread usage reads.
"subagent",
// Agent TokenJuice profile → sub-agent context middleware (#4466).
- definition
- .extensions
- .effective_tokenjuice_compression(&definition.model),
+ definition.effective_tokenjuice_compression(),
// The spawn-wide config snapshot supplies the `[context]`
// knobs the graph used to load for itself.
config.as_ref().ok().map(|c| c.as_ref()),