Skip to content

fix(agents): default proxy completions tool choice - #71472

Merged
steipete merged 2 commits into
openclaw:mainfrom
Speed-maker:main
Apr 25, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
Speed-maker:main

Conversation

@Speed-maker

Copy link
Copy Markdown
Contributor

Summary

Default tool_choice to "auto" for proxy-like openai-completions endpoints when tools are present and no explicit tool choice is set.

This keeps native OpenAI routes unchanged while improving tool-call behavior for custom/baseUrl OpenAI-compatible providers routed through a proxy.

Problem

In proxy-like openai-completions setups, OpenClaw can send a non-empty tools array without an explicit tool_choice. Some upstream OpenAI-compatible providers then fall back to plain-text behavior instead of entering native tool-calling flow.

That shows up as models emitting textual tool directives instead of actual tool calls.

Change

  • Detect proxy-like openai-completions routes via existing compat/capability detection
  • If tools is non-empty and toolChoice is not explicitly provided, default tool_choice to "auto"
  • Keep native OpenAI endpoints unchanged

Tests

Added coverage for:

  • proxy-like openai-completions endpoints defaulting tool_choice to "auto"
  • native OpenAI endpoints still omitting tool_choice by default

@greptile-apps

greptile-apps Bot commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR defaults tool_choice to "auto" for proxy-like openai-completions endpoints (those with a non-OpenAI/Azure configured baseUrl) when tools are present and no explicit toolChoice is set. The behavior is correctly gated on usesExplicitProxyLikeEndpoint, leaving native OpenAI routes unchanged.

Confidence Score: 4/5

Safe to merge; the logic is correct and well-tested, with only a minor redundancy to clean up.

Only P2 findings — a redundant double call to detectOpenAICompletionsCompat that has no behavioral impact. Core logic, guard conditions, and test coverage are all sound.

No files require special attention.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/openai-transport-stream.ts
Line: 1717

Comment:
**Redundant double call to `detectOpenAICompletionsCompat`**

`detectOpenAICompletionsCompat(model)` is already called inside `getCompat(model)` (via `detectCompat`), so this adds a second identical invocation for every request. The cleaner fix would be to expose `usesExplicitProxyLikeEndpoint` from `detectCompat`/`getCompat` directly, rather than calling `detectOpenAICompletionsCompat` a second time in `buildOpenAICompletionsParams`.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(agents): default proxy completions t..." | Re-trigger Greptile

@@ -1714,6 +1714,7 @@ export function buildOpenAICompletionsParams(
options: OpenAICompletionsOptions | undefined,
) {
const compat = getCompat(model);
const compatDetection = detectOpenAICompletionsCompat(model);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Redundant double call to detectOpenAICompletionsCompat

detectOpenAICompletionsCompat(model) is already called inside getCompat(model) (via detectCompat), so this adds a second identical invocation for every request. The cleaner fix would be to expose usesExplicitProxyLikeEndpoint from detectCompat/getCompat directly, rather than calling detectOpenAICompletionsCompat a second time in buildOpenAICompletionsParams.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/openai-transport-stream.ts
Line: 1717

Comment:
**Redundant double call to `detectOpenAICompletionsCompat`**

`detectOpenAICompletionsCompat(model)` is already called inside `getCompat(model)` (via `detectCompat`), so this adds a second identical invocation for every request. The cleaner fix would be to expose `usesExplicitProxyLikeEndpoint` from `detectCompat`/`getCompat` directly, rather than calling `detectOpenAICompletionsCompat` a second time in `buildOpenAICompletionsParams`.

How can I resolve this? If you propose a fix, please make it concise.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Apr 25, 2026

@steipete steipete left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Codex maintainer review: looks good to land.

What I checked:

  • The behavior is gated to openai-completions request construction only when context.tools produces a non-empty tools array, no explicit options.toolChoice is set, and the compat/capability layer marks the route as a configured non-native-OpenAI endpoint.
  • Native OpenAI remains unchanged: the new regression covers provider: "openai" + https://api.openai.com/v1 and still omits tool_choice by default.
  • Explicit caller-provided toolChoice still wins.
  • hasToolHistory() fallback that sends tools: [] is unchanged and does not get tool_choice: "auto".

Verification:

pnpm test src/agents/openai-transport-stream.test.ts -t "tool_choice"
pnpm test src/agents/openai-transport-stream.test.ts

Results: focused tool-choice tests passed (3 passed), full file passed (82 passed).

I also smoke-tested raw Ollama OpenAI-compatible requests with tool_choice: "auto":

  • local qwen3-coder:30b: accepted, returned native tool_calls.
  • Ollama Cloud kimi-k2.6:cloud: accepted the request, no schema rejection.

Only minor note: Greptile is right that detectOpenAICompletionsCompat(model) is called twice on this path (getCompat() already detects it). That is redundant, but it is pure local capability detection and not a correctness blocker.

@steipete
steipete merged commit 7711df0 into openclaw:main Apr 25, 2026
66 checks passed
Angfr95 pushed a commit to Angfr95/openclaw that referenced this pull request Apr 25, 2026
ayesha-aziz123 pushed a commit to ayesha-aziz123/openclaw that referenced this pull request Apr 26, 2026
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants