Skip to content

Commit abdd004

Browse files
committed
Fix gemini_investigate: revert function-result role to "user" and thread functionCall.id through to functionResponse.id for Gemini 3 compatibility
The 2026-07-25 "context drift" fix changed function-result turns from role:"user" to role:"function", based on an older multi-turn doc example. That contract doesn't match Gemini 3 models (gemini-flash-latest now resolves to gemini-3.5-flash): current docs for generateContent with gemini-3.6-flash show function-result turns going back with role:"user", and functionResponse now also carrying an id echoing the model's original functionCall.id. This reverts the role and adds id-threading so both the original convention and Gemini 3's schema are satisfied.
1 parent 6addcf6 commit abdd004

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

connectors/gemini/delegate.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ export async function runInvestigation({ task, max_steps = 6 }) {
800800

801801
const responseParts = [];
802802
for (const part of functionCalls) {
803-
const { name, args } = part.functionCall;
803+
const { name, args, id } = part.functionCall;
804804
const fn = FUNCTIONS.find((f) => f.name === name);
805805
let resultText;
806806
if (!fn) {
@@ -813,9 +813,13 @@ export async function runInvestigation({ task, max_steps = 6 }) {
813813
}
814814
}
815815
transcript.push(`[step ${step}] ${name}(${JSON.stringify(args || {})}) -> ${resultText.length > 300 ? resultText.slice(0, 300) + "…" : resultText}`);
816-
responseParts.push({ functionResponse: { name, response: { result: resultText } } });
816+
// Gemini 3 (current generateContent contract, verified 2026-07-25): function-result
817+
// turns go back with role "user" (NOT "function" -- that was the older doc convention
818+
// and is rejected by Gemini 3 models), and functionResponse.id echoes the model's
819+
// original functionCall.id so the API can thread multi-call turns correctly.
820+
responseParts.push({ functionResponse: { name, id, response: { result: resultText } } });
817821
}
818-
contents.push({ role: "function", parts: responseParts });
822+
contents.push({ role: "user", parts: responseParts });
819823
}
820824

821825
return { answer: `(Investigation stopped after reaching the step cap of ${cappedSteps} without a final answer -- the task may need to be narrowed, or more steps requested up to the hard cap of ${HARD_MAX_STEPS}.)`, steps: cappedSteps, transcript };

0 commit comments

Comments
 (0)