Skip to content

fix(provider): ensure OpenAI tool schemas use array required#2085

Open
cuipengcx90 wants to merge 1 commit into
MoonshotAI:mainfrom
cuipengcx90:fix/openai-tool-schema-required-array
Open

fix(provider): ensure OpenAI tool schemas use array required#2085
cuipengcx90 wants to merge 1 commit into
MoonshotAI:mainfrom
cuipengcx90:fix/openai-tool-schema-required-array

Conversation

@cuipengcx90

Copy link
Copy Markdown

Summary

  • OpenAI-compatible relays that forward to Moonshot backends validate tool parameters as Moonshot-flavored JSON Schema.
  • With providers.*.type = "openai", toolToOpenAI previously passed tool parameters through unchanged.
  • If any object schema had missing / non-array required, the upstream returns:
400 Invalid request: ***.***.parameters is not a valid moonshot flavored json schema
details: <At path 'required': required must be an array>
  • This PR makes toolToOpenAI force required: [] on type: "object" nodes when required is missing or not an array (both packages/kosong and packages/agent-core-v2).
  • The type = "kimi" path already runs normalizeKimiToolSchema; this closes the gap for the OpenAI wire used by third-party relays.

Test plan

  • pnpm --filter @moonshot-ai/kosong exec vitest run test/providers/openai-common-tool-schema.test.ts
  • CI full suite on this PR
  • Manual: kimi with type = "openai" against a Moonshot-strict relay, ensure tool-enabled turns no longer 400 on required

Notes

This is a focused wire-format compatibility fix. It does not change Anthropic/Google tool conversion.

OpenAI-compatible relays that forward to Moonshot backends validate tool
parameters as Moonshot-flavored JSON Schema and reject non-array `required`.
Normalize object schemas in toolToOpenAI so type=openai providers do not
fail with "required must be an array".
@changeset-bot

changeset-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 420dc20

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 420dc202fe

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

};
};

/**

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Move helper comments into the file header

In packages/agent-core-v2, the scoped convention allows comments only in the top-of-file /** */ header, so this new function-level JSDoc (and the helper JSDoc below it) makes the file violate the local comment rules. Please move the compatibility note into the module header or remove the inline blocks.

AGENTS.md reference: packages/agent-core-v2/AGENTS.md:L13-L13

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant