#9339: fix: enhance OpenAI compatibility for tool calling
agents
stale
size: S
Cluster:
Error Handling in Agent Tools
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
#10975: fix: add missing clientTools parameter to runEmbeddedAttempt call
by xamdel · 2026-02-07
79.9%
#9511: feat: add tool error fallback toggle
by bolismauro · 2026-02-05
78.5%
#4767: fix(agents): handle read alias required schema
by RomeroYang · 2026-01-30
78.3%
#14734: test(agents): guard against stale allowAgents in existing sessions
by davidahmann · 2026-02-12
77.7%
#21195: fix: suppress orphaned tool_use/tool_result errors after session co...
by ruslansychov-git · 2026-02-19
77.4%
#8270: fix: support snake_case 'tool_use' in transcript repair (#8264)
by heliosarchitect · 2026-02-03
77.2%
#8312: fix: add logging and markers for tool result repair
by ekson73 · 2026-02-03
77.1%
#11854: fix: resolve per-agent tools.exec config in pi-tools
by Yida-Dev · 2026-02-08
77.1%
#11825: fix: keep tool_use/tool_result pairs together during session compac...
by C31gordon · 2026-02-08
76.5%
#19094: Fix empty tool_call_id and function names in provider transcript pa...
by yxshee · 2026-02-17
76.5%