Skip to content

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

refactor(session): update goal handling and state management

Steven Enamakel70908d72f51c
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 bed289433c..22131c7fb6 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
@@ -220,30 +220,27 @@ impl OpenHumanTurnPrelude {
let active_goal = if turn.overrides.suppress_active_goal {
None
- } else {
- let loaded = 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))
+ } else if let Some(thread_id) = self.thread_id.as_deref() {
+ let store = crate::agent::goals::goal_store(&self.workspace_dir, &self.dispatch_ctx());
+ match store.prepare_turn(thread_id).await {
+ Ok(preparation) => {
+ if let Some(block) = preparation.context_block {
+ context.push_str(&block);
+ }
+ preparation.goal
+ }
+ Err(error) => {
+ tracing::debug!(thread_id, %error, "[thread_goals] prepare_turn failed");
+ None
}
- other => other,
}
+ } else {
+ None
};
if let Some(goal) = &active_goal {
- if let Some(block) = tinyagents_graph::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,
+ crate::agent::goals::goal_store(&self.workspace_dir, &self.dispatch_ctx())
+ .backing_store(),
goal,
) {
run_context.stop_hooks.push(Arc::new(hook));
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session_usage.rs b/crates/openhuman-core/src/agent/session_host/runtime_session_usage.rs
index a789333040..a97f98f5f3 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session_usage.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_usage.rs
@@ -38,15 +38,13 @@ pub(in crate::agent::session_host) async fn account_committed_turn_against_goal(
sidecar: &crate::agent::tinyagents::host::run_context::SessionTurnSidecar,
) {
let usage = rollup_usage(sidecar);
- crate::agent::goals::runtime::account_turn_against_goal(
+ crate::agent::goals::account_turn(
workspace_dir,
+ &crate::core::runtime::DispatchCtx::ambient(),
thread_id,
usage.input_tokens,
usage.output_tokens,
- sidecar
- .duration
- .map(|duration| duration.as_secs())
- .unwrap_or_default(),
+ sidecar.duration.unwrap_or_default(),
)
.await;
}
diff --git a/crates/openhuman-core/src/threads/ops/live_state.rs b/crates/openhuman-core/src/threads/ops/live_state.rs
index 751985c96c..69d40ae117 100644
--- a/crates/openhuman-core/src/threads/ops/live_state.rs
+++ b/crates/openhuman-core/src/threads/ops/live_state.rs
@@ -7,7 +7,7 @@
//! that already had one in flight.
use super::support::{envelope, workspace_dir};
-use crate::agent::goals::goal_to_value;
+use crate::agent::goals::{goal_store, goal_to_value};
use crate::core::Outcome;
use crate::threads::ApiEnvelope;
@@ -30,7 +30,7 @@ pub struct ThreadGoalGetResponse {
/// thread has never written one.
#[derive(Debug, Clone, serde::Serialize)]
pub struct ThreadTodosGetResponse {
- pub todos: Vec<tinyagents_graph::todos::TodoItem>,
+ pub todos: Vec<tinyagents_harness_tools::todos::TodoItem>,
}
/// `threads.goal_get` — read a thread's current goal without waiting for the
@@ -44,10 +44,14 @@ pub async fn goal_get(
if thread_id.is_empty() {
return Err("thread_id is required".to_string());
}
- let goal = crate::agent::goals::runtime::load_for_thread(&dir, Some(thread_id))
- .await
- .as_ref()
- .map(goal_to_value);
+ let context = crate::core::runtime::DispatchCtx::ambient();
+ let goal = match goal_store(&dir, &context).get(thread_id).await {
+ Ok(goal) => goal.as_ref().map(goal_to_value),
+ Err(error) => {
+ log::debug!("[threads] goal_get thread_id={thread_id} failed: {error}");
+ None
+ }
+ };
Ok(envelope(ThreadGoalGetResponse { goal }, None, None))
}
@@ -62,7 +66,7 @@ pub async fn todos_get(
return Err("thread_id is required".to_string());
}
let store = crate::storage::sessions::stores_or_ephemeral(&dir).kv;
- let todos = match tinyagents_graph::todos::store::list(&store, thread_id).await {
+ let todos = match tinyagents_harness_tools::todos::store::list(&store, thread_id).await {
Ok(snapshot) => snapshot.items,
Err(e) => {
log::debug!("[threads] todos_get thread_id={thread_id} list failed: {e}");