Fix output() tool for forked agents: extract from AST after tool turns
The old dispatch_tools intercepted output() calls and stored them in auto.outputs. The new Agent::turn() dispatches normally, so output() was hitting the filesystem path (which fails without POC_AGENT_OUTPUT_DIR). Now run_with_backend scans the conversation AST after each tool turn and extracts output() call arguments into auto.outputs. collect_results in dmn.rs reads these to surface memories and inject reflections. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
fba8fcc587
commit
33ed54396c
1 changed files with 22 additions and 0 deletions
|
|
@ -165,6 +165,28 @@ impl AutoAgent {
|
|||
.map_err(|e| format!("{}: {}", self.name, e))?;
|
||||
|
||||
if result.had_tool_calls {
|
||||
// Extract output() calls from the conversation
|
||||
let ctx = backend.0.context.lock().await;
|
||||
for node in ctx.conversation() {
|
||||
if let super::context::AstNode::Branch { children, .. } = node {
|
||||
for child in children {
|
||||
if let Some(leaf) = child.leaf() {
|
||||
if let super::context::NodeBody::ToolCall { name, arguments } = leaf.body() {
|
||||
if name == "output" {
|
||||
if let Ok(args) = serde_json::from_str::<serde_json::Value>(arguments) {
|
||||
let key = args["key"].as_str().unwrap_or("");
|
||||
let value = args["value"].as_str().unwrap_or("");
|
||||
if !key.is_empty() {
|
||||
self.outputs.insert(key.to_string(), value.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
drop(ctx);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue