Skip to content

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

fix(agent): a thread-less turn finds its plan under the session id

sanil-2371db7db55dcf
diff --git a/crates/openhuman-core/src/agent/tinyagents/state_block.rs b/crates/openhuman-core/src/agent/tinyagents/state_block.rs
index 1112dc9a71..6652102323 100644
--- a/crates/openhuman-core/src/agent/tinyagents/state_block.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/state_block.rs
@@ -24,16 +24,19 @@ pub(crate) fn applies(is_subagent: bool, agent_definition_id: Option<&str>) -> b
}
/// Installs the block for a turn in scope that has the session store the goal
-/// and `todo` tools write.
+/// and `todo` tools write, with the key the `todo` tool falls back to when the
+/// turn has no thread (the session id).
pub(super) fn install<C: Send + Sync + 'static>(
harness: &mut AgentHarness<(), C>,
- store: Option<Arc<dyn Store>>,
+ source: Option<(Arc<dyn Store>, String)>,
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)));
+ 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),
+ ));
}
_ => tracing::debug!(
is_subagent,
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 777611c635..b03603adcb 100644
--- a/crates/openhuman-core/src/agent/tinyagents/state_block_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/state_block_tests.rs
@@ -16,7 +16,12 @@ fn install_needs_the_scope_and_a_store() {
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);
+ install(
+ &mut harness,
+ store.map(|store| (store, "standalone".to_string())),
+ is_subagent,
+ agent,
+ );
harness.middleware().len() - before
};
assert_eq!(
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
index 1f18904381..6f20a53d30 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
@@ -587,7 +587,10 @@ async fn drive_turn(
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
+ (
+ crate::storage::sessions::stores_or_ephemeral(&parent.workspace_dir).kv,
+ parent.session_id.clone(),
+ )
}),
},
);
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs b/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs
index d124e84845..f8c8d6423d 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs
@@ -107,7 +107,9 @@ pub(super) struct TurnMiddlewareInputs {
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>>,
+ /// With the scope the `todo` tool uses on a turn without a thread (the
+ /// session id), so a headless turn's block still finds its plan.
+ pub(super) state_store: Option<(Arc<dyn tinyagents_harness::store::Store>, String)>,
}
/// The handles the run loop reads after the drive returns.
@@ -511,9 +513,14 @@ pub(super) fn install_turn_middleware(
// it so its `after_model` runs first and the plan check comes first.
match todo_store {
Some(store) if verify_before_finish::applies(is_subagent, agent_id) => {
- harness.push_middleware(Arc::new(
- tinyagents_harness_tools::todos::TodoSequenceMiddleware::new(store),
- ));
+ // A thread-less turn's plan sits under the session id (the `todo`
+ // tool's fallback scope); without the same key these rules never
+ // see it.
+ let mut sequence = tinyagents_harness_tools::todos::TodoSequenceMiddleware::new(store);
+ if let Some((_, fallback_thread)) = &state_store {
+ sequence = sequence.with_fallback_thread(fallback_thread.clone());
+ }
+ harness.push_middleware(Arc::new(sequence));
}
_ => tracing::debug!(
is_subagent,