mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 19:05:11 +00:00
Fix Claude via Google APIs requiring tool call IDs (#653)
Claude models accessed through Google Cloud Code Assist API require explicit id fields in both functionCall and functionResponse parts. Without these IDs, the API returns 'tool_use.id: Field required' error. Add requiresToolCallId() helper to centralize the Claude model detection and include IDs in both tool call and tool result message conversions.
This commit is contained in:
parent
934e7e470b
commit
7a41975e9e
1 changed files with 10 additions and 0 deletions
|
|
@ -58,6 +58,13 @@ function resolveThoughtSignature(isSameProviderAndModel: boolean, signature: str
|
|||
return isSameProviderAndModel && isValidThoughtSignature(signature) ? signature : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Claude models via Google APIs require explicit tool call IDs in function calls/responses.
|
||||
*/
|
||||
export function requiresToolCallId(modelId: string): boolean {
|
||||
return modelId.startsWith("claude-");
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert internal messages to Gemini Content[] format.
|
||||
*/
|
||||
|
|
@ -128,6 +135,7 @@ export function convertMessages<T extends GoogleApiType>(model: Model<T>, contex
|
|||
functionCall: {
|
||||
name: block.name,
|
||||
args: block.arguments,
|
||||
...(requiresToolCallId(model.id) ? { id: block.id } : {}),
|
||||
},
|
||||
};
|
||||
const thoughtSignature = resolveThoughtSignature(isSameProviderAndModel, block.thoughtSignature);
|
||||
|
|
@ -169,12 +177,14 @@ export function convertMessages<T extends GoogleApiType>(model: Model<T>, contex
|
|||
},
|
||||
}));
|
||||
|
||||
const includeId = requiresToolCallId(model.id);
|
||||
const functionResponsePart: Part = {
|
||||
functionResponse: {
|
||||
name: msg.toolName,
|
||||
response: msg.isError ? { error: responseValue } : { output: responseValue },
|
||||
// Nest images inside functionResponse.parts for Gemini 3
|
||||
...(hasImages && supportsMultimodalFunctionResponse && { parts: imageParts }),
|
||||
...(includeId ? { id: msg.toolCallId } : {}),
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue