feat: add turn_events to ToolCtx and implement live state updates in spawn tool
This commit is contained in:
+34
-2
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user