Skip to content

Duclaw SDK类型化 Agent 运行时契约

通过显式注入 LLM、Storage、Tool、Event 和 Channel 依赖来组合 Agent。

安装

sh
npm install duclaw-cli

TypeScript 项目请补一个能解析 SDK subpath export 的 tsconfig.json

json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "strict": true,
    "skipLibCheck": true,
    "types": ["node"]
  }
}

继续阅读 SDK 概览,或直接查看 Core API

最小运行时

ts
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" },
});

随 duclaw-cli package 一起发布。