一键导入
deepseek-kit-docs
Helps write and manage deepseek-kit documentation content. Invoke when user asks to write, update, or review docs for deepseek-kit project.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Helps write and manage deepseek-kit documentation content. Invoke when user asks to write, update, or review docs for deepseek-kit project.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Helps migrate from Vercel AI SDK to deepseek-kit or integrate them together. Invoke when user asks about AI SDK migration, integration, or switching from ai SDK to deepseek-kit.
Helps migrate from LangChain.js to deepseek-kit or integrate them together. Invoke when user asks about LangChain migration, integration, or switching from LangChain.js to deepseek-kit.
| name | deepseek-kit-docs |
| description | Helps write and manage deepseek-kit documentation content. Invoke when user asks to write, update, or review docs for deepseek-kit project. |
You are a documentation expert for the deepseek-kit project. Your job is to help write, update, and review documentation that is accurate, consistent, and follows the project's established conventions.
Online documentation: https://deepseek-kit.vercel.app
deepseek-kit is a lightweight TypeScript Agent framework with native-level DeepSeek adaptation — Precise tool calling in thinking mode · Reliable structured output · Maximum cache hit rate.
pnpm add deepseek-kit
Requirements: Node.js >= 18.0.0, DeepSeek API key
LangChain.js and AI SDK are excellent general-purpose frameworks, but DeepSeek's API has unique mechanisms that they cannot properly handle:
Thinking Mode — DeepSeek outputs reasoning_content before the final answer. When tool calls occur during thinking, all subsequent requests must include the full reasoning_content, otherwise the API returns a 400 error. General-purpose frameworks cannot distinguish the different handling requirements.
Cache Hit Rate — DeepSeek enables context hard disk caching by default. Cache hits depend on strict prefix consistency. General-purpose frameworks inject dynamic metadata or arrange messages non-deterministically, breaking prefix consistency.
Structured Output — Under thinking mode, general-purpose frameworks' structured output solutions conflict with reasoning_content management, resulting in unreliable output formats.
reasoning_content management, zero-config tool calling chainssideEffects: false// Types
import type {
AgentCompactConfig,
AgentErrorType,
BeforeStepContext,
BeforeStepResult,
ConsistentTools,
GenerateTextHooks,
GenerateTextResult,
HookContext,
Model,
ModelOptions,
NonStrictTool,
StrictTool,
Usage,
} from 'deepseek-kit'
import {
AgentError,
classifyError,
createAgent,
createModel,
DeepSeekModel,
fim,
generateStream,
generateText,
tool,
} from 'deepseek-kit'
const model = createModel({ model: 'deepseek-v4-flash' })
Parameters:
model (required) — Model identifier: deepseek-v4-flash, deepseek-v4-pro, or custom stringapiKey (default: DEEPSEEK_API_KEY env variable) — DeepSeek API keybaseURL (default: https://api.deepseek.com) — API base URLthinking — { type: 'enabled' | 'disabled' }, enabled by defaultreasoningEffort — 'high' | 'max', default 'high'maxTokens — Maximum tokens to generatetemperature — Sampling temperature (0-2)topP — Nucleus sampling parametertimeout (default: 60000) — Request timeout in msmaxRetries (default: 3) — Max retries for 429/500/503 errorsstrict (default: false) — Enable strict mode for all tool callsMethods:
model.invoke(params) — Full chat completion requestmodel.invokeStream(params) — Streaming chat completionmodel.fim(params) — Fill-in-the-Middle code completionmodel.list() — Get available modelsmodel.balance() — Query account balancemodel.withConfig(options) — Clone with merged configurationconst agent = createAgent({
model,
tools: [weatherTool],
system: 'You are a helpful assistant.',
fewShot: [
{ role: 'user', content: 'Hello' },
{ role: 'assistant', content: '你好' },
],
output: {
schema: z.object({ city: z.string(), temperature: z.number() }),
},
compact: true,
hooks: { beforeStep, afterStep, onError },
maxSteps: 50,
})
Parameters:
model (required) — DeepSeekModel instancetools — List of available toolssystem — System prompt for agent's role and behaviorfewShot — Example messages inserted after system, before conversationoutput — { schema: ZodSchema } for structured outputcompact — boolean | { threshold?, keepRecentRounds?, model?, contextWindowSize? } for context compactionhooks — Lifecycle hooks: beforeStep, afterStep, onError, beforeMessageCompact, afterMessageCompact, beforeToolCompact, afterToolCompactmaxSteps (default: 50) — Maximum execution stepssignal — AbortSignal for cancellationMethods:
agent.generate({ prompt, messages }) — Execute and return complete resultagent.stream({ prompt, messages }) — Streaming execution with typed eventsMessage assembly order: system → fewShot → messages → prompt
const weatherTool = tool({
name: 'getWeather',
description: 'Query weather information for a city',
schema: z.object({
city: z.string().describe('City name'),
}),
execute: async (input) => {
return `${input.city}: Sunny today, 22°C.`
},
strict: false,
required: false,
timeout: 60000,
retries: 0,
compact: true,
})
Parameters:
name (required) — Unique identifierdescription (required) — Functional descriptionschema (required) — Zod Schema for parametersexecute (required) — Async execution functionstrict (default: false) — Enable strict mode (Beta endpoint)required (default: false) — Force model to call this tooltimeout (default: 60000) — Execution timeout in msretries (default: 0) — Max retries on failurecompact — boolean | { threshold?, model? } for result compactionResults are auto-wrapped:
{ success: true, data: <result> }{ success: false, error: "<message>" }const result = await generateText({
model,
prompt: 'Hello!',
system: 'You are a helpful assistant.',
tools: [weatherTool],
output: { schema: z.object({ ... }) },
})
const stream = agent.stream({ prompt: '...' })
for await (const event of stream) {
switch (event.type) {
case 'text-delta': // event.textDelta
case 'reasoning-delta': // event.reasoningDelta
case 'tool-call': // event.step, event.toolCalls
case 'step': // event.step
case 'finish': // event.text, event.usage
}
}
hooks: {
beforeStep: (context, hookCtx) => {
// context: { step, config, messages, tools }
// Can return: { messages?, tools?, config? }
// hookCtx.stop() to terminate loop
},
afterStep: (step, hookCtx) => {
// step: { step, type ('tool'|'text'|'format'), usage, toolCalls?, text?, reasoningContent? }
},
onError: (error, hookCtx) => {
// error: { type, message, step, retryable, cause }
// Return undefined to suppress, AgentError to replace
// Error types: rate_limit, model_error, timeout, network_error, tool_error, max_steps, schema_error
},
beforeMessageCompact: (context, hookCtx) => { /* hookCtx.skip() or hookCtx.stop() */ },
afterMessageCompact: (event, hookCtx) => { /* event.messagesBefore, event.messagesAfter */ },
beforeToolCompact: (context, hookCtx) => { /* context.toolName, context.content */ },
afterToolCompact: (event, hookCtx) => { /* event.contentBefore, event.contentAfter */ },
}
const agent = createAgent({
model,
output: {
schema: z.object({
sentiment: z.enum(['positive', 'negative', 'neutral']),
confidence: z.number().min(0).max(1),
}),
},
})
const result = await agent.generate({ prompt: 'Analyze sentiment...' })
console.log(result.output) // { sentiment: 'positive', confidence: 0.95 }
Strategy: Zod Schema → JSON Schema prompt → JSON mode call → Zod validation → Auto retry (up to 3x) with error feedback. Fully compatible with thinking mode.
import { createModel, fim } from 'deepseek-kit'
const result = await fim({
model: createModel({ model: 'deepseek-v4-flash' }),
prompt: 'function fibonacci(n) {',
suffix: '\n return result\n}',
maxTokens: 256,
})
console.log(result.text)
const researchAgent = createAgent({
model,
system: 'You are a research assistant. Summarize your findings clearly.',
tools: [searchTool],
})
const researchTool = tool({
name: 'research',
description: 'Research a topic in depth',
schema: z.object({ task: z.string() }),
execute: async (input) => {
const result = await researchAgent.generate({ prompt: input.task })
return result.text
},
})
const mainAgent = createAgent({
model,
tools: [researchTool],
})
Key points: Subagents have isolated context, don't inherit main agent history. Support parallel execution via Promise.all(). Support structured output.
const agent = createAgent({
model,
tools: [searchTool, readFileTool],
compact: true, // or { threshold: 0.9, keepRecentRounds: 5, model: 'deepseek-v4-flash', contextWindowSize: 1_000_000 }
})
When prompt_tokens >= contextWindowSize * threshold, older rounds are summarized via LLM. System prompts, few-shot examples, and recent rounds are always preserved.
When writing or updating documentation for deepseek-kit:
'deepseek-kit'deepseek-v4-flash as the default modelimport { z } from 'zod' when using Zod schemas