Skip to content

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

feat(tinyagents): expose task recency window via run host extension

Steven Enamakel807c8ffded7e
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 ac7dee62f9..21911c2c9a 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -396,6 +396,37 @@ pub(crate) fn sandbox_mode_for_tool(
.and_then(|host| host.sandbox_mode)
}
+/// OpenHuman product values that tools read from the run through
+/// `ToolExecutionContext::host::<OpenHumanRunExt>()`, installed by
+/// [`OpenHumanRunContext::into_tinyagents`] with `RunContext::with_host`.
+/// It replaces the former per-value task-locals, which do not cross a module
+/// boundary.
+#[derive(Debug, Clone, Default, PartialEq, Eq)]
+pub struct OpenHumanRunExt {
+ /// Recency window narrowing integration task-fetch tools (morning
+ /// briefing only); `None` leaves them unbounded.
+ pub task_recency_window: Option<Duration>,
+}
+
+/// Reads the run's task-recency window from the explicit tool carrier.
+/// Direct tool dispatch (CLI, JSON-RPC, tests) has none.
+pub(crate) fn task_recency_window_for_tool(
+ context: Option<&dyn tinytools::ToolRunContext>,
+) -> Option<Duration> {
+ let window = context
+ .and_then(tinytools::ToolRunContext::host_extension)
+ .and_then(|extension| {
+ extension.downcast_ref::<tinyagents_harness::tool::ToolExecutionContext>()
+ })
+ .and_then(|context| context.host::<OpenHumanRunExt>())
+ .and_then(|ext| ext.task_recency_window);
+ tracing::trace!(
+ has_window = window.is_some(),
+ "[composio][task-window] read run window"
+ );
+ window
+}
+
impl Default for OpenHumanRunContext {
fn default() -> Self {
Self::new()
@@ -575,13 +606,17 @@ impl OpenHumanRunContext {
}
let cancellation = self.cancellation.clone();
let workspace = self.workspace.clone();
+ let run_ext = OpenHumanRunExt {
+ task_recency_window: self.task_recency_window,
+ };
let host_operations = Arc::new(HostOperationContext {
origin: self.origin.clone(),
sandbox_mode: self.sandbox_mode,
});
let context = tinyagents_harness::context::RunContext::new(config, self)
.with_cancellation(cancellation)
- .with_state_view(host_operations);
+ .with_state_view(host_operations)
+ .with_host(run_ext);
match workspace {
Some(workspace) => context.with_workspace(workspace),
None => context,