AS AgentScopeAPI 手册 / API Reference

KimiFormatter

public class KimiFormatter extends OpenAIChatFormatter
源码Source io/agentscope/extensions/model/openai/compat/kimi/KimiFormatter.java:82–317

Kimi 格式化器,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.openai.compat.kimi 包,继承自 OpenAIChatFormatter。核心成员包括 supportsStrict、applyOptions、applyToolChoice、sanitizeKimiRequest、applyKimiToolChoice、KimiFormatter。

Formatter for Kimi (Moonshot AI) models (kimi-k3, kimi-k2.7-code, kimi-k2.6, kimi-k2.5, moonshot-v1 series).

Adapted to the latest Kimi open platform Chat Completions API (https://api.moonshot.cn/v1/chat/completions):

  • On kimi-* models, temperature / top_p / n / frequency_penalty / presence_penalty are fixed by the platform and the API rejects requests carrying other values; these parameters are stripped from the request. The moonshot-v1 series still accepts them, so they are kept there.

  • reasoning_effort ("low" / "high" / "max", default "max") is only supported by kimi-k3; it is stripped for other models

  • thinking_budget is not a Kimi parameter and is always stripped; K2.x thinking is controlled through the thinking body parameter instead (see below)

  • Only max_completion_tokens is documented; max_tokens is mapped to max_completion_tokens when the latter is not set. Reasoning tokens count towards max_completion_tokens, so the official guide recommends max_completion_tokens >= 16000 for thinking models

  • tool_choice supports auto / none on all models; required is 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 on kimi-k2.6 / kimi-k2.5 unless thinking is explicitly disabled

  • The strict parameter in tool definitions is not documented by Kimi and is not sent

  • Assistant reasoning_content is preserved in the request history (inherited from the base message converter), as required by Preserved Thinking on kimi-k3 / kimi-k2.7-code and by thinking.keep = "all" on kimi-k2.6

Thinking mode: kimi-k2.6 / kimi-k2.5 accept a thinking body parameter (e.g. {"type": "disabled"}), which can be passed through GenerateOptions.additionalBodyParam("thinking", Map.of("type", "disabled")). kimi-k3 uses the top-level reasoning_effort option (GenerateOptions.reasoningEffort) instead. JSON mode is enabled via response_format = {"type": "json_object"}; json_schema is not supported.

Usage:

`OpenAIChatModel.builder()
.formatter(new KimiFormatter())
.modelName("kimi-k3")
.baseUrl("https://api.moonshot.cn/v1")
.apiKey(apiKey)
.build();
`

构造器摘要Constructor Summary

构造器Constructor说明Description
public KimiFormatter()
初始化 `KimiFormatter` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
protected boolean supportsStrict()
返回 `supportsStrict` 结果。
Returns the supports strict.
public void applyOptions(OpenAIRequest request, GenerateOptions options, GenerateOptions defaultOptions)
应用选项。
Performs the apply options operation.
public void applyToolChoice(OpenAIRequest request, ToolChoice toolChoice)
应用工具选项。
Performs the apply tool choice operation.
protected static void sanitizeKimiRequest(OpenAIRequest request)
static
设置该参数。
Sanitize the request according to the Kimi Chat Completions API reference.
protected static void applyKimiToolChoice(OpenAIRequest request, ToolChoice toolChoice)
static
应用 `applyKimiToolChoice`。
Apply Kimi-specific tool choice handling.

构造器详情Constructor Detail

KimiFormatter

public KimiFormatter()

初始化 KimiFormatter 实例。

Creates a new instance.

源码Source io/agentscope/extensions/model/openai/compat/kimi/KimiFormatter.java:86–88

方法详情Method Detail

supportsStrict

protected boolean supportsStrict()

返回 supportsStrict 结果。

Returns the supports strict.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/extensions/model/openai/compat/kimi/KimiFormatter.java:90–93

applyOptions

public void applyOptions(OpenAIRequest request, GenerateOptions options, GenerateOptions defaultOptions)

应用选项。

Performs the apply options operation.

参数Parameters
名称Name类型Type说明Description
requestOpenAIRequest请求(类型 `OpenAIRequest`)。The request.
optionsGenerateOptions选项(类型 `GenerateOptions`)。The options.
defaultOptionsGenerateOptions默认选项(类型 `GenerateOptions`)。The default options.
源码Source io/agentscope/extensions/model/openai/compat/kimi/KimiFormatter.java:95–100

applyToolChoice

public void applyToolChoice(OpenAIRequest request, ToolChoice toolChoice)

应用工具选项。

Performs the apply tool choice operation.

参数Parameters
名称Name类型Type说明Description
requestOpenAIRequest请求(类型 `OpenAIRequest`)。The request.
toolChoiceToolChoice工具选项(类型 `ToolChoice`)。The tool choice.
源码Source io/agentscope/extensions/model/openai/compat/kimi/KimiFormatter.java:102–105

sanitizeKimiRequest

protected static void sanitizeKimiRequest(OpenAIRequest request)
static

设置该参数。

Sanitize the request according to the Kimi Chat Completions API reference.

参数Parameters
名称Name类型Type说明Description
requestOpenAIRequest请求(类型 `OpenAIRequest`)。the request to sanitize
源码Source io/agentscope/extensions/model/openai/compat/kimi/KimiFormatter.java:181–236

applyKimiToolChoice

protected static void applyKimiToolChoice(OpenAIRequest request, ToolChoice toolChoice)
static

应用 applyKimiToolChoice。

Apply Kimi-specific tool choice handling.

参数Parameters
名称Name类型Type说明Description
requestOpenAIRequest请求(类型 `OpenAIRequest`)。the request to apply tool choice to
toolChoiceToolChoice工具选项(类型 `ToolChoice`)。the requested tool choice
源码Source io/agentscope/extensions/model/openai/compat/kimi/KimiFormatter.java:257–302

继承成员Inherited Members

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.