Skip to content

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

feat(agent): a turn that suppresses the thread goal keeps the plan in its run-state block

sanil-23c5df83aa5bcc
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
index 642028aef6..98dcab50b7 100644
--- 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
@@ -108,7 +108,7 @@ async fn a_turn_without_the_state_block_still_carries_the_active_goal() {
}
/// A turn that suppresses the thread goal tells the run context, so the
-/// run-state block (which reads the goal from the store) stays off that turn.
+/// run-state block (which reads the goal from the store) leaves the goal out.
#[tokio::test]
async fn a_suppressed_goal_reaches_the_run_context() {
let (host, tmp) = host_for("orchestrator");
diff --git a/crates/openhuman-core/src/agent/tinyagents/state_block.rs b/crates/openhuman-core/src/agent/tinyagents/state_block.rs
index a4eb9ade1c..bf6ee1affe 100644
--- a/crates/openhuman-core/src/agent/tinyagents/state_block.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/state_block.rs
@@ -37,9 +37,8 @@ pub(crate) fn applies(is_subagent: bool, agent_definition_id: Option<&str>) -> b
///
/// A turn that suppresses the thread goal (`goal_suppressed`, from
/// `TurnOverrides::suppress_active_goal`: a conversational reply, a flow or a
-/// cron run) gets no block: the block reads the goal from the store, and the
-/// goal must not reach that turn. Until TinyAgents' `hide_goal` is pinned, the
-/// plan and notes are left out with it, as on a turn without the block.
+/// cron run) still gets the block, without the goal: the plan, the agent's
+/// notes and the turn's facts show, and the goal does not reach that turn.
pub(super) fn install<C: Send + Sync + 'static>(
harness: &mut AgentHarness<(), C>,
source: Option<(Arc<dyn Store>, String)>,
@@ -47,18 +46,19 @@ pub(super) fn install<C: Send + Sync + 'static>(
agent_definition_id: Option<&str>,
goal_suppressed: bool,
) {
- if goal_suppressed {
- tracing::debug!(
- agent = agent_definition_id.unwrap_or("<none>"),
- "[state_block] not installed: this turn suppresses the thread goal"
- );
- return;
- }
match source {
Some((store, fallback_thread)) if applies(is_subagent, agent_definition_id) => {
- harness.push_middleware(Arc::new(
- StateBlockMiddleware::new(store).with_fallback_thread(fallback_thread),
- ));
+ if goal_suppressed {
+ tracing::debug!(
+ agent = agent_definition_id.unwrap_or("<none>"),
+ "[state_block] installed without the goal: this turn suppresses it"
+ );
+ }
+ harness.push_middleware(Arc::new(middleware(
+ store,
+ fallback_thread,
+ goal_suppressed,
+ )));
}
_ => tracing::debug!(
is_subagent,
@@ -68,6 +68,18 @@ pub(super) fn install<C: Send + Sync + 'static>(
}
}
+/// The block for one turn: the session store, the thread-less fallback key,
+/// and the goal left out when the turn suppresses it.
+fn middleware(
+ store: Arc<dyn Store>,
+ fallback_thread: String,
+ goal_suppressed: bool,
+) -> StateBlockMiddleware {
+ StateBlockMiddleware::new(store)
+ .with_fallback_thread(fallback_thread)
+ .hide_goal(goal_suppressed)
+}
+
/// A plan that finished this turn, with what it was for.
pub(crate) struct FinishedPlan {
/// The plan with its notes.
diff --git a/crates/openhuman-core/src/agent/tinyagents/state_block_tests.rs b/crates/openhuman-core/src/agent/tinyagents/state_block_tests.rs
index 3254e9ce5f..a665c6c4ec 100644
--- a/crates/openhuman-core/src/agent/tinyagents/state_block_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/state_block_tests.rs
@@ -37,25 +37,66 @@ fn install_needs_the_scope_and_a_store() {
assert_eq!(installed(Some(store), false, Some("planner")), 0);
}
-/// A turn that suppresses the thread goal (`suppress_active_goal`) gets no
-/// block: the block would show the goal it must not see.
-#[test]
-fn a_turn_that_suppresses_the_goal_gets_no_block() {
+/// A turn that suppresses the thread goal (`suppress_active_goal`) still gets
+/// the block, without the goal: the plan shows and the goal does not.
+#[tokio::test]
+async fn a_turn_that_suppresses_the_goal_sees_the_plan_but_not_the_goal() {
+ use tinyagents_harness::context::{RunConfig, RunContext};
+ use tinyagents_harness::middleware::Middleware;
+ use tinyagents_harness_tools::goals::store as goal_store;
+ use tinyagents_harness_tools::todos::{store as todo_store, TodoItem};
+ use tinyinference_llm::message::Message;
+ use tinyinference_llm::model::ModelRequest;
+
let store: Arc<dyn Store> = Arc::new(InMemoryStore::default());
- let installed = |goal_suppressed: bool| {
- let mut harness = AgentHarness::<(), ()>::new();
- let before = harness.middleware().len();
- install(
- &mut harness,
- Some((store.clone(), "standalone".to_string())),
- false,
- Some("orchestrator"),
- goal_suppressed,
- );
- harness.middleware().len() - before
+ goal_store::set(&store, "t", "Migrate the billing tables", None)
+ .await
+ .unwrap();
+ todo_store::replace(&store, "t", vec![TodoItem::new("Dump the schema")])
+ .await
+ .unwrap();
+ let block = |goal_suppressed: bool| {
+ let block_mw = middleware(store.clone(), "standalone".to_string(), goal_suppressed);
+ async move {
+ let mut ctx = RunContext::new(RunConfig::new("state-block").with_thread("t"), ());
+ let mut request = ModelRequest {
+ messages: vec![Message::system("persona"), Message::user("hey")],
+ ..Default::default()
+ };
+ Middleware::<(), ()>::before_model_dispatch(&block_mw, &mut ctx, &(), &mut request)
+ .await
+ .unwrap();
+ request
+ .messages
+ .iter()
+ .map(Message::text)
+ .collect::<Vec<_>>()
+ .join("\n")
+ }
};
- assert_eq!(installed(false), 1);
- assert_eq!(installed(true), 0);
+
+ let shown = block(false).await;
+ assert!(shown.contains("Migrate the billing tables"), "{shown}");
+ assert!(shown.contains("Dump the schema"), "{shown}");
+
+ let suppressed = block(true).await;
+ assert!(
+ !suppressed.contains("Migrate the billing tables"),
+ "{suppressed}"
+ );
+ assert!(suppressed.contains("Dump the schema"), "{suppressed}");
+
+ // And the turn still installs it.
+ let mut harness = AgentHarness::<(), ()>::new();
+ let before = harness.middleware().len();
+ install(
+ &mut harness,
+ Some((store, "standalone".to_string())),
+ false,
+ Some("orchestrator"),
+ true,
+ );
+ assert_eq!(harness.middleware().len() - before, 1);
}
#[tokio::test]