- Added tracing instrumentation and improved logging messages in the Pong, Todofinish, and Todowrite tools for better debugging and monitoring. - Enhanced documentation comments for clarity on tool functionalities and workflows. - Implemented tracing in WorkflowRun, NoteFinding, ReadFindings, and HiveMind tools to track execution phases and findings. - Updated TUI overlays (e.g., Bash, Clear Confirm, Editor, Effort Level, Help, Key Input, Learning, Loading, MCP, Model Selector, Plan, Quit Confirm, Rewind, Settings, Todo, Usage) with debug logging to capture rendering details. - Improved the status bar and workflow panel rendering with additional debug information. - Added tracing to various utility functions to facilitate better performance monitoring and error tracking.
39 lines
1.2 KiB
Rust
39 lines
1.2 KiB
Rust
//! Subagent spawning — launch a subagent on a background OS thread.
|
|
//!
|
|
//! Flow: creates a new tokio runtime on a dedicated OS thread, then
|
|
//! `block_on` the engine's `run_agent` future. Returns a
|
|
//! `JoinHandle<Result<String>>` the caller can `.join()`.
|
|
|
|
use std::thread;
|
|
|
|
use anyhow::Result;
|
|
use tracing::{info, instrument};
|
|
|
|
use crate::subagent::context::SubagentContext;
|
|
use crate::subagent::division::AccessTier;
|
|
use crate::subagent::engine::run_agent;
|
|
use crate::tools::ToolCtx;
|
|
|
|
/// Spawn a subagent on a background OS thread.
|
|
///
|
|
/// The subagent runs inside its own tokio runtime so it can make async calls
|
|
/// without blocking the calling thread's runtime.
|
|
///
|
|
/// Flow: `thread::spawn` → create `tokio::runtime::Runtime` →
|
|
/// `runtime.block_on(run_agent(...))` → return.
|
|
///
|
|
/// Returns a `JoinHandle` the caller can `join()` to await the result.
|
|
#[instrument(skip(ctx, tool_ctx))]
|
|
pub fn spawn_subagent(
|
|
ctx: SubagentContext,
|
|
directive: String,
|
|
access: AccessTier,
|
|
tool_ctx: ToolCtx,
|
|
) -> thread::JoinHandle<Result<String>> {
|
|
info!("Spawning subagent: {directive}");
|
|
thread::spawn(move || {
|
|
let rt = tokio::runtime::Runtime::new()?;
|
|
rt.block_on(run_agent(ctx, &directive, access, tool_ctx))
|
|
})
|
|
}
|