Skip to content

Commit f64a922

Browse files
committed
perf(agent): append post-tool hook note in place
Addresses review feedback: append_post_tool_output receives the tool result by value, so push the hook note onto the existing buffer instead of allocating a new string and copying the (potentially large) tool output.
1 parent f992d1b commit f64a922

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/agent/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,17 @@ fn extract_exec_command(args: &Value) -> Option<String> {
291291
/// Ok/Err polarity so the model sees it alongside the tool's own output and can self-correct.
292292
fn append_post_tool_output(res: Result<String, String>, hook_out: &str) -> Result<String, String> {
293293
let note = format!("\n\n[post-tool hook]\n{hook_out}");
294+
// `res` is owned, so append the note onto the existing buffer in place rather than allocating a
295+
// fresh string and copying the (potentially large) tool output into it.
294296
match res {
295-
Ok(s) => Ok(format!("{s}{note}")),
296-
Err(s) => Err(format!("{s}{note}")),
297+
Ok(mut s) => {
298+
s.push_str(&note);
299+
Ok(s)
300+
}
301+
Err(mut s) => {
302+
s.push_str(&note);
303+
Err(s)
304+
}
297305
}
298306
}
299307

0 commit comments

Comments
 (0)