kimi

package
v0.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package kimi is the provider-native Kimi (Moonshot) model adapter: an agentcore.ChatModel (llm.LLM) backed by Kimi's chat-completions API. Kimi's own API is OpenAI-shaped, so a plain net/http client IS native here, not a compatibility shim layered over a different provider, and it needs no SDK.

It is the anti-corruption layer between Kimi's wire format and agentcore types, so consumers never see a vendor type. Full scope: real SSE token streaming and tool calling, so kimi-k3 works as a primary conversational model. Kimi-specific extensions beyond standard OpenAI are wired too:

  • reasoning_effort (kimi-k3 thinking), mapped from the call's thinking level, with the model's reasoning_content surfaced as an agentcore thinking block,
  • partial mode (prefix continuation), triggered by "partial": true metadata on a trailing assistant message,
  • EstimateTokens, over Kimi's /tokenizers/estimate-token-count endpoint.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter wraps Kimi's chat-completions API as an llm.LLM.

func New

func New(cfg Config) (*Adapter, error)

New builds an Adapter from config.

func (*Adapter) EstimateTokens

func (a *Adapter) EstimateTokens(ctx context.Context, msgs []ac.Message) (int, error)

EstimateTokens returns Kimi's server-side token estimate for the given messages under this adapter's model, via /tokenizers/estimate-token-count. Useful for pre-flight budgeting; it is not part of the llm.LLM port.

func (*Adapter) Generate

func (a *Adapter) Generate(ctx context.Context, msgs []ac.Message, tools []ac.ToolSpec, opts ...ac.CallOption) (*ac.LLMResponse, error)

Generate runs a one-shot chat completion.

func (*Adapter) GenerateStream

func (a *Adapter) GenerateStream(ctx context.Context, msgs []ac.Message, tools []ac.ToolSpec, opts ...ac.CallOption) (<-chan ac.StreamEvent, error)

GenerateStream runs a streaming chat completion, emitting the agentcore StreamEvent sequence the loop expects: thinking/text start-delta-end, tool-call start/delta/end with the completed call, a terminal done event carrying the fully assembled message + stop reason, and an error event on failure. reasoning_content deltas become thinking events.

func (*Adapter) ProviderName

func (a *Adapter) ProviderName() string

ProviderName implements agentcore.ProviderNamer.

func (*Adapter) SupportsTools

func (a *Adapter) SupportsTools() bool

SupportsTools reports true: this adapter wires OpenAI-format tool calling.

type Config

type Config struct {
	APIKey  string
	Model   string // e.g. "kimi-k3"
	BaseURL string
	// Meter, if set, receives token/latency Usage for every call.
	Meter llm.Meter
	// Temperature and TopP are optional sampler params. nil leaves them off the
	// wire (the model's own default). Set by a per-model profile.
	Temperature *float64
	TopP        *float64
}

Config configures the adapter. APIKey and Model are required; BaseURL defaults to Kimi's public endpoint (e.g. override for a gateway).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL