The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(agent): track subagent progress in host types
Steven Enamakel0981ded9aea5
diff --git a/crates/openhuman-core/src/agent/progress.rs b/crates/openhuman-core/src/agent/progress.rsindex 9ed06a59a6..97bdbce424 100644--- a/crates/openhuman-core/src/agent/progress.rs+++ b/crates/openhuman-core/src/agent/progress.rs@@ -13,450 +13,7 @@//! that created the channel already knows those and tags the outgoing//! socket events accordingly.-/// A real-time progress event emitted during an agent turn.-#[derive(Debug, Clone)]-pub enum AgentProgress {- /// The turn has started (about to enter the iteration loop).- TurnStarted,-- /// A new LLM iteration is starting.- IterationStarted {- /// 1-based iteration index.- iteration: u32,- /// Maximum iterations configured for this turn.- max_iterations: u32,- },-- /// The LLM responded and the agent is about to execute a tool.- ToolCallStarted {- /// Provider-assigned (or synthesised) tool call id that ties- /// this event to its eventual [`Self::ToolCallCompleted`] and- /// to any preceding [`Self::ToolCallArgsDelta`] fragments.- call_id: String,- tool_name: String,- arguments: serde_json::Value,- /// 1-based iteration index.- iteration: u32,- /// Server-computed human label for the chat processing timeline- /// (e.g. "Reading messages"), or `None` to defer to the client- /// formatter. Set from [`tinytools::Tool::display_label`].- display_label: Option<String>,- /// Server-computed contextual detail shown after the label- /// (e.g. "[email protected]"), from `Tool::display_detail`.- display_detail: Option<String>,- },-- /// A tool execution completed (success or failure).- ToolCallCompleted {- /// Same call id as the matching [`Self::ToolCallStarted`] and- /// [`Self::ToolCallArgsDelta`] events.- call_id: String,- tool_name: String,- success: bool,- output_chars: usize,- /// Full text the tool returned. Mirrors- /// [`Self::SubagentToolCallCompleted::output`] so trace exporters can- /// record the parent-scope tool result as the span output (truncated +- /// content-gated at the collector). Empty when the harness ran with- /// payload capture off.- output: String,- /// The arguments the tool was invoked with, when the harness captured- /// them (`PayloadCapture::tool_io`). The crate emits arguments on the- /// *completed* event, so trace exporters use this to backfill the tool- /// span's input (the started event's `arguments` is `Null` on the- /// tinyagents path).- arguments: Option<serde_json::Value>,- elapsed_ms: u64,- /// 1-based iteration index.- iteration: u32,- /// Present when `success` is false: a user-facing classification of the- /// failure (class, category, plain-language cause + next action) that- /// the chat "View processing" timeline renders. `None` on success and- /// on legacy snapshots. See `crate::tools::status`.- failure: Option<tinytools::status::ClassifiedFailure>,- /// Server-computed human label recomputed from the tool's OWN- /// [`tinytools::Tool::display_label`] using the real call arguments- /// (the matching `ToolCallStarted.display_label` was computed with no- /// arguments, since the harness start event carries none). Forwarded- /// on the wire as `tool_display_label` so a completed row can pick up- /// a label that only became knowable once the arguments existed.- display_label: Option<String>,- /// Server-computed contextual detail (e.g. "[email protected]"),- /// recomputed the same way from `Tool::display_detail`.- display_detail: Option<String>,- /// Structured, tool-specific result payload copied from- /// [`tinytools::ToolResult::metadata`] when it is a JSON object- /// carrying a `"kind"` discriminator (e.g. `{"kind":"web_search",...}`).- /// `None` for tools that don't populate metadata of that shape.- structured: Option<serde_json::Value>,- },-- /// A running tool reported progress through- /// `ToolRunContext::report_progress` (a shell call's elapsed time and- /// output, a media job's state). Falls between the call's- /// [`Self::ToolCallStarted`] and [`Self::ToolCallCompleted`]. Parent-scope- /// calls only.- ToolCallProgress {- /// Correlation id of the running call.- call_id: String,- /// Human-readable status line.- message: String,- },-- /// A sub-agent was spawned during tool execution.- SubagentSpawned {- agent_id: String,- task_id: String,- /// Resolved spawn mode — currently always `"typed"`. Kept as a- /// string so future modes (e.g. background/swarm) can land- /// without changing the event shape.- mode: String,- /// `true` when the spawn was requested with- /// `dedicated_thread: true`. The UI links the inline subagent- /// row to the eventual worker thread once the run completes.- dedicated_thread: bool,- /// Character length of the delegated prompt — useful to decide- /// whether to render the prompt detail inline or behind a- /// "show more" affordance.- prompt_chars: usize,- /// Persistent worker sub-thread id backing this delegation, when- /// one was created (`worker-<uuid>`). The UI uses it to reopen the- /// full parent↔subagent conversation from memory after the live- /// turn ends. `None` for live-only runs (no parent context).- worker_thread_id: Option<String>,- /// Human-readable display name from the agent registry (e.g.- /// "Researcher", "Coding Agent"). Falls back to `agent_id` in- /// the UI when absent.- display_name: Option<String>,- /// The full delegated prompt text. `prompt_chars` stays as the cheap- /// size hint; trace exporters record this (truncated + content-gated)- /// as the subagent span's input so a delegation is inspectable- /// end-to-end in Langfuse.- prompt: String,- /// The parent turn's tool-call id (the `spawn_subagent` /- /// dispatch call) this spawn is attributed to. `None` until- /// every emit site is updated to pass it through; additive so- /// existing consumers reading only the other fields are- /// unaffected. Mirrors- /// [`crate::web_chat::SubagentProgressDetail::parent_call_id`].- parent_call_id: Option<String>,- },-- /// A sub-agent completed successfully.- SubagentCompleted {- agent_id: String,- task_id: String,- elapsed_ms: u64,- /// Number of LLM iterations the sub-agent actually used. The- /// UI surfaces this in the parent thread's subagent row so a- /// completed delegation reads as "code_executor · 3 turns · 4.2s"- /// instead of just "done".- iterations: u32,- /// Character length of the sub-agent's final assistant text.- output_chars: usize,- /// This child's own token + cost totals, **and only when they did not- /// already reach the parent turn's ledger**.- ///- /// ## Populate this ONLY when the spend is not already counted- ///- /// A blocking spawn records into `parent_subagent_usage`, and- /// `holistic_last_turn_usage` then folds those child tokens AND- /// `charged_amount_usd` into the figures `chat_done` carries. A- /// detached spawn does not: `detached_child()` sets- /// `parent_subagent_usage` to `None` and swaps in a fresh ledger, so- /// the entry lands somewhere the parent never reads.- ///- /// The consumer adds whatever arrives here, unconditionally. That is- /// what makes the omission safe — a site that does not populate this- /// contributes nothing, which is the status quo — and it is also why- /// populating it for a child that DID reach the parent ledger silently- /// doubles the user's reported spend, money included, with no test- /// failing. **Check the ledger, not the spawn mode**: spawn mode is a- /// proxy and proxies drift.- usage: Option<crate::agent::subagent_host::SubagentUsage>,- /// The sub-agent's full final assistant text. Trace exporters record- /// this (truncated + content-gated) as the subagent span's output.- output: String,- /// Absolute path to the worker's isolated `git worktree` checkout,- /// when it ran with `isolation = "worktree"` (#3376). `None` for- /// non-isolated (read-only / shared-workspace) workers.- worktree_path: Option<String>,- /// Files (relative to the worktree root) the worker changed, snapshot- /// from `git status` after the run. Empty for non-isolated workers or- /// a clean worktree.- changed_files: Vec<String>,- /// Whether the worker's worktree had uncommitted changes after the- /// run. A dirty worktree must not be auto-removed — surfaced so the UI- /// can require an explicit user decision. `None` for non-isolated.- dirty_status: Option<bool>,- /// Set when the sub-agent's own turn was stopped early (failure- /// breaker or iteration cap) and handed back as incomplete. The trace- /// collector closes the subagent span at `WARNING` with it. `None` for- /// a sub-agent that finished normally.- stop: Option<tinyagents_harness::turn_stop::TurnStop>,- },-- /// A sub-agent failed.- SubagentFailed {- agent_id: String,- task_id: String,- error: String,- },-- /// A sub-agent paused and is waiting for user input relayed via- /// `continue_subagent`. The orchestrator surfaces the question to- /// the user and calls `continue_subagent` with the answer.- SubagentAwaitingUser {- agent_id: String,- task_id: String,- question: String,- worker_thread_id: Option<String>,- /// Where the paused conversation was persisted, or `None` when the- /// write failed.- ///- /// Carried rather than re-derived by the consumer: the run ledger used- /// to rebuild this path from the workspace dir and record it- /// unconditionally, so it claimed a checkpoint existed even when none- /// had been written, and would have pointed at the wrong directory for- /// any run whose `checkpoint_dir` was overridden (#5928).- checkpoint_path: Option<String>,- },-- /// A sub-agent's inner LLM iteration is starting. Emitted **only- /// from inside [`crate::agent::subagent_host`]**- /// when the parent context carries an `on_progress` sink — the- /// outer parent loop uses [`Self::IterationStarted`] for its own- /// rounds. Carries the child's `task_id` so the UI can attribute- /// the round to a specific live subagent row.- SubagentIterationStarted {- agent_id: String,- task_id: String,- /// 1-based child iteration index.- iteration: u32,- /// Maximum iterations configured for this child run.- max_iterations: u32,- /// `true` when the agent uses [`IterationPolicy::Extended`](tinyagents_definition::IterationPolicy::Extended).- /// The UI uses this to show "step N" instead of "turn N/M".- extended_policy: bool,- },-- /// A sub-agent is about to execute a tool. Distinct from- /// [`Self::ToolCallStarted`] so the parent thread can render- /// child-tool activity nested under the subagent row instead of- /// flattened into the parent's tool timeline.- SubagentToolCallStarted {- agent_id: String,- task_id: String,- call_id: String,- tool_name: String,- /// Full arguments the child invoked the tool with, so the parent- /// thread's UI can show *what exactly* the sub-agent did (not just- /// the tool name). Mirrors the top-level `ToolCallStarted.arguments`.- arguments: serde_json::Value,- /// 1-based child iteration index this call belongs to.- iteration: u32,- /// Server-computed human label for the timeline (e.g. "Reading- /// messages"), or `None` to defer to the client formatter. Mirrors- /// the top-level `ToolCallStarted.display_label`.- display_label: Option<String>,- /// Server-computed contextual detail (e.g. "[email protected]").- display_detail: Option<String>,- },-- /// A sub-agent's tool execution finished.- SubagentToolCallCompleted {- agent_id: String,- task_id: String,- call_id: String,- tool_name: String,- success: bool,- output_chars: usize,- /// Full text the tool returned, so the UI can show the sub-agent's- /// actual result/output. `output_chars` is kept as a cheap size hint- /// for consumers that only want the length.- output: String,- /// The arguments the tool was invoked with, when the harness captured- /// them (`PayloadCapture::tool_io`). Backfills the tool span's input in- /// trace exports (the started event's `arguments` is `Null` on the- /// tinyagents path).- arguments: Option<serde_json::Value>,- elapsed_ms: u64,- /// 1-based child iteration index.- iteration: u32,- /// Present when `success` is false: a user-facing classification of the- /// child tool failure, mirroring [`Self::ToolCallCompleted::failure`] so- /// a failed sub-agent row carries the same "why + what to do next" copy- /// instead of discarding the already-computed classification (#4459).- failure: Option<tinytools::status::ClassifiedFailure>,- /// Mirrors [`Self::ToolCallCompleted::display_label`], recomputed from- /// the child tool's own `Tool::display_label` using the real call- /// arguments.- display_label: Option<String>,- /// Mirrors [`Self::ToolCallCompleted::display_detail`].- display_detail: Option<String>,- /// Mirrors [`Self::ToolCallCompleted::structured`].- structured: Option<serde_json::Value>,- },-- /// A chunk of a sub-agent's visible assistant text arrived from the- /// provider while the child iteration is still in flight. Distinct- /// from [`Self::TextDelta`] so the parent thread can attribute the- /// streamed token to a specific live subagent row (via `task_id`)- /// and render it inside that row's transcript instead of merging it- /// into the parent's own streaming buffer. Emitted **only from- /// inside [`crate::agent::subagent_host`]** when- /// the parent context carries an `on_progress` sink.- SubagentTextDelta {- agent_id: String,- task_id: String,- delta: String,- /// 1-based child iteration index this delta belongs to.- iteration: u32,- },-- /// A chunk of a sub-agent's model reasoning / thinking output- /// arrived (for models that emit `reasoning_content`). Counterpart- /// to [`Self::ThinkingDelta`] scoped to a child run — see- /// [`Self::SubagentTextDelta`] for the attribution rationale.- SubagentThinkingDelta {- agent_id: String,- task_id: String,- delta: String,- /// 1-based child iteration index.- iteration: u32,- },-- /// A chunk of visible assistant text arrived from the provider- /// while the current iteration is still in flight.- TextDelta {- delta: String,- /// 1-based iteration index this delta belongs to.- iteration: u32,- },-- /// A chunk of model reasoning / thinking output arrived (for- /// models that emit `reasoning_content`). Consumers typically- /// render this in a separate collapsible UI region.- ThinkingDelta {- delta: String,- /// 1-based iteration index.- iteration: u32,- },-- /// A chunk of argument JSON arrived for an in-flight tool call.- /// Emitted before the matching [`AgentProgress::ToolCallStarted`]- /// event so consumers can show the model composing the call.- ToolCallArgsDelta {- /// Provider-assigned tool call id (stable across chunks).- call_id: String,- /// Tool name, when known (may be empty on the very first- /// chunk if the provider hasn't sent the `function.name` yet).- tool_name: String,- /// Raw JSON text fragment; concatenated fragments form the- /// complete arguments object.- delta: String,- /// 1-based iteration index.- iteration: u32,- },-- /// Cumulative cost / token tally for the current turn, emitted- /// after each provider response that carried a usage block.- /// Consumers can render a live "$0.04 · 1.2k in / 480 out" line in- /// the UI without subscribing to provider-level events.- ///- /// `total_usd` prefers backend-reported `charged_amount_usd`- /// (sum of authoritative figures) and falls back to a tier-based- /// token-rate estimate for calls that didn't carry one — see- /// [`tinyagents_harness::cost::TurnCost::total_usd`].- TurnCostUpdated {- /// Last model that contributed to this update.- model: String,- /// 1-based iteration index this update belongs to.- iteration: u32,- /// Cumulative input tokens across the turn.- input_tokens: u64,- /// Cumulative output tokens across the turn.- output_tokens: u64,- /// Cumulative cached prefix input tokens across the turn.- cached_input_tokens: u64,- /// Best-available USD total for the turn so far.- total_usd: f64,- },-- /// A single LLM call finished and reported usage. Unlike- /// [`Self::TurnCostUpdated`] (cumulative rollup), every field here is- /// **per-call**, so trace exporters can render each model invocation as- /// its own Langfuse generation with exact model + token + cost figures.- /// Emitted once per model call — parent-scope calls carry- /// `subagent_task_id: None`; child (subagent) calls carry the owning- /// task id so exporters can nest the generation under the subagent span.- ModelCallCompleted {- /// Model that served this call (tier handle or concrete model id).- model: String,- /// Provider that served this call (`"managed"`, `"openai"`,- /// `"ollama"`, …). Trace exporters render the Langfuse model as- /// `{provider_id}.{model}` (e.g. `managed.hint:chat`).- provider_id: String,- /// Owning subagent task id when this call ran inside a child run- /// (`spawn_subagent` / Context Scout). `None` for parent-scope calls.- subagent_task_id: Option<String>,- /// The request messages sent to the model (including the system- /// prompt), when the harness captured them- /// (`PayloadCapture::model_io`). Trace exporters record this as the- /// generation's input, gated on `capture_content`.- input: Option<serde_json::Value>,- /// The model completion (assistant message), when captured. Recorded- /// as the generation's output, gated on `capture_content`.- output: Option<serde_json::Value>,- /// 1-based iteration index (one model call per iteration).- iteration: u32,- /// Input/prompt tokens for this call.- input_tokens: u64,- /// Output/completion tokens for this call.- output_tokens: u64,- /// Input tokens served from a provider-side cache (cache reads).- cached_input_tokens: u64,- /// Input tokens written into a provider cache (cache creation).- cache_creation_tokens: u64,- /// Reasoning/thinking tokens, when the provider reports them.- reasoning_tokens: u64,- /// USD cost of this single call: the backend's reported charge, else- /// the catalog's list-price estimate; `None` when neither exists.- cost_usd: Option<f64>,- },-- /// The turn completed with a final text response.- TurnCompleted {- /// Total iterations used.- iterations: u32,- /// Set when the harness stopped the turn early (failure breaker,- /// deadline wind-down, iteration cap) even though it reached this- /// completion path. Content-free; the trace collector closes the turn- /// span at `WARNING` with it. `None` for a turn that finished on its- /// own.- stop: Option<tinyagents_harness::turn_stop::TurnStop>,- },-- /// The turn's content: the user's prompt and the model's final reply.- /// Emitted just before [`Self::TurnCompleted`] so a tracing consumer can- /// attach `input`/`output` to the turn span. Carries prompt/reply text, so- /// exporters must honor the opt-in `observability.agent_tracing.capture_content`- /// gate before transmitting it off-device.- TurnContent {- /// The user's prompt for this turn.- input: Option<String>,- /// The model's final reply for this turn.- output: Option<String>,- },-}--impl AgentProgress {- /// A [`Self::TurnCompleted`] for a turn that finished on its own (no- /// early stop).- pub fn turn_completed(iterations: u32) -> Self {- Self::TurnCompleted {- iterations,- stop: None,- }- }-}+/// The progress vocabulary is TinyAgents' (`tinyagents_harness::progress`): the+/// host consumes the very events the harness emits, and the web chat's turn+/// runner carries them as its canonical progress.+pub use tinyagents_harness::progress::AgentProgress;diff --git a/crates/openhuman-core/src/agent/subagent_host/types.rs b/crates/openhuman-core/src/agent/subagent_host/types.rsindex 62bb9d44ff..43c8f89db5 100644--- a/crates/openhuman-core/src/agent/subagent_host/types.rs+++ b/crates/openhuman-core/src/agent/subagent_host/types.rs@@ -185,38 +185,19 @@ impl SubagentRunOutcome {}}-/// Token + cost totals for a single sub-agent run.-///-/// Mirrors the inner-loop `AggregatedUsage`, lifted into the public outcome so-/// the parent turn can fold sub-agent spend into the session-level token/cost-/// meters surfaced in the UI footer.-#[derive(Debug, Clone, Copy, Default, PartialEq, serde::Serialize, serde::Deserialize)]-pub struct SubagentUsage {- pub input_tokens: u64,- pub output_tokens: u64,- pub cached_input_tokens: u64,- /// Sum of the run's known call costs; read with `cost_source`.- pub charged_amount_usd: f64,- /// How certain `charged_amount_usd` is. `Unknown` means some call had no- /// charge and no catalogued price, so the sum is incomplete.- #[serde(- default = "unknown_cost_source",- skip_serializing_if = "is_unknown_cost_source"- )]- pub cost_source: tinyagents_harness::cost::CostSource,-}--fn unknown_cost_source() -> tinyagents_harness::cost::CostSource {- tinyagents_harness::cost::CostSource::Unknown-}--fn is_unknown_cost_source(source: &tinyagents_harness::cost::CostSource) -> bool {- *source == tinyagents_harness::cost::CostSource::Unknown+/// Token + cost totals for a single sub-agent run, lifted into the public+/// outcome so the parent turn can fold sub-agent spend into the session-level+/// token/cost meters surfaced in the UI footer. The type is TinyAgents'+/// (`AgentProgress::SubagentCompleted` carries it).+pub use tinyagents_harness::progress::SubagentUsage;++/// The run's cost as a tally, for folding into a parent's.+pub trait SubagentUsageExt {+ fn cost(&self) -> tinyagents_harness::cost::CostTally;}-impl SubagentUsage {- /// The run's cost as a tally, for folding into a parent's.- pub fn cost(&self) -> tinyagents_harness::cost::CostTally {+impl SubagentUsageExt for SubagentUsage {+ fn cost(&self) -> tinyagents_harness::cost::CostTally {tinyagents_harness::cost::CostTally {known_usd: self.charged_amount_usd,source: self.cost_source,