安装
安装已发布的 package:
sh
npm install duclaw-cliTypeScript 项目还需要安装编译器/运行辅助依赖,并使用能识别 package subpath exports 的解析模式:
sh
npm install -D typescript tsx @types/nodejson
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"skipLibCheck": true,
"types": ["node"]
}
}如果你使用 Vite 或其它 bundler,也可以使用 moduleResolution: "Bundler"。旧的 node 解析模式不会读取 SDK 的 subpath export map,可能会报 Cannot find module 'duclaw-cli/sdk'。
通用 Agent 组合使用 SDK 主入口:
ts
import {
anthropic,
createAgent,
memoryStorage,
tool,
} from "duclaw-cli/sdk";创建 Agent
ts
const agent = createAgent({
model: anthropic({ apiKey: process.env.ANTHROPIC_API_KEY! }),
storage: memoryStorage(),
tools: [
tool({
name: "lookup_account",
description: "Look up an account by id.",
inputSchema: {
type: "object",
properties: {
accountId: {
type: "string",
description: "Account id, for example acc_123.",
},
},
required: ["accountId"],
additionalProperties: false,
},
async run({ accountId }) {
return { id: accountId, plan: "pro" };
},
}),
],
system: "You are a precise SDK example agent.",
});运行请求
ts
const result = await agent.run({
input: "Check account acc_123.",
context: {
userId: "developer",
requestId: "request-001",
},
});
console.log(result.output);必需依赖
公开 SDK facade 需要这些依赖:
| 字段 | 用途 |
|---|---|
system | Agent 的运行时指令 |
model | Model contract 的实现 |
storage | 消息历史存储 |
tools | Agent 可用的 tool 定义 |
除非你导入 preset subpath,否则 SDK 不会创建 Duclaw 产品默认配置。