Repository navigation
fix(agents): omit empty tools array in OpenAI transport params - #61147
GitZhangChi wants to merge 1 commit into
Conversation
Greptile SummaryTargeted fix for strict OpenAI-compatible providers that reject requests with an empty Confidence Score: 5/5Safe to merge — the fix is correct and targeted with no blocking issues. All findings are P2 style suggestions. The core logic is sound: the length guard correctly prevents empty tools arrays from being sent to strict providers, and the hasToolHistory removal is safe because OpenAI does not require the tools parameter to be present when tool calls appear in message history. 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: 1302-1306
Comment:
**Redundant inner length guard**
`convertTools` is a pure `.map()` over every entry (lines 1258–1266) and cannot filter or drop items, so `converted.length` is always equal to `context.tools.length`. Because the outer guard already ensures `context.tools.length > 0`, the inner `converted.length > 0` check is always `true` and can never fire. It may mislead readers into thinking `convertTools` can produce fewer items than its input (e.g. if it were filtering unsupported tools). Consider simplifying:
```suggestion
if (context.tools && context.tools.length > 0) {
params.tools = convertTools(context.tools, compat, model);
}
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(agents): skip empty tools array in O..." | Re-trigger Greptile |
Only set params.tools when context.tools is non-empty — the old code called convertTools([]) and forwarded tools:[] to the provider, which strict OpenAI-compatible providers reject with a 400. Also drops the hasToolHistory fallback that unconditionally sent tools:[] whenever prior tool calls appeared in message history; OpenAI does not require the field to be present in that case. convertTools is a pure .map() so the outer length guard is sufficient. Tests: assert tools key is absent when context.tools is empty, and when tool call history exists but no tools are currently registered.
Summary
Old code could send
tools: []in two cases: whencontext.toolsexisted but was empty, and whenhasToolHistoryinferred prior tool calls from message history. Strict OpenAI-compatible providers (e.g. vLLM, LocalAI) reject requests with an emptytoolsarray, causing inference to fail even when no tools should be active.This change only sets
params.toolswhencontext.tools.length > 0, and removes the now-unneededhasToolHistoryfallback. No changes to tool conversion, compat flags, or provider routing.Change Type
Scope
Root Cause
Two paths could emit
tools: []:context.toolswas truthy but empty, soconvertTools([])produced[]and forwarded it.hasToolHistoryunconditionally setparams.tools = []when prior tool calls existed in message history, even if no tools were currently registered.Targeted regression coverage was missing for the no-active-tools path.
Regression Test Plan
src/agents/openai-transport-stream.test.tstoolsis omitted whencontext.toolsis emptytoolsis omitted when tool call history exists but no tools are currently registeredUser-visible / Behavior Changes
Requests to strict OpenAI-compatible providers (e.g. vLLM, LocalAI) no longer fail due to an empty
toolsarray when no tools are active for the current turn.Repro + Verification
Environment
Evidence
pnpm lintpnpm checkCompatibility / Migration
Risks and Mitigations
Omitting an empty
toolsfield is the correct OpenAI-compatible behavior. Providers that need explicit tool disablement should usetool_choice: "none"rather than rely ontools: [].