Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,12 @@ export class AnthropicContentGenerator implements ContentGenerator {
const { system, messages } =
this.converter.convertGeminiRequestToAnthropic(request);

const tools = request.config?.tools
? await this.converter.convertGeminiToolsToAnthropic(request.config.tools)
: undefined;
const tools =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Critical] The Anthropic path still allows an empty converted tool list to flow into the request. In buildRequest(), the new guard only checks that request.config.tools.length > 0 before calling convertGeminiToolsToAnthropic(), but that converter can legally return [] after filtering out invalid declarations (for example, functions missing name or description). In that case this code still sends tools: [], which is the same validation problem this PR is fixing in the OpenAI/logging paths.

Suggested change
const tools =
const tools =
request.config?.tools && request.config.tools.length > 0
? await this.converter.convertGeminiToolsToAnthropic(
request.config.tools,
)
: undefined;
const sampling = this.buildSamplingParameters(request);
const thinking = this.buildThinkingConfig(request);
const outputConfig = this.buildOutputConfig();
return {
model: this.contentGeneratorConfig.model,
system,
messages,
...(tools && tools.length > 0 ? { tools } : {}),
...sampling,
...(thinking ? { thinking } : {}),
...(outputConfig ? { output_config: outputConfig } : {}),
};

— gpt-5.4 via Qwen Code /review

request.config?.tools && request.config.tools.length > 0
? await this.converter.convertGeminiToolsToAnthropic(
request.config.tools,
)
: undefined;

const sampling = this.buildSamplingParameters(request);
const thinking = this.buildThinkingConfig(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,13 @@ export class LoggingContentGenerator implements ContentGenerator {
messages,
};

if (request.config?.tools) {
openaiRequest.tools = await converter.convertGeminiToolsToOpenAI(
if (request.config?.tools && request.config.tools.length > 0) {
const tools = await converter.convertGeminiToolsToOpenAI(
request.config.tools,
);
if (tools.length > 0) {
openaiRequest.tools = tools;
}
}

if (request.config?.temperature !== undefined) {
Expand Down
9 changes: 6 additions & 3 deletions packages/core/src/core/openaiContentGenerator/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,14 @@ export class ContentGenerationPipeline {
baseRequest.stream_options = { include_usage: true };
}

// Add tools if present
if (request.config?.tools) {
baseRequest.tools = await this.converter.convertGeminiToolsToOpenAI(
// Add tools if present — omit empty array to avoid API validation errors
if (request.config?.tools && request.config.tools.length > 0) {
const tools = await this.converter.convertGeminiToolsToOpenAI(
request.config.tools,
);
if (tools.length > 0) {
baseRequest.tools = tools;
}
}

// Let provider enhance the request (e.g., add metadata, cache control)
Expand Down
Loading