feat: add turn_events to ToolCtx and implement live state updates in spawn tool

This commit is contained in:
asepharyana
2026-07-12 17:50:38 +07:00
parent 53b0cb271f
commit a59feb23c4
4 changed files with 42 additions and 2 deletions
+34 -2
View File
@@ -88,12 +88,28 @@ impl Tool for SpawnAgents {
},
};
use std::sync::Arc;
let live: Option<crate::app::workflow::engine::LiveStateFn> = _ctx.turn_events.as_ref().map(|turn_events| {
let turn_events = turn_events.clone();
let f: crate::app::workflow::engine::LiveStateFn = Arc::new(move |agent_id: String, status| {
let name = agent_id.chars().take(30).collect::<String>();
if let Ok(mut q) = turn_events.lock() {
q.push_back(crate::app::state::runtime::TurnEvent::WorkflowAgentUpdate {
agent_id,
agent_name: name,
status,
});
}
});
f
});
let results = crate::app::workflow::engine::execute_primitive(
&wf.script,
&HashMap::new(),
max_concurrency,
true,
None,
live.as_ref(),
)?;
format_results(results, "parallel")
}
@@ -155,12 +171,28 @@ impl Tool for SpawnPipeline {
},
};
use std::sync::Arc;
let live: Option<crate::app::workflow::engine::LiveStateFn> = _ctx.turn_events.as_ref().map(|turn_events| {
let turn_events = turn_events.clone();
let f: crate::app::workflow::engine::LiveStateFn = Arc::new(move |agent_id: String, status| {
let name = agent_id.chars().take(30).collect::<String>();
if let Ok(mut q) = turn_events.lock() {
q.push_back(crate::app::state::runtime::TurnEvent::WorkflowAgentUpdate {
agent_id,
agent_name: name,
status,
});
}
});
f
});
let results = crate::app::workflow::engine::execute_primitive(
&wf.script,
&HashMap::new(),
1,
false,
None,
live.as_ref(),
)?;
format_results(results, "pipeline")
}