Skip to content

Tools

Tools 是暴露给 Agent 的类型化能力。

ts
import {
  tool,
  type Tool,
} from "duclaw-cli/sdk";

定义 Tool

ts
const lookupAccount = tool({
  name: "lookup_account",
  description: "Look up one 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" };
  },
});

Schema 兼容性

inputSchema 是 SDK 示例中使用的 TypeScript 友好字段。 复制 Anthropic tool definition 时,也可以使用 input_schema

ts
const lookupAccount = tool({
  name: "lookup_account",
  description: "Look up one account by id.",
  input_schema: {
    type: "object",
    properties: {
      accountId: { type: "string" },
    },
    required: ["accountId"],
  },
  async run(input) {
    return { id: input.accountId };
  },
});

不要同时传入不同内容的 inputSchemainput_schema。如果两者同时存在,它们应引用同一个 schema object。

随 duclaw-cli package 一起发布。