← Back to PRs

#9339: fix: enhance OpenAI compatibility for tool calling

by 0xrushi open 2026-02-05 04:08 View on GitHub →
agents stale size: S
Edit https://github.com/openclaw/openclaw/pull/4287 to be fix instead of feature <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds an opt-in compatibility flag (`compat.openaiCompletionsTools`) for `openai-completions` models to route the agent toolset through the SDK “built-in tools” path (instead of `customTools`). This is intended to improve tool-calling interoperability with some OpenAI-compatible servers that only honor `tools`/`tool_choice` on the `/v1/chat/completions` endpoint. Changes are implemented by extending `splitSdkTools` to optionally return `builtInTools=tools` and `customTools=[]`, and wiring that decision into both `runEmbeddedAttempt` and `compactEmbeddedPiSessionDirect`. Config schema/types and docs are updated, and tests are added to validate routing behavior and that `createAgentSession` receives tools in the expected field when the compat flag is enabled. <h3>Confidence Score: 4/5</h3> - This PR looks safe to merge and is largely additive, with behavior changes gated behind an explicit compat flag. - The routing change is opt-in (`compat.openaiCompletionsTools`) and is covered by focused unit tests. Main remaining concern is that enabling the flag bypasses the previous guarantee that all tools flow through the `customTools` path (where policy filtering/sandbox integration may live); if the built-in tool path doesn’t enforce the same restrictions, users could unintentionally weaken tool restrictions when they enable the compat flag. - src/agents/pi-embedded-runner/tool-split.ts; src/agents/pi-embedded-runner/run/attempt.ts; src/agents/pi-embedded-runner/compact.ts <!-- greptile_other_comments_section --> <sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub> **Context used:** - Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8)) - Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13)) <!-- /greptile_comment -->

Most Similar PRs