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

@@ -537,6 +537,34 @@ impl MitmStore {
std::mem::take(&mut *self.tool_rounds.write().await)
}
/// Push a new tool round from Google's response (calls only, results empty).
/// Called by proxy.rs when the MITM intercepts functionCall parts.
pub async fn push_tool_round_calls(&self, calls: Vec<CapturedFunctionCall>) {
if !calls.is_empty() {
self.tool_rounds.write().await.push(ToolRound {
calls,
results: Vec::new(),
});
}
}
/// Attach tool results to the latest incomplete tool round (one with empty results).
/// Called by responses.rs/gemini.rs when the client sends tool results.
/// If there's no open round, creates a legacy round with no calls.
pub async fn attach_tool_round_results(&self, results: Vec<PendingToolResult>) {
let mut rounds = self.tool_rounds.write().await;
// Find the last round that has no results yet
if let Some(round) = rounds.iter_mut().rev().find(|r| r.results.is_empty()) {
round.results = results;
} else {
// No open round — probably a race or legacy path, create standalone
rounds.push(ToolRound {
calls: Vec::new(),
results,
});
}
}
// ── Direct response capture (bypass LS) ──────────────────────────────
/// Set (replace) the captured response text.