默认依赖倒置
Core API 定义稳定契约。应用显式注入 adapters、tools、storage 和 presets。
npm install duclaw-cliTypeScript 项目请补一个能解析 SDK subpath export 的 tsconfig.json:
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"skipLibCheck": true,
"types": ["node"]
}
}import {
anthropic,
createAgent,
memoryStorage,
tool,
} from "duclaw-cli/sdk";
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" },
},
required: ["accountId"],
},
async run({ accountId }) {
return { id: accountId, plan: "pro" };
},
}),
],
system: "You are a precise SDK example agent.",
});
const result = await agent.run({
input: "Check account acc_123.",
context: { userId: "developer" },
});