Skip to content

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

feat(agent): run-state block on orchestrator turns; the model decides on a paused goal

sanil-23fb6fd181be39
diff --git a/crates/openhuman-core/Cargo.toml b/crates/openhuman-core/Cargo.toml
index 3ec1b8eaad..a26e88e319 100644
--- a/crates/openhuman-core/Cargo.toml
+++ b/crates/openhuman-core/Cargo.toml
@@ -101,6 +101,7 @@ tinyagents-harness = { path = "../../vendor/tinyagents/crates/tinyagents-harness
tinyagents-harness-tools = { path = "../../vendor/tinyagents/crates/tinyagents-harness-tools", default-features = false, features = [
"goals",
"skills",
+ "state-block",
"subagents",
"todos",
] }
diff --git a/crates/openhuman-core/src/agent/goals/runtime.rs b/crates/openhuman-core/src/agent/goals/runtime.rs
index 13106702fd..0aba042b6e 100644
--- a/crates/openhuman-core/src/agent/goals/runtime.rs
+++ b/crates/openhuman-core/src/agent/goals/runtime.rs
@@ -34,36 +34,6 @@ pub async fn load_for_thread(workspace_dir: &Path, thread_id: Option<&str>) -> O
}
}
-/// Reactivate a paused goal for an explicit thread (thread-resume semantics).
-/// Best-effort: a failure is logged and surfaced as `Ok(None)`-style `None`.
-pub async fn resume_for_thread(
- workspace_dir: &Path,
- thread_id: Option<&str>,
-) -> Option<Option<ThreadGoal>> {
- let thread_id = normalized_thread(thread_id)?;
- let store = crate::storage::sessions::stores_or_ephemeral(workspace_dir).kv;
- match tinyagents_harness_tools::goals::store::resume(&store, &thread_id)
- .await
- .map_err(|e| e.to_string())
- {
- Ok(goal) => {
- if goal.status.is_active() {
- BUS.publish(DomainEvent::ThreadGoalUpdated {
- thread_id: goal.thread_id.clone(),
- goal_id: goal.goal_id.clone(),
- status: goal.status.as_str().to_string(),
- goal: Some(super::goal_to_value(&goal)),
- });
- }
- Some(Some(goal))
- }
- Err(e) => {
- tracing::debug!(thread_id = %thread_id, error = %e, "[thread_goals] resume_for_thread failed");
- None
- }
- }
-}
-
/// Mark the active goal for an explicit thread `Complete` (the originating
/// task settled successfully). Best-effort; safe to call when there is no goal
/// or no thread id. Emits `ThreadGoalUpdated` so the UI chip refreshes.
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index f41cf260a9..fe043d209d 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -32,7 +32,6 @@ use std::sync::Arc;
use anyhow::Result;
use tinyagents_harness::multimodal::markers::extract_image_placeholders_in_text;
use tinyagents_harness::tool::ToolSnapshot;
-use tinyagents_harness_tools::goals::ThreadGoalStatus;
use tinyagents_runtime::{
CommitReceipt, ResumePreparation, SessionBuilder, SessionTerminal, TranscriptTarget,
TurnPreparation,
@@ -621,6 +620,10 @@ pub(super) mod tool_surface;
#[path = "runtime_session_juice_tests.rs"]
mod juice_tests;
+#[cfg(test)]
+#[path = "runtime_session_goal_tests.rs"]
+mod goal_tests;
+
mod parent_snapshot;
#[path = "../../integrations/prelude_integrations.rs"]
mod prelude_integrations;
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/prelude.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/prelude.rs
index 93b3f2c1f7..eeb5422052 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session/prelude.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/prelude.rs
@@ -237,29 +237,28 @@ impl OpenHumanTurnPrelude {
) -> String {
let mut context = String::new();
+ // A paused goal stays paused: the model reads the message and resumes,
+ // replaces or leaves it with the goal tools. Turns with the run-state
+ // block see the goal there, current on every call, so it is not also
+ // prepended to the user's message.
let active_goal = if turn.overrides.suppress_active_goal {
None
} else {
- let loaded = crate::agent::goals::runtime::load_for_thread(
+ crate::agent::goals::runtime::load_for_thread(
&self.workspace_dir,
self.thread_id.as_deref(),
)
- .await;
- match loaded {
- Some(goal) if matches!(goal.status, ThreadGoalStatus::Paused) => {
- crate::agent::goals::runtime::resume_for_thread(
- &self.workspace_dir,
- self.thread_id.as_deref(),
- )
- .await
- .unwrap_or(Some(goal))
- }
- other => other,
- }
+ .await
};
+ let state_block_shows_goal =
+ crate::agent::tinyagents::state_block::applies(false, Some(&self.agent_definition_id));
if let Some(goal) = &active_goal {
- if let Some(block) = tinyagents_harness_tools::goals::active_goal_context_block(goal) {
- context.push_str(&block);
+ if !state_block_shows_goal {
+ if let Some(block) =
+ tinyagents_harness_tools::goals::active_goal_context_block(goal)
+ {
+ context.push_str(&block);
+ }
}
if let Some(hook) = tinyagents_hooks::stop::GoalBudgetStopHook::for_goal(
crate::storage::sessions::stores_or_ephemeral(&self.workspace_dir).kv,
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session_goal_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_session_goal_tests.rs
new file mode 100644
index 0000000000..fca44b6898
--- /dev/null
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_goal_tests.rs
@@ -0,0 +1,101 @@
+//! The turn start and the thread goal: a paused goal stays paused, and a turn
+//! that gets the run-state block does not also carry the goal in its message.
+
+use super::*;
+
+use tinyagents_harness_tools::goals::store as goal_store;
+use tinyagents_harness_tools::goals::ThreadGoalStatus;
+
+const THREAD: &str = "goal-thread";
+
+/// A session for `agent_id` bound to [`THREAD`], with its runtime session up.
+fn host_for(agent_id: &str) -> (crate::agent::OpenHumanSessionHost, tempfile::TempDir) {
+ let _ = crate::agent_registry::host_definition::AgentDefinitionRegistry::init_global_builtins();
+ let tmp = tempfile::TempDir::new().unwrap();
+ let config = crate::config::Config {
+ workspace_dir: tmp.path().join("workspace"),
+ action_dir: tmp.path().join("workspace"),
+ config_path: tmp.path().join("config.toml"),
+ ..crate::config::Config::default()
+ };
+ std::fs::create_dir_all(&config.workspace_dir).unwrap();
+ let definition = crate::agent_registry::agents::load_builtins()
+ .unwrap()
+ .into_iter()
+ .find(|def| def.id == agent_id)
+ .expect("builtin definition");
+ let mut host = OpenHumanSessionHost::from_config_with_definition(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ &definition,
+ )
+ .expect("session builds");
+ host.set_thread_id(Some(THREAD));
+ host.ensure_runtime_session().expect("runtime session");
+ (host, tmp)
+}
+
+fn store(tmp: &tempfile::TempDir) -> Arc<dyn tinyagents_harness::store::Store> {
+ crate::storage::sessions::stores_or_ephemeral(&tmp.path().join("workspace")).kv
+}
+
+/// The user message the turn start builds for `host`.
+async fn enriched(host: &crate::agent::OpenHumanSessionHost) -> String {
+ let prelude = host
+ .runtime_state
+ .lock()
+ .unwrap_or_else(|poisoned| poisoned.into_inner())
+ .prelude
+ .clone()
+ .expect("prelude");
+ let mut run_context = OpenHumanRunContext::new();
+ prelude
+ .enrich_request(
+ "what's the weather?",
+ &crate::agent::session_host::types::TurnInputs::default(),
+ &mut run_context,
+ )
+ .await
+}
+
+#[tokio::test]
+async fn a_paused_goal_is_not_resumed_by_a_new_message() {
+ let (host, tmp) = host_for("orchestrator");
+ let store = store(&tmp);
+ goal_store::set(&store, THREAD, "Migrate the auth schema", None)
+ .await
+ .unwrap();
+ goal_store::pause(&store, THREAD).await.unwrap();
+
+ let message = enriched(&host).await;
+
+ assert!(!message.contains("Migrate the auth schema"), "{message}");
+ let goal = goal_store::get(&store, THREAD).await.unwrap().unwrap();
+ assert_eq!(goal.status, ThreadGoalStatus::Paused);
+}
+
+#[tokio::test]
+async fn an_orchestrator_turn_leaves_the_goal_to_the_state_block() {
+ let (host, tmp) = host_for("orchestrator");
+ goal_store::set(&store(&tmp), THREAD, "Migrate the auth schema", None)
+ .await
+ .unwrap();
+ let message = enriched(&host).await;
+ assert!(
+ !message.contains("Migrate the auth schema"),
+ "the run-state block shows it: {message}"
+ );
+}
+
+#[tokio::test]
+async fn a_turn_without_the_state_block_still_carries_the_active_goal() {
+ let (host, tmp) = host_for("planner");
+ goal_store::set(&store(&tmp), THREAD, "Migrate the auth schema", None)
+ .await
+ .unwrap();
+ let message = enriched(&host).await;
+ assert!(
+ message.contains("[thread goal]") && message.contains("Migrate the auth schema"),
+ "{message}"
+ );
+}
diff --git a/crates/openhuman-core/src/agent/tinyagents/mod.rs b/crates/openhuman-core/src/agent/tinyagents/mod.rs
index a74eade563..95790580f4 100644
--- a/crates/openhuman-core/src/agent/tinyagents/mod.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/mod.rs
@@ -47,6 +47,7 @@ pub mod budget;
pub mod payload_summarizer;
mod policy_denial;
pub(crate) mod reaper;
+pub(crate) mod state_block;
mod steering_forwarder;
mod supplemental_trace;
pub(crate) mod thread_reasoning;
diff --git a/crates/openhuman-core/src/agent/tinyagents/state_block.rs b/crates/openhuman-core/src/agent/tinyagents/state_block.rs
new file mode 100644
index 0000000000..1112dc9a71
--- /dev/null
+++ b/crates/openhuman-core/src/agent/tinyagents/state_block.rs
@@ -0,0 +1,48 @@
+//! The run-state block for OpenHuman turns.
+//!
+//! TinyAgents' [`StateBlockMiddleware`] adds one block to every model request
+//! of the turn: the thread goal, the `todo` plan and facts derived from the
+//! turn's own tool calls. It is request-only (never on the transcript) and
+//! emits no events, so the UI keeps showing only the goal chip.
+//!
+//! It is installed on root orchestrator turns, the scope of the requirements
+//! check. On those turns the turn start does not prepend the goal to the user's
+//! message (`session_host::runtime_session::prelude`): the block shows the goal
+//! once, current on every call, and a paused goal comes with the choice to
+//! resume it, replace it or leave it, which the model makes with the goal
+//! tools after reading the message.
+
+use std::sync::Arc;
+
+use tinyagents_harness::runtime::AgentHarness;
+use tinyagents_harness::store::Store;
+use tinyagents_harness_tools::state_block::StateBlockMiddleware;
+
+/// Whether a turn gets the run-state block.
+pub(crate) fn applies(is_subagent: bool, agent_definition_id: Option<&str>) -> bool {
+ super::verify_before_finish::applies(is_subagent, agent_definition_id)
+}
+
+/// Installs the block for a turn in scope that has the session store the goal
+/// and `todo` tools write.
+pub(super) fn install<C: Send + Sync + 'static>(
+ harness: &mut AgentHarness<(), C>,
+ store: Option<Arc<dyn Store>>,
+ is_subagent: bool,
+ agent_definition_id: Option<&str>,
+) {
+ match store {
+ Some(store) if applies(is_subagent, agent_definition_id) => {
+ harness.push_middleware(Arc::new(StateBlockMiddleware::new(store)));
+ }
+ _ => tracing::debug!(
+ is_subagent,
+ agent = agent_definition_id.unwrap_or("<none>"),
+ "[state_block] not installed for this turn"
+ ),
+ }
+}
+
+#[cfg(test)]
+#[path = "state_block_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/agent/tinyagents/state_block_tests.rs b/crates/openhuman-core/src/agent/tinyagents/state_block_tests.rs
new file mode 100644
index 0000000000..777611c635
--- /dev/null
+++ b/crates/openhuman-core/src/agent/tinyagents/state_block_tests.rs
@@ -0,0 +1,32 @@
+use super::*;
+
+use tinyagents_harness::store::InMemoryStore;
+
+#[test]
+fn only_root_orchestrator_turns_get_the_block() {
+ assert!(applies(false, Some("orchestrator")));
+ assert!(!applies(true, Some("orchestrator")), "a sub-agent run");
+ assert!(!applies(false, Some("planner")));
+ assert!(!applies(false, None));
+}
+
+#[test]
+fn install_needs_the_scope_and_a_store() {
+ let store: Arc<dyn Store> = Arc::new(InMemoryStore::default());
+ let installed = |store: Option<Arc<dyn Store>>, is_subagent: bool, agent: Option<&str>| {
+ let mut harness = AgentHarness::<(), ()>::new();
+ let before = harness.middleware().len();
+ install(&mut harness, store, is_subagent, agent);
+ harness.middleware().len() - before
+ };
+ assert_eq!(
+ installed(Some(store.clone()), false, Some("orchestrator")),
+ 1
+ );
+ assert_eq!(installed(None, false, Some("orchestrator")), 0);
+ assert_eq!(
+ installed(Some(store.clone()), true, Some("orchestrator")),
+ 0
+ );
+ assert_eq!(installed(Some(store), false, Some("planner")), 0);
+}
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
index 0e7b5bf749..1f18904381 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
@@ -586,6 +586,9 @@ async fn drive_turn(
let bridge = bridge.clone();
Arc::new(move || bridge.announce_compaction())
}),
+ state_store: run_context.parent.as_ref().map(|parent| {
+ crate::storage::sessions::stores_or_ephemeral(&parent.workspace_dir).kv
+ }),
},
);
if let Some(scope) = run_context.response_shape.clone() {
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs b/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs
index 13834a7e63..d124e84845 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs
@@ -105,6 +105,9 @@ pub(super) struct TurnMiddlewareInputs {
/// Called when the turn starts summarizing earlier conversation, so the
/// client can show it. `None` for a turn nobody watches.
pub(super) compaction_notice: Option<super::context_wiring::CompactionNotice>,
+ /// The session store the goal and `todo` tools write, whether or not this
+ /// turn has the `todo` tool; the run-state block reads it.
+ pub(super) state_store: Option<Arc<dyn tinyagents_harness::store::Store>>,
}
/// The handles the run loop reads after the drive returns.
@@ -157,6 +160,7 @@ pub(super) fn install_turn_middleware(
tool_outcome_sink,
todo_store,
compaction_notice,
+ state_store,
} = inputs;
let super::host::HarnessHostPolicy {
stop_hooks,
@@ -517,6 +521,10 @@ pub(super) fn install_turn_middleware(
"[todo_sequence] not installed for this turn"
),
}
+ // The goal, the plan and the turn's tool-call facts on every model call,
+ // request-only. On these turns the goal is not prepended to the user's
+ // message (see `state_block`).
+ super::state_block::install(harness, state_store, is_subagent, agent_id);
// Direct web lookup is bounded. Once enough search/fetch results have
// returned, the web tools leave the request so the run works with what it
diff --git a/crates/openhuman-core/src/agent_registry/agents/orchestrator/agent.toml b/crates/openhuman-core/src/agent_registry/agents/orchestrator/agent.toml
index 869c0705fb..0d5b471aed 100644
--- a/crates/openhuman-core/src/agent_registry/agents/orchestrator/agent.toml
+++ b/crates/openhuman-core/src/agent_registry/agents/orchestrator/agent.toml
@@ -337,6 +337,9 @@ named = [
"goal_set",
"goal_get",
"goal_complete",
+ # Resumes a paused goal when the user's message continues it; the turn
+ # start no longer resumes one on any message.
+ "goal_resume",
# Workflow composition. `run_workflow` runs another workflow as a
# subagent and (by default) waits on its result like a function call;
# `await_workflow` re-attaches to a run that outlived its inline wait.