SIGN IN SIGN UP

feat(models): add Kimi (Moonshot AI) adaptation with dedicated provider and formatters (#2320)

Fixes #2213

### New implementations
(`io.agentscope.extensions.model.openai.compat.kimi`)
This PR adds first-class Kimi (Moonshot AI) support on top of the
OpenAI-compatible extension module, adapted to the latest official Kimi
open platform documentation (kimi-k3 / kimi-k2.7-code / kimi-k2.6 /
kimi-k2.5 / moonshot-v1 series).

- **`KimiFormatter`** — extends `OpenAIChatFormatter` with Kimi-specific
request adaptations. Unlike other vendors, Kimi's constraints differ per
model series, so the sanitization is model-aware:
- `temperature` / `top_p` / `frequency_penalty` / `presence_penalty` are
**fixed by the platform** on `kimi-*` models (the API rejects other
values) and are stripped from requests; they are passed through for the
`moonshot-v1` series, which still accepts them.
- `reasoning_effort` (`low` / `high` / `max`) is only supported by
`kimi-k3` and stripped on other models; `thinking_budget` is not a Kimi
parameter and always stripped (K2.x thinking is controlled via the
`thinking` body param instead).
- Only `max_tokens` is documented: `max_completion_tokens` (newer OpenAI
style) is mapped onto it.
- `tool_choice` matrix per the official guide: `auto` / `none` pass
through everywhere; `required` is kimi-k3-only and degraded to `auto` on
the K2.x series; forcing a **specific** function is incompatible with
thinking enabled (HTTP 400), so it is degraded to `auto` on
always-thinking models (`kimi-k3`, `kimi-k2.7-code`) and passed through
otherwise.
- The `strict` parameter in tool definitions is not sent (not documented
by Kimi).
- Assistant `reasoning_content` is preserved in the request history,
satisfying **Preserved Thinking** on `kimi-k3` / `kimi-k2.7-code` and
`thinking.keep = "all"` on `kimi-k2.6`.
- **`KimiMultiAgentFormatter`** — extends `OpenAIMultiAgentFormatter`,
reusing the same Kimi-specific sanitization and tool-choice handling.
- **`KimiModelProvider`** — resolves `kimi:<model>` ids through
`ModelRegistry` (Java SPI). Creates `OpenAIChatModel` instances
preconfigured with:
- base URL `https://api.moonshot.cn/v1` (consistent with
`KimiCredential.DEFAULT_BASE_URL`);
- API key from `ModelCreationContext`, then `MOONSHOT_API_KEY`, then
`KIMI_API_KEY`;
- `KimiFormatter` as the default formatter (a custom `Formatter`
component takes precedence);
- `nativeStructuredOutput` disabled by default (Kimi `response_format`
only supports `json_object`, agents fall back to the `generate_response`
tool) and `nativeStructuredOutputWithTools` disabled by default (Kimi
prioritises `response_format` over tool invocations); both re-enablable
via context options.
L
Leeaoyin committed
d3a9783ab6021567999f7b597046c6ce50c8c949
Parent: ef06c7a
Committed by GitHub <noreply@github.com> on 8/3/2026, 10:55:39 AM