Skip to content

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

refactor(session_host): split runtime accessors into their own module

Steven Enamakelb074f8d0c817
diff --git a/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs b/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs
index d0d1ebf413..263b4d2913 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs
@@ -558,6 +558,19 @@ impl OpenHumanSessionHost {
.pending_turn_overrides = overrides;
}
+ /// Ask the **next** turn to shape every model call (response format,
+ /// output cap) and report its final call into `scope`. Consumed at the
+ /// start of that turn, like [`Self::set_next_turn_overrides`].
+ pub fn set_next_turn_response_shape(
+ &mut self,
+ scope: Option<Arc<tinyagents_harness::middleware::ResponseShapeScope>>,
+ ) {
+ self.runtime_state
+ .lock()
+ .unwrap_or_else(|poisoned| poisoned.into_inner())
+ .pending_response_shape = scope;
+ }
+
/// Set the reply-language instruction every following user message
/// carries (next to the `Current Date & Time` line), or clear it with
/// `None`. Sent per message rather than baked into the system prompt, so
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 38e47fe427..1f0eacda9a 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -55,6 +55,9 @@ pub(super) struct OpenHumanSessionState {
required_output: Option<tinyagents_harness::config::RequiredOutput>,
pub(crate) pending_turn_overrides: super::types::TurnOverrides,
pub(super) active_turn_overrides: super::types::TurnOverrides,
+ /// The next turn's response shape (consumed at its start).
+ pub(crate) pending_response_shape:
+ Option<Arc<tinyagents_harness::middleware::ResponseShapeScope>>,
pub(super) reply_language_directive: Option<String>,
pub(super) time_zone: Option<String>,
prelude: Option<OpenHumanTurnPrelude>,
@@ -482,6 +485,7 @@ impl OpenHumanTurnPrelude {
.unwrap_or_else(std::sync::PoisonError::into_inner);
mutable.last_memory_context = (!context.is_empty()).then_some(context);
}
+ run_context.response_shape = turn.response_shape.clone();
run_context.attach_parent(self.parent_context());
self.apply_pending_announcements(&mut enriched);
diff --git a/crates/openhuman-core/src/agent/session_host/types.rs b/crates/openhuman-core/src/agent/session_host/types.rs
index a5ffba7868..7752bbdfd6 100644
--- a/crates/openhuman-core/src/agent/session_host/types.rs
+++ b/crates/openhuman-core/src/agent/session_host/types.rs
@@ -61,6 +61,7 @@ pub struct TurnOverrides {
#[derive(Debug, Default)]
pub(crate) struct TurnInputs {
pub(crate) overrides: TurnOverrides,
+ pub(crate) response_shape: Option<Arc<tinyagents_harness::middleware::ResponseShapeScope>>,
pub(crate) reply_language_directive: Option<String>,
pub(crate) time_zone: Option<String>,
}
@@ -82,6 +83,7 @@ impl super::runtime_session::OpenHumanSessionState {
pub(super) fn take_turn_inputs(&mut self) -> TurnInputs {
TurnInputs {
overrides: std::mem::take(&mut self.active_turn_overrides),
+ response_shape: self.pending_response_shape.take(),
reply_language_directive: self.reply_language_directive.clone(),
time_zone: self.time_zone.clone(),
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
index bd981a166c..3b6106e630 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -272,6 +272,11 @@ impl TurnDispatchState {
pub struct OpenHumanRunContext {
/// Explicit shared model-call budget inherited by synchronous children.
pub model_budget: Option<super::super::budget::ModelBudget>,
+ /// The response format and output cap this root turn asks of every model
+ /// call, and the slot its final call is reported into. Carried explicitly
+ /// from the caller (`agent_chat`) through the session; children never
+ /// inherit it.
+ pub response_shape: Option<Arc<tinyagents_harness::middleware::ResponseShapeScope>>,
/// A host can narrow synchronous delegation depth; children inherit this.
pub max_spawn_depth: Option<usize>,
/// Trust/routing source used by OpenHuman approval and attribution policy.
@@ -439,6 +444,7 @@ impl OpenHumanRunContext {
pub fn new() -> Self {
Self {
model_budget: super::super::budget::current(),
+ response_shape: None,
max_spawn_depth: super::super::budget::spawn_depth_limit(),
origin: None,
progress: None,
@@ -563,6 +569,7 @@ impl OpenHumanRunContext {
child.subagent_usage = Arc::new(Mutex::new(Vec::new()));
child.resolved_route = Arc::new(Mutex::new(None));
child.memory_turn = None;
+ child.response_shape = None;
child
}