fix: extend multi-round tool history to responses and gemini endpoints

- proxy.rs: push_tool_round_calls alongside set_last_function_calls
  when Google responds with functionCall — accumulates rounds
- responses.rs: attach_tool_round_results to pair tool results with
  the correct round instead of flat add_tool_result
- gemini.rs: same attach_tool_round_results integration
- store.rs: add push_tool_round_calls and attach_tool_round_results
  methods for cross-request round accumulation
- Legacy add_tool_result kept for backward compat alongside new path
This commit is contained in:
Nikketryhard
2026-02-16 19:11:38 -06:00
parent 39381a4dfe
commit 32f02d6456
4 changed files with 60 additions and 6 deletions

View File

@@ -242,6 +242,7 @@ pub(crate) async fn handle_responses(
// Handle tool result submission (function_call_output in input)
let is_tool_result_turn = !tool_results.is_empty();
if is_tool_result_turn {
let mut pending: Vec<PendingToolResult> = Vec::new();
for tr in &tool_results {
// Look up function name from call_id
let name = state
@@ -254,17 +255,28 @@ pub(crate) async fn handle_responses(
let result_value = serde_json::from_str::<serde_json::Value>(&tr.output)
.unwrap_or_else(|_| serde_json::json!({"result": tr.output}));
// Also store as pending (legacy compat)
state
.mitm_store
.add_tool_result(PendingToolResult {
name,
result: result_value,
name: name.clone(),
result: result_value.clone(),
})
.await;
pending.push(PendingToolResult {
name,
result: result_value,
});
}
// Attach results to the latest open ToolRound (pushed by proxy.rs)
state
.mitm_store
.attach_tool_round_results(pending)
.await;
info!(
count = tool_results.len(),
"Stored tool results for MITM injection"
"Stored tool results for MITM injection (attached to tool round)"
);
}