adk

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Botpress ADK Guidelines

Botpress ADK 开发指南

Use this skill when you've got questions about the Botpress Agent Development Kit (ADK) - like when you're building a feature that involves tables, actions, tools, workflows, conversations, files, knowledge bases, triggers, or Zai.
当你对Botpress Agent Development Kit(ADK)有疑问时,可使用本技能——比如当你开发涉及表格、动作、工具、工作流、对话、文件、知识库、触发器或Zai的功能时。

What is the ADK?

什么是ADK?

The Botpress ADK is a convention-based TypeScript framework where file structure maps directly to bot behavior. Place files in the correct directories, and they automatically become available as bot capabilities.
The ADK provides primitives for:
  • Actions & Tools (reusable functions and AI-callable tools)
  • Workflows (long-running, resumable processes)
  • Conversations (message handling)
  • Tables (data storage with semantic search)
  • Files (file storage with semantic search)
  • Knowledge Bases (RAG implementation)
  • Triggers (event-driven automation)
  • Zai (production-ready LLM utility library for common AI operations)
Botpress ADK是一个基于约定的TypeScript框架,其文件结构直接对应机器人行为。将文件放置在正确的目录中,它们会自动成为机器人的可用功能。
ADK提供以下基础组件:
  • 动作与工具(可复用函数和AI可调用工具)
  • 工作流(长期运行、可恢复的流程)
  • 对话(消息处理)
  • 表格(带语义搜索的数据存储)
  • 文件(带语义搜索的文件存储)
  • 知识库(RAG实现)
  • 触发器(事件驱动的自动化)
  • Zai(用于常见AI操作的生产级LLM工具库)

Project Structure (Convention-Based)

项目结构(基于约定)

All primitives must be placed in
src/
directory:
/                      # Project root
├── src/
│   ├── actions/       # Strongly-typed functions → auto-registered
│   ├── tools/         # AI-callable tools → available via execute()
│   ├── workflows/     # Long-running processes → resumable/scheduled
│   ├── conversations/ # Message handlers → routes by channel
│   ├── tables/        # Database schemas → auto-created with search
│   ├── triggers/      # Event handlers → subscribe to events
│   ├── knowledge/     # Knowledge bases → RAG with semantic search
│   └── utils/         # Shared helpers (not auto-registered)
└── agent.config.ts    # Bot configuration (includes integrations)
Note:
dependencies.json
was removed in ADK 1.9+. All configuration including integrations now lives in
agent.config.ts
.
Critical: Files outside
src/
are not discovered. Location = behavior.
所有基础组件必须放置在
src/
目录中:
/                      # Project root
├── src/
│   ├── actions/       # Strongly-typed functions → auto-registered
│   ├── tools/         # AI-callable tools → available via execute()
│   ├── workflows/     # Long-running processes → resumable/scheduled
│   ├── conversations/ # Message handlers → routes by channel
│   ├── tables/        # Database schemas → auto-created with search
│   ├── triggers/      # Event handlers → subscribe to events
│   ├── knowledge/     # Knowledge bases → RAG with semantic search
│   └── utils/         # Shared helpers (not auto-registered)
└── agent.config.ts    # Bot configuration (includes integrations)
注意: 在ADK 1.9+版本中已移除
dependencies.json
。所有配置(包括集成)现在都存放在
agent.config.ts
中。
关键提示:
src/
目录外的文件不会被识别。位置决定行为。

When to Use This Skill

何时使用本技能

Activate this skill when users ask ADK-related questions like:
  • "How do I create an Action/Tool/Workflow/Conversation?"
  • "What is the difference between X and Y?"
  • "Show me an example of..."
  • "How do I configure...?"
  • "What's the CLI command for...?"
  • "How do I use the Context API?"
  • "How do I call integration actions?"
  • "How do I use Zai for [extract/check/label/etc]?"
  • "What are the best practices for...?"
  • "How do I avoid common mistakes?"
  • "How do I handle ticket assignment/escalation?"
当用户询问以下ADK相关问题时,启用本技能:
  • "如何创建Action/Tool/Workflow/Conversation?"
  • "X和Y之间有什么区别?"
  • "给我展示一个...的示例"
  • "如何配置...?"
  • "...对应的CLI命令是什么?"
  • "如何使用Context API?"
  • "如何调用集成动作?"
  • "如何使用Zai进行[提取/检查/标注等]操作?"
  • "...的最佳实践是什么?"
  • "如何避免常见错误?"
  • "如何处理工单分配/升级?"

How to Answer ADK Questions

如何解答ADK相关问题

ADK questions fall into two categories: CLI queries and documentation lookups.
ADK问题分为两类:CLI查询文档查阅

Option 1: Direct CLI Commands (FAST - Use First!)

选项1:直接使用CLI命令(快速优先!)

For integration discovery and CLI queries, use the Bash tool to run commands directly:
Integration Discovery:
bash
undefined
对于集成发现和CLI查询,使用Bash工具直接运行命令:
集成发现:
bash
undefined

Search for integrations

搜索集成

adk search <query>
adk search <query>

List all available integrations

列出所有可用集成

adk list --available
adk list --available

Get detailed integration info (actions, channels, events)

获取集成详细信息(动作、渠道、事件)

adk info <integration-name>
adk info <integration-name>

Check installed integrations (must be in ADK project)

检查已安装的集成(必须在ADK项目中)

adk list

**Project Info:**

```bash
adk list

**项目信息:**

```bash

Check CLI version

检查CLI版本

adk --version
adk --version

Show project status

查看项目状态

adk
adk

Get help

获取帮助

adk --help

**When to use CLI commands:**

- "What integrations are available?"
- "Search for Slack integration"
- "Show me details about the Linear integration"
- "What actions does the Slack integration have?"
- "What version of ADK am I using?"
- "How do I add an integration?"

**Response pattern:**

1. Use Bash tool to run the appropriate `adk` command
2. Parse and present the output to the user
3. Optionally suggest next steps (e.g., "Run `adk add slack@3.0.0` to install")
adk --help

**何时使用CLI命令:**

- "有哪些可用集成?"
- "搜索Slack集成"
- "展示Linear集成的详细信息"
- "Slack集成有哪些动作?"
- "我使用的ADK版本是多少?"
- "如何添加集成?"

**回复模式:**

1. 使用Bash工具运行合适的`adk`命令
2. 解析并向用户展示输出结果
3. 可选择建议后续步骤(例如:"运行`adk add slack@3.0.0`进行安装")

Option 2: Documentation Questions (For Conceptual Questions)

选项2:文档类问题(针对概念性问题)

For documentation, patterns, and how-to questions, search and reference the documentation files directly:
When to use documentation:
  • "How do I create a workflow?"
  • "What's the difference between Actions and Tools?"
  • "Show me an example of using Zai"
  • "What are best practices for state management?"
  • "How do I fix this error?"
  • "What's the pattern for X?"
How to answer documentation questions:
  1. Find relevant files - Use Glob to discover documentation:
    pattern: **/references/*.md
  2. Search for keywords - Use Grep to find relevant content:
    pattern: <keyword from user question>
    path: <path to references directory from step 1>
    output_mode: files_with_matches
  3. Read the files - Use Read to load relevant documentation
  4. Provide answer with:
    • Concise explanation
    • Code examples from the references
    • File references with line numbers (e.g., "From references/actions.md:215")
    • Common pitfalls if relevant
    • Related topics for further reading
对于文档、模式和操作类问题,直接搜索并参考文档文件:
何时查阅文档:
  • "如何创建工作流?"
  • "Actions和Tools之间有什么区别?"
  • "给我展示使用Zai的示例"
  • "状态管理的最佳实践是什么?"
  • "如何修复这个错误?"
  • "X的实现模式是什么?"
如何解答文档类问题:
  1. 查找相关文件 - 使用Glob工具发现文档:
    pattern: **/references/*.md
  2. 搜索关键词 - 使用Grep工具查找相关内容:
    pattern: <用户问题中的关键词>
    path: <步骤1中找到的参考目录路径>
    output_mode: files_with_matches
  3. 读取文件 - 使用Read工具加载相关文档
  4. 提供答案,包含:
    • 简洁的解释
    • 参考文档中的代码示例
    • 带行号的文件引用(例如:"来自references/actions.md:215")
    • 相关的常见陷阱
    • 可供进一步阅读的相关主题

Available Documentation

可用文档

Documentation should be located in
./references/
directory relative to this skill. When answering questions, search for these topics:
文档应位于本技能相对路径下的
./references/
目录中。解答问题时,可搜索以下主题:

Core Concepts

核心概念

  • actions.md - Actions with strong typing and validation
  • tools.md - AI-callable tools and Autonomous namespace
  • workflows.md - Workflows and step-based execution
  • conversations.md - Conversation handlers and message routing
  • triggers.md - Event-driven automation
  • messages.md - Sending messages and events
  • actions.md - 强类型和验证的Actions
  • tools.md - AI可调用工具与Autonomous命名空间
  • workflows.md - 工作流与基于步骤的执行
  • conversations.md - 对话处理与消息路由
  • triggers.md - 事件驱动的自动化
  • messages.md - 消息与事件发送

Data & Content

数据与内容

  • tables.md - Data storage with semantic search
  • files.md - File storage and management
  • knowledge-bases.md - RAG implementation
  • zai-complete-guide.md - Complete ZAI developer guide
  • zai-agent-reference.md - Quick ZAI reference
  • tables.md - 带语义搜索的数据存储
  • files.md - 文件存储与管理
  • knowledge-bases.md - RAG实现
  • zai-complete-guide.md - ZAI开发者完整指南
  • zai-agent-reference.md - ZAI快速参考

Configuration & Integration

配置与集成

  • agent-config.md - Bot configuration and state management
  • model-configuration.md - AI model configuration reference
  • context-api.md - Runtime context access
  • integration-actions.md - Using integration actions
  • tags.md - Entity tags for bot, user, conversation, and workflow
  • cli.md - Complete CLI command reference
  • mcp-server.md - MCP server for AI assistants
  • agent-config.md - 机器人配置与状态管理
  • model-configuration.md - AI模型配置参考
  • context-api.md - 运行时上下文访问
  • integration-actions.md - 集成动作的使用
  • tags.md - 机器人、用户、对话和工作流的实体标签
  • cli.md - CLI命令完整参考
  • mcp-server.md - AI助手的MCP服务器

Frontend Integration

前端集成

  • frontend/botpress-client.md - Using @botpress/client in frontends
  • frontend/calling-actions.md - Calling bot actions from frontend
  • frontend/type-generation.md - Type-safe integration with generated types
  • frontend/authentication.md - Authentication with PATs
  • frontend/botpress-client.md - 在前端中使用@botpress/client
  • frontend/calling-actions.md - 从前端调用机器人动作
  • frontend/type-generation.md - 利用生成类型实现类型安全集成
  • frontend/authentication.md - 使用PAT进行身份验证

Runtime Access Patterns

运行时访问模式

Quick reference for accessing ADK runtime services:
ADK运行时服务快速参考:

Imports

导入

typescript
// Always import from @botpress/runtime
import {
  Action,
  Autonomous,
  Workflow,
  Conversation,
  z,
  actions,
  adk,
  user,
  bot,
  conversation,
  context,
} from "@botpress/runtime";
typescript
// Always import from @botpress/runtime
import {
  Action,
  Autonomous,
  Workflow,
  Conversation,
  z,
  actions,
  adk,
  user,
  bot,
  conversation,
  context,
} from "@botpress/runtime";

State Management

状态管理

typescript
// Bot state (defined in agent.config.ts)
bot.state.maintenanceMode = true;
bot.state.lastDeployedAt = new Date().toISOString();

// User state (defined in agent.config.ts)
user.state.preferredLanguage = "en";
user.state.onboardingComplete = true;

// User tags
user.tags.email; // Access user metadata
typescript
// Bot state (defined in agent.config.ts)
bot.state.maintenanceMode = true;
bot.state.lastDeployedAt = new Date().toISOString();

// User state (defined in agent.config.ts)
user.state.preferredLanguage = "en";
user.state.onboardingComplete = true;

// User tags
user.tags.email; // Access user metadata

Calling Actions

调用动作

typescript
// Call bot actions
await actions.fetchUser({ userId: "123" });
await actions.processOrder({ orderId: "456" });

// Call integration actions
await actions.slack.sendMessage({ channel: "...", text: "..." });
await actions.linear.issueList({ teamId: "..." });

// Convert action to tool
tools: [fetchUser.asTool()];
typescript
// 调用机器人动作
await actions.fetchUser({ userId: "123" });
await actions.processOrder({ orderId: "456" });

// 调用集成动作
await actions.slack.sendMessage({ channel: "...", text: "..." });
await actions.linear.issueList({ teamId: "..." });

// 将动作转换为工具
tools: [fetchUser.asTool()];

Context API

Context API

typescript
// Get runtime services
const client = context.get("client"); // Botpress client
const cognitive = context.get("cognitive"); // AI model client
const citations = context.get("citations"); // Citation manager
typescript
// 获取运行时服务
const client = context.get("client"); // Botpress客户端
const cognitive = context.get("cognitive"); // AI模型客户端
const citations = context.get("citations"); // 引用管理器

File Naming

文件命名规范

  • Actions/Tools/Workflows:
    myAction.ts
    ,
    searchDocs.ts
    (camelCase)
  • Tables:
    Users.ts
    ,
    Orders.ts
    (PascalCase)
  • Conversations/Triggers:
    chat.ts
    ,
    slack.ts
    (lowercase)
  • Actions/Tools/Workflows
    myAction.ts
    ,
    searchDocs.ts
    (小驼峰式)
  • Tables
    Users.ts
    ,
    Orders.ts
    (大驼峰式)
  • Conversations/Triggers
    chat.ts
    ,
    slack.ts
    (全小写)

Critical ADK Patterns (Always Reference in Answers)

ADK关键模式(答案中需始终参考)

When answering questions, always verify these patterns against the documentation:
解答问题时,请始终对照文档验证以下模式:

Package Management

包管理

bash
undefined
bash
undefined

All package managers are supported

支持所有包管理器

bun install # Recommended (fastest) npm install # Works fine yarn install # Works fine pnpm install # Works fine
bun install # 推荐(速度最快) npm install # 可正常使用 yarn install # 可正常使用 pnpm install # 可正常使用

ADK auto-detects based on lock files

ADK会根据锁文件自动检测

- bun.lockb → uses bun

- bun.lockb → 使用bun

- package-lock.json → uses npm

- package-lock.json → 使用npm

- yarn.lock → uses yarn

- yarn.lock → 使用yarn

- pnpm-lock.yaml → uses pnpm

- pnpm-lock.yaml → 使用pnpm

undefined
undefined

Imports

导入规范

typescript
// ✅ CORRECT - Always from @botpress/runtime
import { Action, Autonomous, Workflow, z } from "@botpress/runtime";

// ❌ WRONG - Never from zod or @botpress/sdk
import { z } from "zod"; // ❌ Wrong
import { Action } from "@botpress/sdk"; // ❌ Wrong
typescript
// ✅ 正确做法 - 始终从@botpress/runtime导入
import { Action, Autonomous, Workflow, z } from "@botpress/runtime";

// ❌ 错误做法 - 绝不要从zod或@botpress/sdk导入
import { z } from "zod"; // ❌ 错误
import { Action } from "@botpress/sdk"; // ❌ 错误

Export Patterns

导出模式

typescript
// ✅ Both patterns work - export const is recommended
export const myAction = new Action({ ... });  // Recommended
export default new Action({ ... });           // Also valid

// Why export const?
// - Enables direct imports: import { myAction } from "./actions/myAction"
// - Can pass to execute(): tools: [myAction.asTool()]
typescript
// ✅ 两种模式都可行 - 推荐使用export const
export const myAction = new Action({ ... });  // 推荐
export default new Action({ ... });           // 同样有效

// 为什么推荐export const?
// - 支持直接导入:import { myAction } from "./actions/myAction"
// - 可传递给execute():tools: [myAction.asTool()]

Actions

动作规范

typescript
// ✅ CORRECT - Handler receives { input, client }
export const fetchUser = new Action({
  name: "fetchUser",
  async handler({ input, client }) {  // ✅ Destructure from props
    const { userId } = input;         // ✅ Then destructure fields
    return { name: userId };
  }
});

// ❌ WRONG - Cannot destructure input fields directly
handler({ userId }) {  // ❌ Wrong - must be { input }
  return { name: userId };
}
typescript
// ✅ 正确做法 - 处理器接收{ input, client }
export const fetchUser = new Action({
  name: "fetchUser",
  async handler({ input, client }) {  // ✅ 从props中解构
    const { userId } = input;         // ✅ 然后解构字段
    return { name: userId };
  }
});

// ❌ 错误做法 - 不能直接解构input字段
handler({ userId }) {  // ❌ 错误 - 必须是{ input }
  return { name: userId };
}

Tools

工具规范

typescript
// ✅ CORRECT - Tools CAN destructure directly
export const myTool = new Autonomous.Tool({
  handler: async ({ query, maxResults }) => {
    // ✅ Direct destructuring OK
    return search(query, maxResults);
  },
});
typescript
// ✅ 正确做法 - 工具可直接解构
export const myTool = new Autonomous.Tool({
  handler: async ({ query, maxResults }) => {
    // ✅ 直接解构没问题
    return search(query, maxResults);
  },
});

Conversations

对话规范

typescript
// ✅ CORRECT - Use conversation.send() method
await conversation.send({
  type: "text",
  payload: { text: "Hello!" }
});

// ❌ WRONG - Never use client.createMessage() directly
await client.createMessage({ ... });  // ❌ Wrong
typescript
// ✅ 正确做法 - 使用conversation.send()方法
await conversation.send({
  type: "text",
  payload: { text: "Hello!" }
});

// ❌ 错误做法 - 绝不要直接使用client.createMessage()
await client.createMessage({ ... });  // ❌ 错误

Examples of Questions This Skill Answers

本技能可解答的问题示例

Beginner Questions

入门级问题

  • "What is an Action?"
  • "How do I create my first workflow?"
  • "What's the difference between Actions and Tools?"
  • "什么是Action?"
  • "如何创建我的第一个工作流?"
  • "Actions和Tools之间有什么区别?"

Implementation Questions

实现类问题

  • "How do I access the Botpress client?"
  • "How do I use citations in RAG?"
  • "What's the syntax for searchable table columns?"
  • "How do I call a Slack integration action?"
  • "How do I use Zai to extract structured data?"
  • "How do I validate content with Zai?"
  • "如何访问Botpress客户端?"
  • "如何在RAG中使用引用?"
  • "可搜索表格列的语法是什么?"
  • "如何调用Slack集成动作?"
  • "如何使用Zai提取结构化数据?"
  • "如何使用Zai验证内容?"

Advanced Pattern Questions

高级模式问题

  • "How do I add guardrails to prevent hallucinations?"
  • "How do I implement admin authentication?"
  • "How do I add logging and observability?"
  • "How do I compose multiple extensions?"
  • "How do I manage context in async tool handlers?"
  • "如何添加防护机制防止幻觉?"
  • "如何实现管理员身份验证?"
  • "如何添加日志和可观测性?"
  • "如何组合多个扩展?"
  • "如何在异步工具处理器中管理上下文?"

Troubleshooting Questions

故障排除类问题

  • "Why am I getting 'Cannot destructure property' error?"
  • "How do I fix import errors?"
  • "What's wrong with my workflow state access?"
  • "为什么我会收到'Cannot destructure property'错误?"
  • "如何修复导入错误?"
  • "我的工作流状态访问有什么问题?"

Best Practices Questions

最佳实践问题

  • "What are common mistakes to avoid?"
  • "How should I structure my project?"
  • "What's the recommended pattern for X?"
  • "有哪些常见错误需要避免?"
  • "应该如何组织项目结构?"
  • "X的推荐实现模式是什么?"

Response Format

回复格式

When answering ADK questions, follow this structure:
  1. Start with a concise explanation - Answer the core question directly
  2. Provide working code examples - Use examples from references or create based on patterns
  3. Include file references - Cite documentation (e.g., "From actions.md:215")
  4. Highlight common pitfalls - Reference the troubleshooting section if relevant
  5. Security & best practices - Mention security considerations when applicable
  6. Link to related topics - Suggest further reading or related concepts
Example Response Structure:
Actions are strongly-typed functions that can be called from anywhere in your bot.

**Example:**
[code example]

**Common Pitfall:** Remember to destructure `input` first (see troubleshooting section)

**Related:** You can convert Actions to Tools using `.asTool()` - see the "When to Use What" decision tree.

**Next Steps:** Create your action in `src/actions/myAction.ts` and it will be auto-registered.
解答ADK问题时,请遵循以下结构:
  1. 开头给出简洁解释 - 直接回答核心问题
  2. 提供可运行的代码示例 - 使用参考文档中的示例或基于模式创建
  3. 包含文件引用 - 引用文档(例如:"来自actions.md:215")
  4. 突出常见陷阱 - 如有相关,参考故障排除部分
  5. 安全与最佳实践 - 适用时提及安全注意事项
  6. 链接到相关主题 - 建议进一步阅读或相关概念
示例回复结构:
Actions是强类型函数,可在机器人的任何位置调用。

**示例:**
[代码示例]

**常见陷阱:** 请记住先解构`input`(见故障排除部分)

**相关内容:** 你可以使用`.asTool()`将Actions转换为Tools——请参阅“何时使用何种组件”决策树。

**下一步:** 在`src/actions/myAction.ts`中创建你的动作,它将自动注册。