Skip to content

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

refactor(subagent_host): widen lifecycle visibility and use absolute paths

Steven Enamakelec2d99ffc978
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
index 3304942499..56c179eee9 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
@@ -36,6 +36,8 @@ mod checkpoint;
#[path = "lifecycle_outcome.rs"]
mod outcome;
use checkpoint::absolute_checkpoint_dir;
+use outcome::HostInFlightMap;
+use driver_adapter::HostInvocation;
use super::{
SubagentRunError, SubagentRunOptions, SubagentRunOutcome, SubagentRunStatus, SubagentUsage,
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs
index d1d5142f4b..a7ef97771a 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs
@@ -5,7 +5,7 @@ pub(crate) struct OpenHumanDriverBundle {
Arc<SubagentDriver<crate::agent::tinyagents::host::OpenHumanRunContext, HostRequest>>,
pub(crate) failures: Arc<Mutex<HashMap<SubagentTaskKey, SubagentRunError>>>,
pub(crate) host_outcome: Arc<Mutex<HashMap<SubagentTaskKey, SubagentRunOutcome>>>,
- configured_tool_result: Arc<Mutex<HashMap<SubagentTaskKey, tinytools::ToolResult>>>,
+ pub(super) configured_tool_result: Arc<Mutex<HashMap<SubagentTaskKey, tinytools::ToolResult>>>,
pub(crate) persistence: Arc<OpenHumanPersistence>,
}
@@ -55,7 +55,7 @@ pub(crate) struct HostRequest {
}
#[derive(Clone)]
-enum HostInvocation {
+pub(super) enum HostInvocation {
Agent(crate::agent_registry::host_definition::AgentDefinition),
ConfiguredTool {
agent_id: String,
@@ -65,7 +65,7 @@ enum HostInvocation {
}
impl HostRequest {
- fn agent_id(&self) -> &str {
+ pub(super) fn agent_id(&self) -> &str {
match &self.invocation {
HostInvocation::Agent(definition) => &definition.id,
HostInvocation::ConfiguredTool { agent_id, .. } => agent_id,
@@ -184,7 +184,7 @@ impl SubagentExecutor<crate::agent::tinyagents::host::OpenHumanRunContext> for O
.unwrap_or_default();
match invocation {
HostInvocation::Agent(definition) => {
- let run = Box::pin(super::ops::run_subagent_direct(
+ let run = Box::pin(crate::agent::subagent_host::ops::run_subagent_direct(
&definition,
&input,
options.clone(),
@@ -272,7 +272,7 @@ impl SubagentExecutor<crate::agent::tinyagents::host::OpenHumanRunContext> for O
output: output.clone(),
iterations: 1,
elapsed: std::time::Duration::ZERO,
- mode: super::SubagentMode::Typed,
+ mode: crate::agent::subagent_host::SubagentMode::Typed,
status,
final_history: Vec::new(),
usage: SubagentUsage::default(),
@@ -361,7 +361,7 @@ pub(super) fn outcome_to_host(
.map(|(_, elapsed_ms)| elapsed_ms)
.unwrap_or_default(),
),
- mode: super::SubagentMode::Typed,
+ mode: crate::agent::subagent_host::SubagentMode::Typed,
status: SubagentRunStatus::Completed,
final_history: outcome
.history
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs
index 1acc958e8e..3556aea3f3 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs
@@ -1,6 +1,7 @@
use super::*;
+use crate::agent::subagent_host::types::SubagentCheckpointData;
-pub(super) struct OpenHumanPersistence {
+pub(in crate::agent::subagent_host) struct OpenHumanPersistence {
checkpoint_dir: std::path::PathBuf,
host_outcome: Arc<Mutex<HashMap<SubagentTaskKey, SubagentRunOutcome>>>,
}
@@ -29,7 +30,7 @@ impl OpenHumanPersistence {
}
}
- fn with_host_outcome(
+ pub(super) fn with_host_outcome(
mut self,
host_outcome: Arc<Mutex<HashMap<SubagentTaskKey, SubagentRunOutcome>>>,
) -> Self {
@@ -65,7 +66,7 @@ impl OpenHumanPersistence {
}
}
- fn pause_path(&self, key: &SubagentTaskKey) -> std::path::PathBuf {
+ pub(super) fn pause_path(&self, key: &SubagentTaskKey) -> std::path::PathBuf {
self.checkpoint_dir
.join("lifecycle")
.join(format!("{}.pause.json", Self::key_component(key)))
@@ -239,13 +240,13 @@ impl OpenHumanPersistence {
fn read_pause_checkpoint(
&self,
key: &SubagentTaskKey,
- ) -> Result<Option<super::SubagentCheckpointData>, SubagentError> {
+ ) -> Result<Option<SubagentCheckpointData>, SubagentError> {
let raw = match std::fs::read_to_string(self.pause_path(key)) {
Ok(raw) => raw,
Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(None),
Err(error) => return Err(SubagentError::Persistence(error.to_string())),
};
- let checkpoint = serde_json::from_str::<super::SubagentCheckpointData>(&raw)
+ let checkpoint = serde_json::from_str::<SubagentCheckpointData>(&raw)
.map_err(|error| SubagentError::Persistence(error.to_string()))?;
if checkpoint.task_key.as_ref() != Some(key) {
return Err(SubagentError::Persistence("checkpoint key mismatch".into()));
@@ -274,7 +275,7 @@ impl OpenHumanPersistence {
}
}
- fn durable_host_metadata(
+ pub(super) fn durable_host_metadata(
&self,
key: &SubagentTaskKey,
) -> Result<Option<(String, u64)>, SubagentError> {
@@ -290,7 +291,7 @@ impl OpenHumanPersistence {
}))
}
- pub(crate) fn checkpoint_resume(checkpoint: &super::SubagentCheckpointData) -> SubagentResume {
+ pub(crate) fn checkpoint_resume(checkpoint: &SubagentCheckpointData) -> SubagentResume {
SubagentResume {
history: checkpoint
.history
@@ -302,7 +303,7 @@ impl OpenHumanPersistence {
}
}
- fn checkpoint_outcome(checkpoint: super::SubagentCheckpointData) -> SubagentOutcome {
+ fn checkpoint_outcome(checkpoint: SubagentCheckpointData) -> SubagentOutcome {
let resume = Self::checkpoint_resume(&checkpoint);
SubagentOutcome {
task_id: checkpoint.task_id,
@@ -350,7 +351,7 @@ impl OpenHumanPersistence {
fn live_checkpoint(
&self,
key: &SubagentTaskKey,
- ) -> Result<Option<super::SubagentCheckpointData>, SubagentError> {
+ ) -> Result<Option<SubagentCheckpointData>, SubagentError> {
let _key_lock = self.key_lock(key)?;
if self.terminal_path(key).exists() {
return Ok(None);
@@ -358,11 +359,11 @@ impl OpenHumanPersistence {
self.read_pause_checkpoint(key)
}
- fn checkpoint_for_task(
+ pub(super) fn checkpoint_for_task(
&self,
task_id: &str,
- ) -> Result<super::SubagentCheckpointData, SubagentRunError> {
- if !super::ops::is_safe_task_id(task_id) {
+ ) -> Result<SubagentCheckpointData, SubagentRunError> {
+ if !crate::agent::subagent_host::ops::is_safe_task_id(task_id) {
return Err(SubagentRunError::Provider(anyhow::anyhow!(
"unsafe task id"
)));
@@ -456,7 +457,7 @@ impl tinyagents_orchestration::subagent::SubagentPersistence for OpenHumanPersis
.filter(|value| !value.is_empty())
.cloned()
};
- let checkpoint = super::SubagentCheckpointData {
+ let checkpoint = SubagentCheckpointData {
task_key: Some(pause.key.clone()),
task_id: pause.key.task_id.clone(),
agent_id: optional_metadata("agent_id").unwrap_or_default(),