Repository navigation
fix(agents): default proxy completions tool choice - #71472
Conversation
Greptile SummaryThis PR defaults Confidence Score: 4/5Safe 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 No files require special attention. Prompt To Fix All With AIThis 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); | |||
There was a problem hiding this 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.
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.
steipete
left a comment
There was a problem hiding this comment.
Codex maintainer review: looks good to land.
What I checked:
- The behavior is gated to
openai-completionsrequest construction only whencontext.toolsproduces a non-emptytoolsarray, no explicitoptions.toolChoiceis 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/v1and still omitstool_choiceby default. - Explicit caller-provided
toolChoicestill wins. hasToolHistory()fallback that sendstools: []is unchanged and does not gettool_choice: "auto".
Verification:
pnpm test src/agents/openai-transport-stream.test.ts -t "tool_choice"
pnpm test src/agents/openai-transport-stream.test.tsResults: 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 nativetool_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.
Summary
Default
tool_choiceto"auto"for proxy-likeopenai-completionsendpoints 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-completionssetups, OpenClaw can send a non-emptytoolsarray without an explicittool_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
openai-completionsroutes via existing compat/capability detectiontoolsis non-empty andtoolChoiceis not explicitly provided, defaulttool_choiceto"auto"Tests
Added coverage for:
openai-completionsendpoints defaultingtool_choiceto"auto"tool_choiceby default