#21720: fix(#21546): OpenAI conditional tool-first prompt
commands
agents
size: S
## Summary
Add conditional for OpenAI/xAI models: User action requests = tool call FIRST, text AFTER. No acknowledgments before completion.
This ensures proper tool call ordering for OpenAI and Grok models.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR adds comprehensive support for Grok model families (grok-2, grok-3, grok-4) and introduces a tool-first behavior instruction for OpenAI/xAI models. The changes span three commits:
- **Extended Grok model prefix support**: Updated `live-model-filter.ts` to recognize grok-2 and grok-3 model families (previously only grok-4)
- **Model definitions registration**: Added `XAI_EXTRA_MODELS` array defining grok-3, grok-3-fast, grok-3-mini, grok-3-mini-fast, and grok-2-1212 with proper configuration including cost, context window, and max tokens
- **Responses API support**: Added `applyXaiResponsesApiConfig()` to enable native xAI server-side tools (web_search, x_search, code_execution)
- **Tool-first prompt instruction**: Added system prompt guidance directing OpenAI/Grok models to call tools first, then provide text responses
The changes ensure users receive clear API-level permission errors instead of silent crashes when their xAI key lacks access to a model, and improve tool call ordering for these model families.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- All changes are well-structured additions with proper test coverage. The new model definitions follow existing patterns, the system prompt addition is non-breaking, and the test suite validates the core functionality. The changes fix real issues (silent crashes, model recognition failures) without modifying existing behavior.
- No files require special attention
<sub>Last reviewed commit: 84ad852</sub>
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#11561: fix: respect supportsReasoningEffort compat flag for xAI/Grok reaso...
by baxter-lindsaar · 2026-02-08
76.1%
#22175: fix: support xai tool stream and compat flags
by ShunsukeHayashi · 2026-02-20
75.1%
#21599: fix(xai): extend Grok model prefix support + add native Responses A...
by RonySpark · 2026-02-20
74.3%
#9339: fix: enhance OpenAI compatibility for tool calling
by 0xrushi · 2026-02-05
73.9%
#12642: feat(tools): typed tool schemas for xAI/Grok compatibility
by 2nd-ren · 2026-02-09
73.4%
#12812: fix(transcript-policy): sanitize tool call IDs for all non-OpenAI p...
by justin-nevins · 2026-02-09
71.5%
#16298: feat(xai): switch grok-4-1-fast variants by thinking level
by avirweb · 2026-02-14
71.5%
#8270: fix: support snake_case 'tool_use' in transcript repair (#8264)
by heliosarchitect · 2026-02-03
71.3%
#7044: feat: Add local model tool calling support
by jokelord · 2026-02-02
71.2%
#20965: feat: Add comprehensive model configuration and discovery for various…
by rodeok · 2026-02-19
70.9%