cline-sdk
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCline SDK Skill
Cline SDK 技能指南
Consolidated skill for building AI agents with the Cline SDK. Use the decision trees below to find the right entry point and API surface, then load detailed references.
这是一份使用Cline SDK构建AI Agent的综合技能指南。使用下方的决策树找到合适的入口点和API层面,然后查看详细参考文档。
Critical Rules
关键规则
Follow these rules in all Cline SDK code:
- Install with . The
npm install @cline/sdkpackage re-exports everything from@cline/sdk,@cline/core,@cline/agents, and@cline/llms.@cline/shared - Requires Node.js 22 or later.
- Use from
createTool()(or@cline/sdk) to define tools. Tool names must be@cline/shared.snake_case - Return errors as structured data from tool functions. Throwing counts as a "mistake" against the agent's mistake limit.
execute - Use on tools that should end the agent loop (e.g. a "submit answer" tool).
lifecycle: { completesRun: true } - When using , always call
ClineCorewhen done to clean up resources.dispose() - The standalone and
Agenthave different event systems. ForClineCore: useAgentto getagent.subscribe()types (text streaming isAgentRuntimeEvent, result text is"assistant-text-delta"). Forresult.outputText: useClineCoreto getcline.subscribe()types (text streaming isCoreSessionEventwith"chunk", result text ispayload.type === "text"). There is no top-levelresult.textfield ononEvent-- useAgentRuntimeConfigoragent.subscribe()instead. Do not use event types likehooks.onEventor"content_update"with"content_start"-- those are internal legacy types from the ClineCore adapter layer.agent.subscribe()
在所有Cline SDK代码中请遵循以下规则:
- 使用进行安装。
npm install @cline/sdk包会重新导出@cline/sdk、@cline/core、@cline/agents和@cline/llms中的所有内容。@cline/shared - 需要Node.js 22或更高版本。
- 使用(或
@cline/sdk)中的@cline/shared来定义工具。工具名称必须为createTool()格式。snake_case - 从工具的函数中以结构化数据形式返回错误。抛出错误会被计入Agent的错误次数限制。
execute - 对于应终止Agent循环的工具(例如“提交答案”工具),请设置。
lifecycle: { completesRun: true } - 使用时,使用完毕后务必调用
ClineCore来清理资源。dispose() - 独立的和
Agent拥有不同的事件系统。对于ClineCore:使用Agent来获取agent.subscribe()类型(文本流为AgentRuntimeEvent,结果文本为"assistant-text-delta")。对于result.outputText:使用ClineCore来获取cline.subscribe()类型(文本流为CoreSessionEvent且"chunk",结果文本为payload.type === "text")。result.text没有顶层的AgentRuntimeConfig字段——请改用onEvent或agent.subscribe()。不要在hooks.onEvent中使用agent.subscribe()或"content_update"等事件类型——这些是ClineCore适配层的内部遗留类型。"content_start"
How to Use This Skill
如何使用本技能指南
Reference File Structure
参考文件结构
The two main API surfaces ( and ) follow a 4-file pattern. Cross-cutting concepts are single-file guides.
AgentClineCoreEach main API surface in contains:
./references/<api>/| File | Purpose | When to Read |
|---|---|---|
| Overview, when to use, quick start | Always read first |
| Full API: classes, methods, config, types | Writing code |
| Common patterns, best practices | Implementation guidance |
| Pitfalls, limitations, debugging | Troubleshooting |
Cross-cutting concepts in have as the entry point.
./references/<concept>/REFERENCE.md两个主要的API层面(和)遵循4文件模式。跨领域概念为单文件指南。
AgentClineCore./references/<api>/| 文件 | 用途 | 阅读时机 |
|---|---|---|
| 概述、适用场景、快速入门 | 务必首先阅读 |
| 完整API:类、方法、配置、类型 | 编写代码时 |
| 常见模式、最佳实践 | 实现指导 |
| 陷阱、限制、调试方法 | 故障排查时 |
./references/<concept>/REFERENCE.mdReading Order
阅读顺序
- Start with for your chosen API surface
REFERENCE.md - Then read additional files relevant to your task:
- Writing agent code ->
api.md - Common patterns ->
patterns.md - Creating tools ->
tools/REFERENCE.md - Adding plugins/hooks ->
plugins/REFERENCE.md - Configuring LLM providers ->
providers/REFERENCE.md - Streaming events ->
events/REFERENCE.md - Deploying to production ->
production/REFERENCE.md - Scheduling agents ->
scheduling/REFERENCE.md - Multi-agent orchestration ->
multi-agent/REFERENCE.md - Debugging ->
gotchas.md
- Writing agent code ->
- 从所选API层面的开始
REFERENCE.md - 然后阅读与任务相关的其他文件:
- 编写Agent代码 ->
api.md - 常见模式 ->
patterns.md - 创建工具 ->
tools/REFERENCE.md - 添加插件/钩子 ->
plugins/REFERENCE.md - 配置LLM提供商 ->
providers/REFERENCE.md - 流事件处理 ->
events/REFERENCE.md - 生产部署 ->
production/REFERENCE.md - Agent任务调度 ->
scheduling/REFERENCE.md - 多Agent编排 ->
multi-agent/REFERENCE.md - 调试 ->
gotchas.md
- 编写Agent代码 ->
Example Paths
示例路径
./references/agent/REFERENCE.md # Start here for lightweight agents
./references/clinecore/REFERENCE.md # Start here for full runtime
./references/agent/api.md # Agent class, config, methods
./references/tools/REFERENCE.md # Creating and using tools
./references/plugins/REFERENCE.md # Plugin system
./references/providers/REFERENCE.md # LLM provider configuration./references/agent/REFERENCE.md # 轻量级Agent从这里开始
./references/clinecore/REFERENCE.md # 完整运行时从这里开始
./references/agent/api.md # Agent类、配置、方法
./references/tools/REFERENCE.md # 创建和使用工具
./references/plugins/REFERENCE.md # 插件系统
./references/providers/REFERENCE.md # LLM提供商配置Quick Decision Trees
快速决策树
"Which API surface should I use?"
“我应该使用哪个API层面?”
Which API?
+-- I want a simple, stateless agent with custom tools
| +-- agent/ (Agent class from @cline/agents)
+-- I need session persistence, built-in tools, config discovery
| +-- clinecore/ (ClineCore from @cline/core)
+-- I want built-in file/shell/search/web tools
| +-- clinecore/ (has built-in tools; Agent does not)
+-- I want scheduled or recurring agents
| +-- clinecore/ (automation API)
+-- I need multi-process or multi-client session sharing
| +-- clinecore/ (hub-backed runtime)
+-- I'm building a browser-compatible agent
| +-- agent/ (no Node.js dependencies)选择哪个API?
+-- 我想要一个带自定义工具的简单无状态Agent
| +-- agent/(来自@cline/agents的Agent类)
+-- 我需要会话持久化、内置工具、配置发现
| +-- clinecore/(来自@cline/core的ClineCore)
+-- 我想要内置的文件/Shell/搜索/网络工具
| +-- clinecore/(包含内置工具;Agent没有)
+-- 我想要定时或周期性运行的Agent
| +-- clinecore/(自动化API)
+-- 我需要多进程或多客户端会话共享
| +-- clinecore/(基于hub的运行时)
+-- 我正在构建兼容浏览器的Agent
| +-- agent/(无Node.js依赖)"I need to create tools"
“我需要创建工具”
Tools?
+-- Define a custom tool with schema -> tools/REFERENCE.md
+-- Use built-in tools (bash, editor, read_files) -> tools/REFERENCE.md (built-in section)
+-- Control tool approval/policies -> tools/REFERENCE.md (policies section)
+-- Tool that ends the agent loop -> tools/REFERENCE.md (completion tools)
+-- Package tools as a reusable plugin -> plugins/REFERENCE.md工具相关?
+-- 定义带Schema的自定义工具 -> tools/REFERENCE.md
+-- 使用内置工具(bash、编辑器、read_files) -> tools/REFERENCE.md(内置工具章节)
+-- 控制工具审批/策略 -> tools/REFERENCE.md(策略章节)
+-- 可终止Agent循环的工具 -> tools/REFERENCE.md(完成型工具章节)
+-- 将工具打包为可复用插件 -> plugins/REFERENCE.md"I need to handle events"
“我需要处理事件”
Events?
+-- Stream text/reasoning in real time -> events/REFERENCE.md
+-- Track token usage and costs -> events/REFERENCE.md
+-- Watch tool calls -> events/REFERENCE.md
+-- Detect completion/errors -> events/REFERENCE.md
+-- Hook into lifecycle stages -> plugins/REFERENCE.md事件相关?
+-- 实时流式传输文本/推理过程 -> events/REFERENCE.md
+-- 跟踪Token使用量和成本 -> events/REFERENCE.md
+-- 监控工具调用 -> events/REFERENCE.md
+-- 检测完成/错误 -> events/REFERENCE.md
+-- 挂钩到生命周期阶段 -> plugins/REFERENCE.md"I need to configure a model provider"
“我需要配置模型提供商”
Providers?
+-- Anthropic (Claude) -> providers/REFERENCE.md
+-- OpenAI (GPT) -> providers/REFERENCE.md
+-- Google (Gemini/Vertex) -> providers/REFERENCE.md
+-- AWS Bedrock -> providers/REFERENCE.md
+-- Mistral -> providers/REFERENCE.md
+-- OpenAI-compatible (vLLM, Together, etc.) -> providers/REFERENCE.md
+-- Custom/self-hosted provider -> providers/REFERENCE.md提供商相关?
+-- Anthropic(Claude) -> providers/REFERENCE.md
+-- OpenAI(GPT) -> providers/REFERENCE.md
+-- Google(Gemini/Vertex) -> providers/REFERENCE.md
+-- AWS Bedrock -> providers/REFERENCE.md
+-- Mistral -> providers/REFERENCE.md
+-- 兼容OpenAI的提供商(vLLM、Together等) -> providers/REFERENCE.md
+-- 自定义/自托管提供商 -> providers/REFERENCE.md"I need plugins or hooks"
“我需要插件或钩子”
Plugins?
+-- Package tools + hooks together -> plugins/REFERENCE.md
+-- Observe tool calls (logging, metrics) -> plugins/REFERENCE.md
+-- Intercept lifecycle events -> plugins/REFERENCE.md
+-- Add system prompt rules -> plugins/REFERENCE.md
+-- Distribute via npm/git -> plugins/REFERENCE.md插件相关?
+-- 将工具+钩子打包在一起 -> plugins/REFERENCE.md
+-- 监控工具调用(日志、指标) -> plugins/REFERENCE.md
+-- 拦截生命周期事件 -> plugins/REFERENCE.md
+-- 添加系统提示规则 -> plugins/REFERENCE.md
+-- 通过npm/git分发 -> plugins/REFERENCE.md"I need multi-agent coordination"
“我需要多Agent协作”
Multi-agent?
+-- Spawn one-off background agents -> multi-agent/REFERENCE.md (sub-agents)
+-- Persistent cross-session teams -> multi-agent/REFERENCE.md (teams)
+-- Parent-child delegation -> multi-agent/REFERENCE.md (sub-agents)
+-- Peer-to-peer task board -> multi-agent/REFERENCE.md (teams)多Agent相关?
+-- 生成一次性后台Agent -> multi-agent/REFERENCE.md(子Agent章节)
+-- 跨会话持久化团队 -> multi-agent/REFERENCE.md(团队章节)
+-- 父-子任务委托 -> multi-agent/REFERENCE.md(子Agent章节)
+-- 对等任务看板 -> multi-agent/REFERENCE.md(团队章节)"I need scheduling or automation"
“我需要任务调度或自动化”
Scheduling?
+-- Recurring cron jobs -> scheduling/REFERENCE.md
+-- One-off scheduled tasks -> scheduling/REFERENCE.md
+-- Event-driven triggers -> scheduling/REFERENCE.md
+-- CLI schedule management -> scheduling/REFERENCE.md调度相关?
+-- 周期性Cron任务 -> scheduling/REFERENCE.md
+-- 一次性定时任务 -> scheduling/REFERENCE.md
+-- 事件驱动触发器 -> scheduling/REFERENCE.md
+-- CLI调度管理 -> scheduling/REFERENCE.md"I need to go to production"
“我需要部署到生产环境”
Production?
+-- Error handling and status checks -> production/REFERENCE.md
+-- Cost control and token limits -> production/REFERENCE.md
+-- Observability (OpenTelemetry) -> production/REFERENCE.md
+-- Security and sandboxing -> production/REFERENCE.md
+-- Deployment patterns -> production/REFERENCE.md生产环境相关?
+-- 错误处理和状态检查 -> production/REFERENCE.md
+-- 成本控制和Token限制 -> production/REFERENCE.md
+-- 可观测性(OpenTelemetry) -> production/REFERENCE.md
+-- 安全和沙箱 -> production/REFERENCE.md
+-- 部署模式 -> production/REFERENCE.mdTroubleshooting Index
故障排查索引
- Agent loop not stopping -> (completion tools)
tools/REFERENCE.md - Tool errors crashing the agent -> or
agent/gotchas.mdclinecore/gotchas.md - Provider auth failures ->
providers/REFERENCE.md - Session not persisting ->
clinecore/gotchas.md - Token usage too high -> (cost control)
production/REFERENCE.md - Hub connection issues ->
clinecore/gotchas.md - Plugin not loading ->
plugins/REFERENCE.md - Events not firing ->
events/REFERENCE.md
- Agent循环无法停止 -> (完成型工具章节)
tools/REFERENCE.md - 工具错误导致Agent崩溃 -> 或
agent/gotchas.mdclinecore/gotchas.md - 提供商认证失败 ->
providers/REFERENCE.md - 会话无法持久化 ->
clinecore/gotchas.md - Token使用量过高 -> (成本控制章节)
production/REFERENCE.md - Hub连接问题 ->
clinecore/gotchas.md - 插件无法加载 ->
plugins/REFERENCE.md - 事件未触发 ->
events/REFERENCE.md
Product Index
产品索引
API Surfaces
API层面
| API | Entry File | Description |
|---|---|---|
| Agent | | Lightweight stateless agent loop |
| ClineCore | | Full runtime with sessions, persistence, built-in tools |
| API | 入口文件 | 描述 |
|---|---|---|
| Agent | | 轻量级无状态Agent循环 |
| ClineCore | | 包含会话、持久化、内置工具的完整运行时 |
Cross-Cutting Concepts
跨领域概念
| Concept | Entry File | Description |
|---|---|---|
| Tools | | Built-in and custom tool creation |
| Plugins | | Extension system with hooks |
| Events | | Real-time streaming events |
| Providers | | LLM provider configuration |
| Production | | Deployment, security, observability |
| Scheduling | | Cron jobs and automation |
| Multi-Agent | | Teams and sub-agents |
| 概念 | 入口文件 | 描述 |
|---|---|---|
| Tools | | 内置工具和自定义工具创建 |
| Plugins | | 带钩子的扩展系统 |
| Events | | 实时流事件 |
| Providers | | LLM提供商配置 |
| Production | | 部署、安全、可观测性 |
| Scheduling | | Cron任务和自动化 |
| Multi-Agent | | 团队和子Agent |
Package Map
包映射
| Package | Purpose |
|---|---|
| Everything you need, install this one |
| Sessions, persistence, built-in tools, config, hub |
| Stateless agent loop, tool orchestration, streaming |
| LLM provider gateway |
| Types, tool helpers, hook engine |
| 包 | 用途 |
|---|---|
| 所需全部内容,安装这一个即可 |
| 会话、持久化、内置工具、配置、hub |
| 无状态Agent循环、工具编排、流处理 |
| LLM提供商网关 |
| 类型、工具助手、钩子引擎 |
Resources
资源
Repository: https://github.com/cline/cline
SDK Source: https://github.com/cline/cline/tree/main/sdk
Documentation: https://docs.cline.bot/sdk/overview
Discord: https://discord.gg/cline