Skip to content

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

refactor(agent): drop per-agent turn graph hook

Steven Enamakel5213740d385d
diff --git a/crates/openhuman-core/src/agent/harness/agent_graph.rs b/crates/openhuman-core/src/agent/harness/agent_graph.rs
deleted file mode 100644
index 967517312a..0000000000
--- a/crates/openhuman-core/src/agent/harness/agent_graph.rs
+++ /dev/null
@@ -1,150 +0,0 @@
-//! Per-agent turn-graph selection (issue #4249).
-//!
-//! Built-in agents with bespoke turn graphs ship a `graph.rs` exporting
-//! `pub fn graph() -> AgentGraph`, mirroring the per-agent `prompt.rs::build`
-//! hook. Default agents omit that module and the registry loader leaves
-//! [`AgentDefinition::graph`] at [`AgentGraph::Default`]. The sub-agent turn
-//! chokepoint (`run_typed_mode`) consults the resolved value:
-//!
-//! - [`AgentGraph::Default`] runs the shared default sub-agent turn graph
-//! (`subagent_host::ops::graph::run_subagent_via_graph`).
-//! - [`AgentGraph::Custom`] hands the assembled turn to the agent's own graph
-//! runner — a bespoke tinyagents graph, thin over
-//! `run_turn_via_tinyagents_shared`.
-//!
-//! Today every built-in agent selects `Default`. The optional hook is the
-//! extension point that lets a specialized agent (orchestrator, planner, …)
-//! define a bespoke graph without branching the shared runner.
-
-use std::collections::HashSet;
-use std::future::Future;
-use std::path::PathBuf;
-use std::pin::Pin;
-use std::sync::Arc;
-
-use tinytools::WorkspaceDescriptor;
-use tokio::sync::mpsc::Sender;
-
-use crate::agent::progress::AgentProgress;
-use crate::agent::subagent_host::SubagentRunError;
-use crate::agent::tinyagents::TurnModelSource;
-use tinyagents_harness::run_queue::RunQueue;
-use tinyagents_session::transcript::TranscriptMessage;
-use tinytools::{Tool, ToolSpec};
-
-/// The assembled inputs for one sub-agent turn, handed to a custom
-/// [`AgentGraph::Custom`] runner.
-///
-/// Owned (history + tools by value) so the runner can be a boxed `'static`
-/// future without borrowing the caller's stack — mirrors the positional
-/// arguments the default `run_subagent_via_graph` takes.
-pub struct AgentTurnRequest {
- /// The turn's model source — builds the sub-agent's tiered crate `ChatModel`
- /// set (issue #4249, Phase 3 / Motion A). Replaces the raw `Arc<dyn Provider>`.
- pub turn_model_source: TurnModelSource,
- pub model: String,
- pub temperature: f64,
- /// Full working transcript for the turn (system + prior + this user turn).
- pub history: Vec<TranscriptMessage>,
- pub parent_tools: Arc<Vec<Box<dyn Tool>>>,
- pub dynamic_tools: Vec<Box<dyn Tool>>,
- pub specs: Vec<ToolSpec>,
- pub allowed_names: HashSet<String>,
- pub max_iterations: usize,
- pub run_queue: Option<Arc<RunQueue<crate::agent::queued_turn::QueuedTurn>>>,
- pub on_progress: Option<Sender<AgentProgress>>,
- pub agent_id: String,
- pub task_id: String,
- pub extended_policy: bool,
- /// Explicit caller/worker thread propagated from the originating tool.
- pub thread_id: Option<String>,
- /// Explicit host carrier inherited by the recursive child run.
- pub run_context: crate::agent::tinyagents::host::OpenHumanRunContext,
- pub worker_thread_id: Option<String>,
- pub workspace_dir: PathBuf,
- pub workspace_descriptor: Option<WorkspaceDescriptor>,
- pub max_output_tokens: u32,
- pub model_vision: bool,
- pub transcript_stem: String,
- pub provider_label: String,
- /// Agent-level TokenJuice compaction profile
- /// (`definition.effective_tokenjuice_compression()`), threaded into the
- /// sub-agent `TurnContextMiddleware` so tool outputs compact like the chat
- /// path instead of taking a blunt byte-cap truncation (#4466).
- pub tokenjuice_compression: crate::inference::tokenjuice::AgentTokenjuiceCompression,
- /// The spawn's host-config snapshot, supplying the `[context]` middleware
- /// knobs (compaction, microcompact, autocompact, tool-result budget).
- ///
- /// Carried on the request rather than loaded down in the graph
- /// (plan-agents Phase 3): the graph is slated to move into TinyAgents,
- /// which has no config file. `None` yields the safe byte-cap-only
- /// defaults — the same degradation a failed load produced before.
- pub config: Option<Arc<crate::config::Config>>,
-}
-
-/// Token/cost totals a custom runner reports back. Mirrors the runner's internal
-/// `AggregatedUsage` without coupling to its (private) type.
-#[derive(Debug, Clone, Copy, Default)]
-pub struct AgentTurnUsage {
- pub input_tokens: u64,
- pub output_tokens: u64,
- pub cached_input_tokens: u64,
- pub charged_amount_usd: f64,
-}
-
-/// The result of a custom turn graph. `history` is the full updated transcript
-/// (the runner persists it back and mirrors it to any worker thread).
-pub struct AgentTurnResult {
- pub history: Vec<TranscriptMessage>,
- pub output: String,
- pub iterations: usize,
- pub usage: AgentTurnUsage,
- /// Set when an early-exit tool (e.g. `ask_user_clarification`) paused the run.
- pub early_exit_tool: Option<String>,
- /// `true` when the run stopped at the model-call cap with work still pending.
- pub hit_cap: bool,
- /// Set (with the halt reason) when the repeated-failure / repeat-progress
- /// circuit breaker halted the run; the runner reports `Incomplete` (#4466).
- pub breaker_halt: Option<String>,
-}
-
-/// A per-agent custom turn-graph runner: given the assembled [`AgentTurnRequest`],
-/// drive a bespoke tinyagents graph and return the [`AgentTurnResult`].
-pub type AgentGraphRunner =
- fn(
- AgentTurnRequest,
- ) -> Pin<Box<dyn Future<Output = Result<AgentTurnResult, SubagentRunError>> + Send>>;
-
-/// How an agent's turn is driven. Selected per-agent via each folder's
-/// `graph.rs::graph()` and injected onto [`AgentDefinition`][super::definition::AgentDefinition].
-#[derive(Clone, Default)]
-pub enum AgentGraph {
- /// Run the shared default sub-agent turn graph (`run_subagent_via_graph`).
- #[default]
- Default,
- /// Run this agent's bespoke graph.
- Custom(AgentGraphRunner),
-}
-
-impl AgentGraph {
- /// Build a custom graph selection from a runner fn. Sugar for
- /// [`AgentGraph::Custom`] so a folder's `graph.rs` reads
- /// `AgentGraph::custom(run)`.
- pub fn custom(run: AgentGraphRunner) -> Self {
- AgentGraph::Custom(run)
- }
-
- /// `true` when this agent uses the shared default graph.
- pub fn is_default(&self) -> bool {
- matches!(self, AgentGraph::Default)
- }
-}
-
-impl std::fmt::Debug for AgentGraph {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- match self {
- AgentGraph::Default => f.write_str("Default"),
- AgentGraph::Custom(_) => f.write_str("Custom(<fn>)"),
- }
- }
-}
diff --git a/crates/openhuman-core/src/agent/harness/definition/agent_definition.rs b/crates/openhuman-core/src/agent/harness/definition/agent_definition.rs
index c3e27dbbf7..201becc203 100644
--- a/crates/openhuman-core/src/agent/harness/definition/agent_definition.rs
+++ b/crates/openhuman-core/src/agent/harness/definition/agent_definition.rs
@@ -243,15 +243,6 @@ pub struct AgentDefinition {
/// Tracks where the definition was loaded from (Builtin vs. File).
#[serde(skip)]
pub source: DefinitionSource,
-
- // ── turn graph ──────────────────────────────────────────────────────
- /// How this agent's turn is driven (issue #4249). Injected post-load from
- /// the agent folder's `graph.rs::graph()` (mirrors how
- /// [`PromptSource::Dynamic`] is injected from `prompt.rs::build`); TOML-
- /// authored agents cannot set it, so it is `#[serde(skip)]` and defaults to
- /// [`AgentGraph::Default`] (the shared default turn graph).
- #[serde(skip, default)]
- pub graph: crate::agent::harness::agent_graph::AgentGraph,
}
impl AgentDefinition {
diff --git a/crates/openhuman-core/src/agent/harness/mod.rs b/crates/openhuman-core/src/agent/harness/mod.rs
index ad8fd46a2f..399f357104 100644
--- a/crates/openhuman-core/src/agent/harness/mod.rs
+++ b/crates/openhuman-core/src/agent/harness/mod.rs
@@ -20,7 +20,6 @@
//! Cancellation is handled by the tinyagents steering channel (see
//! `crate::agent::tinyagents`); there is no in-house interrupt fence.
-pub mod agent_graph;
pub mod artifact_offload;
pub(crate) mod builtin_definitions;
pub mod definition;
@@ -30,10 +29,8 @@ pub(crate) mod graph;
pub(crate) mod memory_context_safety;
pub mod sandbox_context;
pub(crate) mod spawn_depth_context;
-pub mod task_recency_context;
pub(crate) mod tool_result_artifacts;
-pub use agent_graph::{AgentGraph, AgentTurnRequest, AgentTurnResult, AgentTurnUsage};
// NOTE: deliberately no flat re-export here. `artifact_offload::ArtifactKind`
// would shadow the unrelated `openhuman::agent::artifacts::ArtifactKind` for anyone
// glob-importing this module; callers use the `artifact_offload::` path.
@@ -46,6 +43,5 @@ pub use fork_context::{
};
pub use sandbox_context::{current_sandbox_mode, with_current_sandbox_mode};
pub(crate) use spawn_depth_context::{with_spawn_depth, MAX_SPAWN_DEPTH};
-pub use task_recency_context::{current_task_recency_window, with_task_recency_window};
pub(crate) use graph::run_channel_turn_via_graph;
diff --git a/crates/openhuman-core/src/agent/registry/README.md b/crates/openhuman-core/src/agent/registry/README.md
index 358483342f..4c8d05562d 100644
--- a/crates/openhuman-core/src/agent/registry/README.md
+++ b/crates/openhuman-core/src/agent/registry/README.md
@@ -64,13 +64,11 @@ directly into `AgentDefinition`), a `prompt.md` holding the static archetype
body, and a `prompt.rs` that `include_str!`s that body and exposes
`pub fn build(&PromptContext) -> anyhow::Result<String>`, appending
runtime-dependent sections (rendered tool list, workspace) to it.
-Every archetype currently uses `AgentGraph::Default`; an archetype that needs a
-bespoke `AgentGraph` adds a `graph.rs` and sets `BuiltinAgent::graph_fn`. The per-archetype contract is
-documented on [`agents/mod.rs`](agents/mod.rs).
+Every archetype uses the shared sub-agent turn graph.
[`agents/loader.rs`](agents/loader.rs) owns the `BUILTINS` slice and
`load_builtins`, which parses each `agent.toml`, installs
-`PromptSource::Dynamic(prompt_fn)` and the optional graph, stamps
+`PromptSource::Dynamic(prompt_fn)`, stamps
`DefinitionSource::Builtin`, checks that the folder id matches the TOML id,
and then runs `validate_tier_hierarchy`: a `worker` may not list any agent-id
subagent, and `chat -> chat` / `reasoning -> reasoning` delegation is
diff --git a/crates/openhuman-core/src/agent/registry/agents/loader.rs b/crates/openhuman-core/src/agent/registry/agents/loader.rs
index 768aab63b0..06e840de56 100644
--- a/crates/openhuman-core/src/agent/registry/agents/loader.rs
+++ b/crates/openhuman-core/src/agent/registry/agents/loader.rs
@@ -9,8 +9,6 @@
//! -> anyhow::Result<String>` that returns the sub-agent's system
//! prompt body. Dynamic: may branch on available tools, user profile,
//! connected integrations, model hint, etc.
-//! * `graph.rs` — optional, only for agents with a bespoke
-//! [`AgentGraph`] runner. Agents without one use [`AgentGraph::Default`].
//!
//! Adding a new built-in agent = creating a new subfolder with the required
//! metadata/prompt files, declaring the module, and appending one entry to
@@ -22,7 +20,6 @@
//! 1. [`load_builtins`] walks [`BUILTINS`].
//! 2. For each entry, parses `agent.toml` into an [`AgentDefinition`].
//! 3. Replaces the (unset) `system_prompt` with `PromptSource::Dynamic(prompt_fn)`
-//! and installs the optional `graph_fn` result as the turn graph.
//! 4. Stamps `source = DefinitionSource::Builtin` and checks the folder id
//! matches the TOML `id`.
//! 5. Returns the full `Vec<AgentDefinition>`, in the order listed in [`BUILTINS`].
@@ -32,7 +29,6 @@
//! into the global registry, where they replace built-ins on `id`
//! collision.
-use crate::agent::harness::agent_graph::AgentGraph;
use crate::agent::harness::definition::{
validate_tier_transition, AgentDefinition, AgentTier, DefinitionSource, PromptBuilder,
PromptSource, SubagentEntry,
@@ -52,10 +48,6 @@ pub struct BuiltinAgent {
/// with a populated [`crate::agent::harness::definition::PromptContext`]
/// so the returned body can branch on runtime state.
pub prompt_fn: PromptBuilder,
- /// Optional turn-graph selector. `None` means [`AgentGraph::Default`].
- /// Bespoke agents expose a `graph.rs::graph()` returning
- /// [`AgentGraph::Custom`] and set this field to `Some(...)`.
- pub graph_fn: Option<fn() -> AgentGraph>,
}
/// Every built-in agent, in stable display order.
@@ -66,7 +58,6 @@ pub const BUILTINS: &[BuiltinAgent] = &[
id: "orchestrator",
toml: include_str!("orchestrator/agent.toml"),
prompt_fn: super::orchestrator::prompt::build,
- graph_fn: None,
},
// `planner` and `critic` are not delegable from chat (the orchestrator does
// not list them): they exist for the `parallel_research_cross_check`
@@ -78,67 +69,56 @@ pub const BUILTINS: &[BuiltinAgent] = &[
id: "planner",
toml: include_str!("planner/agent.toml"),
prompt_fn: super::planner::prompt::build,
- graph_fn: None,
},
BuiltinAgent {
id: "critic",
toml: include_str!("critic/agent.toml"),
prompt_fn: super::critic::prompt::build,
- graph_fn: None,
},
BuiltinAgent {
id: "task_manager_agent",
toml: include_str!("task_manager_agent/agent.toml"),
prompt_fn: super::task_manager_agent::prompt::build,
- graph_fn: None,
},
BuiltinAgent {
id: "presentation_agent",
toml: include_str!("presentation_agent/agent.toml"),
prompt_fn: super::presentation_agent::prompt::build,
- graph_fn: None,
},
BuiltinAgent {
id: "vision_agent",
toml: include_str!("vision_agent/agent.toml"),
prompt_fn: super::vision_agent::prompt::build,
- graph_fn: None,
},
BuiltinAgent {
id: "image_agent",
toml: include_str!("image_agent/agent.toml"),
prompt_fn: super::image_agent::prompt::build,
- graph_fn: None,
},
BuiltinAgent {
id: "video_agent",
toml: include_str!("video_agent/agent.toml"),
prompt_fn: super::video_agent::prompt::build,
- graph_fn: None,
},
BuiltinAgent {
id: "trigger_triage",
toml: include_str!("trigger_triage/agent.toml"),
prompt_fn: super::trigger_triage::prompt::build,
- graph_fn: None,
},
BuiltinAgent {
id: "trigger_reactor",
toml: include_str!("trigger_reactor/agent.toml"),
prompt_fn: super::trigger_reactor::prompt::build,
- graph_fn: None,
},
BuiltinAgent {
id: "morning_briefing",
toml: include_str!("morning_briefing/agent.toml"),
prompt_fn: super::morning_briefing::prompt::build,
- graph_fn: None,
},
BuiltinAgent {
id: "summarizer",
toml: include_str!("summarizer/agent.toml"),
prompt_fn: super::summarizer::prompt::build,
- graph_fn: None,
},
// Skill agents — `#[cfg]` rather than stub: `include_str!` embeds the
// agent TOML from disk regardless of module gating, so the entry itself
@@ -148,7 +128,6 @@ pub const BUILTINS: &[BuiltinAgent] = &[
id: "skill_setup",
toml: include_str!("../../../skills/catalog/agent/skill_setup/agent.toml"),
prompt_fn: crate::skills::catalog::agent::skill_setup::prompt::build,
- graph_fn: None,
},
// Workflow-authoring specialist (Phase 5a): builds tinyflows automation
// graphs from natural language and returns a validated PROPOSAL — it never
@@ -160,7 +139,6 @@ pub const BUILTINS: &[BuiltinAgent] = &[
id: "workflow_builder",
toml: include_str!("../../../flows/agents/workflow_builder/agent.toml"),
prompt_fn: crate::flows::agents::workflow_builder::prompt::build,
- graph_fn: None,
},
// Workflow-discovery specialist (the "Flow Scout"): reads the user's
// memory/threads/people/connections/flows read-only and ends by calling
@@ -174,7 +152,6 @@ pub const BUILTINS: &[BuiltinAgent] = &[
id: "flow_discovery",
toml: include_str!("../../../flows/agents/flow_discovery/agent.toml"),
prompt_fn: crate::flows::agents::flow_discovery::prompt::build,
- graph_fn: None,
},
];
@@ -295,11 +272,6 @@ fn parse_builtin(b: &BuiltinAgent) -> Result<AgentDefinition> {
def.system_prompt = PromptSource::Dynamic(b.prompt_fn);
def.source = DefinitionSource::Builtin;
- // Install the agent's turn-graph selection (issue #4249) — the runtime
- // analogue of the prompt builder above. Default agents leave `graph_fn`
- // unset and use `AgentGraph::Default` from `AgentDefinition`.
- def.graph = b.graph_fn.map(|graph| graph()).unwrap_or_default();
-
// Sanity check: file layout id must match declared TOML id. This
// catches copy-paste mistakes where someone forgets to update the
// `id` field after duplicating a folder.
diff --git a/crates/openhuman-core/src/agent/registry/agents/mod.rs b/crates/openhuman-core/src/agent/registry/agents/mod.rs
index 9500571a6b..e1bd641479 100644
--- a/crates/openhuman-core/src/agent/registry/agents/mod.rs
+++ b/crates/openhuman-core/src/agent/registry/agents/mod.rs
@@ -16,10 +16,6 @@
//! [`BUILTINS`] installs it as `PromptSource::Dynamic` on the parsed
//! definition. Most archetypes keep a `prompt_tests.rs` beside it.
//!
-//! An archetype may additionally own a `graph.rs` exposing
-//! `fn graph() -> AgentGraph` for a bespoke turn graph; see
-//! [`BuiltinAgent::graph_fn`].
-//!
//! `loader.rs` holds [`BUILTINS`], [`load_builtins`] and
//! [`validate_tier_hierarchy`]. The slice also registers archetypes that
//! live with other domains (`skills/*/agent/`,
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
index 8c78b5e8b7..77f60ac2d8 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
@@ -10,7 +10,6 @@ use std::collections::HashSet;
use std::sync::Arc;
use std::time::Instant;
-use crate::agent::harness::agent_graph::{AgentTurnRequest, AgentTurnUsage};
use crate::agent::harness::artifact_offload::{
effective_offload_threshold, extract_artifact_paths, new_artifact_offload,
note_artifact_handoff, offload_oversized_result, DEFAULT_OFFLOAD_THRESHOLD_BYTES,
@@ -881,12 +880,6 @@ async fn run_typed_mode(
model_vision,
"[subagent_host] resolved sub-agent model vision capability"
);
- // Per-agent turn graph (issue #4249): `Default` runs the shared sub-agent
- // graph; `Custom` hands the assembled turn to this agent's own graph runner
- // (declared in its `graph.rs::graph()`). Every built-in agent selects
- // `Default` today — the branch is the extension point.
- use super::graph::AggregatedUsage;
- use crate::agent::harness::agent_graph::AgentGraph;
// Resolve the child transcript stem once — `{parent_chain}__{child_session_key}`
// — so the sub-agent's raw transcript lands in `session_raw` under a filename
// that chains the parent session (parity with the removed observer stem).
@@ -938,105 +931,44 @@ async fn run_typed_mode(
}
let (output, iterations, agg_usage, early_exit_tool, hit_cap, breaker_halt) =
- match &definition.graph {
- AgentGraph::Default => {
- super::graph::run_subagent_via_graph(
- subagent_source.clone(),
- &model,
- temperature,
- &mut history,
- parent.all_tools.clone(),
- Vec::new(),
- filtered_specs.clone(),
- allowed_names,
- subagent_iter_cap_with_autonomous_lift(definition.effective_max_iterations()),
- options.run_queue.clone(),
- parent.on_progress.clone(),
- &definition.id,
- task_id,
- definition.iteration_policy == IterationPolicy::Extended,
- options.thread_id.clone(),
- options
- .run_context
- .for_subagent(definition, config.as_ref().ok().map(AsRef::as_ref)),
- options.worker_thread_id.clone(),
- parent.workspace_dir.clone(),
- workspace_descriptor.clone(),
- max_output_tokens,
- model_vision,
- &transcript_stem,
- // Sub-agent turns record their provider label as the literal
- // "subagent" (parity with the legacy observer's TurnObserver
- // provenance), distinguishing delegated spend from the parent's
- // own channel in per-thread usage reads.
- "subagent",
- // Agent-level TokenJuice profile → sub-agent context middleware
- // (#4466), so sub-agent tool outputs compact like the chat path.
- definition.effective_tokenjuice_compression(),
- // The spawn-wide config snapshot supplies the `[context]`
- // knobs the graph used to load for itself.
- config.as_ref().ok().map(|c| c.as_ref()),
- )
- .await?
- }
- AgentGraph::Custom(run) => {
- let req = AgentTurnRequest {
- turn_model_source: subagent_source.clone(),
- model: model.clone(),
- temperature,
- history: std::mem::take(&mut history),
- parent_tools: parent.all_tools.clone(),
- dynamic_tools: Vec::new(),
- specs: filtered_specs.clone(),
- allowed_names,
- max_iterations: subagent_iter_cap_with_autonomous_lift(
- definition.effective_max_iterations(),
- ),
- run_queue: options.run_queue.clone(),
- on_progress: parent.on_progress.clone(),
- agent_id: definition.id.clone(),
- task_id: task_id.to_string(),
- extended_policy: definition.iteration_policy == IterationPolicy::Extended,
- thread_id: options.thread_id.clone(),
- run_context: options.run_context.clone(),
- worker_thread_id: options.worker_thread_id.clone(),
- workspace_dir: parent.workspace_dir.clone(),
- workspace_descriptor: workspace_descriptor.clone(),
- max_output_tokens,
- model_vision,
- transcript_stem: transcript_stem.clone(),
- provider_label: "subagent".to_string(),
- tokenjuice_compression: definition.effective_tokenjuice_compression(),
- config: config.as_ref().ok().map(Arc::clone),
- };
- let res = run(req).await?;
- history = res.history;
- let AgentTurnUsage {
- input_tokens,
- output_tokens,
- cached_input_tokens,
- charged_amount_usd,
- } = res.usage;
- (
- res.output,
- res.iterations,
- AggregatedUsage {
- input_tokens,
- output_tokens,
- cached_input_tokens,
- // A custom turn graph reports its own spend; it is
- // taken as that graph's charge, never re-estimated.
- cost: crate::agent::cost::CostTally {
- known_usd: charged_amount_usd,
- source: crate::agent::cost::CostSource::Charged,
- },
- },
- res.early_exit_tool,
- res.hit_cap,
- res.breaker_halt,
- )
- }
- };
+ super::graph::run_subagent_via_graph(
+ subagent_source.clone(),
+ &model,
+ temperature,
+ &mut history,
+ parent.all_tools.clone(),
+ Vec::new(),
+ filtered_specs.clone(),
+ allowed_names,
+ subagent_iter_cap_with_autonomous_lift(definition.effective_max_iterations()),
+ options.run_queue.clone(),
+ parent.on_progress.clone(),
+ &definition.id,
+ task_id,
+ definition.iteration_policy == IterationPolicy::Extended,
+ options.thread_id.clone(),
+ options
+ .run_context
+ .for_subagent(definition, config.as_ref().ok().map(AsRef::as_ref)),
+ options.worker_thread_id.clone(),
+ parent.workspace_dir.clone(),
+ workspace_descriptor.clone(),
+ max_output_tokens,
+ model_vision,
+ &transcript_stem,
+ // Sub-agent turns record their provider label as the literal
+ // "subagent" (parity with the legacy observer's TurnObserver
+ // provenance), distinguishing delegated spend from the parent's
+ // own channel in per-thread usage reads.
+ "subagent",
+ // Agent-level TokenJuice profile → sub-agent context middleware
+ // (#4466), so sub-agent tool outputs compact like the chat path.
+ definition.effective_tokenjuice_compression(),
+ // The spawn-wide config snapshot supplies the `[context]`
+ // knobs the graph used to load for itself.
+ config.as_ref().ok().map(|c| c.as_ref()),
+ )
+ .await?;
// Determine status: if the turn engine exited early because of
// ask_user_clarification, checkpoint the history and return
diff --git a/crates/openhuman-core/src/cron/scheduler/agent_run.rs b/crates/openhuman-core/src/cron/scheduler/agent_run.rs
index f416e98acb..a73c122661 100644
--- a/crates/openhuman-core/src/cron/scheduler/agent_run.rs
+++ b/crates/openhuman-core/src/cron/scheduler/agent_run.rs
@@ -199,7 +199,7 @@ pub(super) async fn run_agent_job_for_run(
recency_window_secs = MORNING_BRIEFING_TASK_RECENCY_SECS,
"[cron] applying morning-briefing task recency window"
);
- crate::agent::harness::with_task_recency_window(
+ crate::integrations::composio::task_recency_context::with_task_recency_window(
std::time::Duration::from_secs(MORNING_BRIEFING_TASK_RECENCY_SECS),
turn,
)
diff --git a/crates/openhuman-core/src/integrations/composio/mod.rs b/crates/openhuman-core/src/integrations/composio/mod.rs
index 755a3f82ad..b240fc7bf4 100644
--- a/crates/openhuman-core/src/integrations/composio/mod.rs
+++ b/crates/openhuman-core/src/integrations/composio/mod.rs
@@ -88,3 +88,6 @@ pub use types::{
ComposioToolsResponse, ComposioTriggerEvent, ComposioTriggerHistoryEntry,
ComposioTriggerHistoryResult, ComposioTriggerMetadata,
};
+
+/// Product-specific task recency scoping used by the briefing runner.
+pub(crate) mod task_recency_context;
diff --git a/crates/openhuman-core/src/agent/harness/task_recency_context.rs b/crates/openhuman-core/src/integrations/composio/task_recency_context.rs
similarity index 81%
rename from crates/openhuman-core/src/agent/harness/task_recency_context.rs
rename to crates/openhuman-core/src/integrations/composio/task_recency_context.rs
index 1a4d4f136c..870236479f 100644
--- a/crates/openhuman-core/src/agent/harness/task_recency_context.rs
+++ b/crates/openhuman-core/src/integrations/composio/task_recency_context.rs
@@ -2,11 +2,8 @@
//! surface can restrict task-fetch results to "recently created/changed"
//! without widening the [`tinytools::Tool`] trait signature.
//!
-//! Sibling of [`super::sandbox_context`]: same task-local pattern, different
-//! concept. `CURRENT_AGENT_SANDBOX_MODE` carries the calling agent's sandbox
-//! mode; [`TASK_RECENCY_WINDOW`] carries an optional "only data newer than
-//! `now - window`" hint that the `composio_execute` handler applies to a
-//! curated set of task-fetch slugs (see `tinyconnectors-bus::PrepareArguments`).
+//! This Composio product policy is installed by the morning briefing runner
+//! and applied to curated task-fetch actions through the connector bus.
//!
//! Why a task-local instead of a `Tool::execute` argument: the tool trait is
//! invoked from many call sites (CLI, JSON-RPC, tests, agent loops). A
@@ -30,14 +27,14 @@ tokio::task_local! {
/// Returns the active task-recency window, if the scope is installed.
///
/// `None` outside [`with_task_recency_window`] — i.e. normal chat turns,
-/// direct CLI/JSON-RPC tool dispatch, or unit tests calling a [`Tool`]
+/// direct CLI/JSON-RPC tool dispatch, or unit tests calling a [`tinytools::Tool`]
/// directly. Callers treat `None` as "no recency restriction".
pub fn current_task_recency_window() -> Option<Duration> {
let window = TASK_RECENCY_WINDOW.try_with(|w| *w).ok();
tracing::trace!(
has_window = window.is_some(),
window_secs = window.map(|w| w.as_secs()),
- "[harness][task-window] read current window"
+ "[composio][task-window] read current window"
);
window
}
@@ -54,10 +51,10 @@ where
{
tracing::trace!(
window_secs = window.as_secs(),
- "[harness][task-window] scope enter"
+ "[composio][task-window] scope enter"
);
let out = TASK_RECENCY_WINDOW.scope(window, future).await;
- tracing::trace!("[harness][task-window] scope exit");
+ tracing::trace!("[composio][task-window] scope exit");
out
}
diff --git a/crates/openhuman-core/src/agent/harness/task_recency_context_tests.rs b/crates/openhuman-core/src/integrations/composio/task_recency_context_tests.rs
similarity index 100%
rename from crates/openhuman-core/src/agent/harness/task_recency_context_tests.rs
rename to crates/openhuman-core/src/integrations/composio/task_recency_context_tests.rs
diff --git a/crates/openhuman-core/src/integrations/composio/tools/execute.rs b/crates/openhuman-core/src/integrations/composio/tools/execute.rs
index d8784b3e9c..01a4584b35 100644
--- a/crates/openhuman-core/src/integrations/composio/tools/execute.rs
+++ b/crates/openhuman-core/src/integrations/composio/tools/execute.rs
@@ -10,9 +10,9 @@ use serde_json::{json, Value};
use super::live_config::live_composio_config;
use super::redact::redact_composio_outcome;
use crate::agent::harness::current_sandbox_mode;
-use crate::agent::harness::current_task_recency_window;
use crate::agent::harness::definition::SandboxMode;
use crate::config::Config;
+use crate::integrations::composio::task_recency_context::current_task_recency_window;
use tinytools::{PermissionLevel, Tool, ToolCategory, ToolResult};
use super::super::ops::load_user_scope_pref;