Skip to main content

toolpack-agents — Complete Guide

Pre-release

@toolpack-sdk/agents is currently in alpha (2.0.0-alpha.1). APIs may change before the stable release. Install with:

npm install @toolpack-sdk/agents@alpha

toolpack-agents is the agent layer of the Toolpack SDK. It provides a consistent, extensible pattern for building, composing, and deploying AI agents that communicate through real-world channels (Slack, Discord, Telegram, webhooks, SMS, scheduled jobs) and collaborate with each other.

Package

@toolpack-sdk/agents   (imported from '@toolpack-sdk/agents' in the monorepo)

Architecture at a glance

┌──────────────────────────────────────────────────────┐
│ AgentRegistry │
│ Coordinates lifecycle, routing, and delegation │
│ │
│ ┌─────────────────────────────────────────────────┐ │
│ │ BaseAgent (your custom agent) │ │
│ │ ├─ name, description, mode │ │
│ │ ├─ systemPrompt, model, provider │ │
│ │ ├─ channels[] ──► Channel integrations │ │
│ │ ├─ interceptors[] ─► Middleware chain │ │
│ │ ├─ conversationHistory ─► ConversationStore │ │
│ │ └─ invokeAgent() ─► your business logic │ │
│ └─────────────────────────────────────────────────┘ │
│ │ │
│ LocalTransport ◄─┤─► delegate / delegateAndWait │
└──────────────────────────────────────────────────────┘
│ │
External channels Capability agents
(Slack, Discord, (Summarizer, IntentClassifier)
Telegram, etc.)

Key concepts

ConceptPurpose
BaseAgentAbstract base for every agent. Extend it to add business logic.
AgentRegistryCoordinator for multi-agent deployments. Not needed for a single agent.
ChannelInterfaceNormalises external events → AgentInput; delivers AgentOutput back.
InterceptorComposable middleware (dedup, noise filter, rate limit, history capture…).
ConversationStorePersists message history; assemblePrompt() reads it to build LLM context.
AgentTransportRoutes cross-agent invocations (default: LocalTransport, in-process).

Documentation index

FileWhat it covers
agents.mdCreating agents — BaseAgent API, built-in agents, lifecycle
registry.mdAgentRegistry — multi-agent coordination
channels.mdAll 7 channel integrations (Slack, Discord, Telegram, Webhook, Scheduled, Email, SMS)
conversation-history.mdConversation storage, assemblePrompt, addressed-only mode
interceptors.mdInterceptor system — all 10 built-in interceptors and custom interceptors
transport.mdTransport layer — LocalTransport, JsonRpcTransport, delegation
human-in-the-loop.mdask() / handlePendingAsk() — pausing agents for human input
capabilities.mdIntentClassifierAgent and SummarizerAgent
testing.mdcreateTestAgent, MockChannel, captureEvents
examples.mdFull end-to-end examples

Quick install

npm install @toolpack-sdk/agents toolpack-sdk

Peer dependencies are optional — install only what you need:

# Slack (SlackChannel uses a built-in HTTP server, but @slack/web-api is needed for auth.test)
npm install @slack/web-api

# Discord
npm install discord.js

# Telegram
npm install node-telegram-bot-api

# Email
npm install nodemailer

# SMS
npm install twilio

# Persistent store
npm install better-sqlite3

Thirty-second example

import { BaseAgent, AgentInput, AgentResult, AgentRegistry, SlackChannel } from '@toolpack-sdk/agents';

class GreetingAgent extends BaseAgent {
name = 'greeting-agent';
description = 'Greets users warmly';
mode = 'chat';

async invokeAgent(input: AgentInput): Promise<AgentResult> {
return this.run(input.message ?? '');
}
}

const slack = new SlackChannel({
name: 'main-slack',
token: process.env.SLACK_BOT_TOKEN!,
signingSecret: process.env.SLACK_SIGNING_SECRET!,
channel: '#general',
});

const agent = new GreetingAgent({ apiKey: process.env.ANTHROPIC_API_KEY! });
agent.channels = [slack];

const registry = new AgentRegistry([agent]);
await registry.start();

For a full walkthrough see examples.md.