fix(tools): strip xAI-unsupported JSON Schema keywords from tool definitions

xAI rejects minLength, maxLength, minItems, maxItems, minContains, and
maxContains in tool schemas with a 502 error instead of ignoring them.
This causes all requests to fail when any tool definition includes these
validation-constraint keywords (e.g. sessions_spawn uses maxLength and
maxItems on its attachment fields).

Add stripXaiUnsupportedKeywords() in schema/clean-for-xai.ts, mirroring
the existing cleanSchemaForGemini() pattern. Apply it in normalizeToolParameters()
when the provider is xai directly, or openrouter with an x-ai/* model id.

Fixes tool calls for x-ai/grok-* models both direct and via OpenRouter.
This commit is contained in:
Jason Separovic
2026-03-02 09:59:49 -08:00
committed by Peter Steinberger
parent da05395c2a
commit 00347bda75
4 changed files with 221 additions and 12 deletions

View File

@@ -524,7 +524,10 @@ export function createOpenClawCodingTools(options?: {
// Without this, some providers (notably OpenAI) will reject root-level union schemas.
// Provider-specific cleaning: Gemini needs constraint keywords stripped, but Anthropic expects them.
const normalized = subagentFiltered.map((tool) =>
normalizeToolParameters(tool, { modelProvider: options?.modelProvider }),
normalizeToolParameters(tool, {
modelProvider: options?.modelProvider,
modelId: options?.modelId,
}),
);
const withHooks = normalized.map((tool) =>
wrapToolWithBeforeToolCallHook(tool, {