createBot
Create a bot: wire platform adapters to an AG-UI agent, register tools, context, and slash commands, and get the handler surface.
Overview
createBot is the entry point of @copilotkit/bot. It wires one or more platform adapters to an AG-UI agent and returns a Bot — the surface for registering turn handlers, interaction handlers, interrupt handlers, slash commands, and tools, plus start() / stop() lifecycle control.
For a complete walkthrough, see the Slack quickstart.
Signature
import { createBot } from "@copilotkit/bot";
function createBot(opts: CreateBotOptions): Bot;Parameters
Prop
Type
Return Value
Prop
Type
Usage
import { createBot } from "@copilotkit/bot";
import { slack, defaultSlackTools, defaultSlackContext } from "@copilotkit/bot-slack";
const bot = createBot({
adapters: [
slack({
botToken: process.env.SLACK_BOT_TOKEN!,
appToken: process.env.SLACK_APP_TOKEN!,
}),
],
agent: (threadId) => makeAgent(threadId),
tools: [...defaultSlackTools, ...appTools],
context: [...defaultSlackContext, ...appContext],
});
bot.onMention(async ({ thread }) => {
await thread.runAgent();
});
await bot.start();Behavior
- Mention-preferred routing — there is no per-turn "kind": when any
onMentionhandler is registered, all turns route to the mention handlers; otherwiseonMessagehandlers fire. Registering identical handlers on both never double-fires. - Expired actions are swallowed — a click whose snapshot is gone (e.g. after a restart with the in-memory store) raises
ActionExpiredErrorinternally;createBotswallows it, so the click is acked but ignored and no message is posted. - Commands are matched case-insensitively and without the leading slash.
- No agent, no
runAgent— omittingagentis fine for bots that only post UI, butthread.runAgent()will throw.
Related
- Thread — the per-conversation handle your handlers receive
- defineBotTool — tools the agent can call
- defineBotCommand — slash commands
- ActionStore — action binding and durability
- Slack quickstart — zero to a working bot