Pi Bot is a platform-agnostic persistent agent core that handles conversation semantics, model calls, memory, multimodal references, and reliable outbox queuing without any specific IM SDK or gateway.

Stars

3

7-day growth

No data

Forks

2

Open issues

0

License

MIT

Last updated

2026-07-29

AI repository intelligence
FR-AI / ANALYSIS

Why it is worth attention

It provides a clean separation between chat platform adapters and the core logic, with built-in idempotency, serial processing, atomic commits, and a versioned capability system for safe and auditable agent behavior.

Who it is for

  • Developers building multi-platform chatbot backends
  • Platform integrators who need to connect different IM SDKs to a unified agent core
  • Teams requiring persistent, memory-equipped conversational agents with reliability guarantees
  • Engineers designing secure and auditable agent architectures with strict capability controls

Use cases

  • Building a single agent that works across Discord, Telegram, Slack, and custom chat platforms
  • Creating a group chat bot with full conversation history awareness and long-term memory
  • Implementing an agent that can handle media, mentions, and tools while maintaining idempotent message processing
  • Developing a high-reliability chatbot that survives restarts without losing pending outbound messages

Strengths

  • Platform independence through standardized adapter interfaces and versioned feature declarations
  • Robust reliability model with event idempotency, per-session serialization, and atomic outbox commits
  • Modular design segregating transcript, memory, and behavior for auditability
  • Safe capability exposure that prevents model from accessing unconfigured tools or platform resources

Considerations

  • Requires Node.js 22.13+, which is a relatively modern runtime requirement
  • No built-in adapters for specific IM platforms; all adapters must be developed externally
  • Limited to text, media, and file attachments; no native support for interactive UI components like buttons or forms
  • Complexity in setting up proper adapter manifests and capability declarations for advanced platform features

README quick start

Pi Bot

Pi Bot 是一个与聊天平台无关的持久化 Agent 核心。它只处理对话语义、模型调用、记忆、多模态引用和可靠出站队列,不包含任何具体 IM SDK、登录协议或消息网关实现。

IM SDK / Gateway
       ↕
ChannelAdapter + ChannelPlugin v1
       ↕
ChannelRuntime
       ↕
GroupAgentCore → Pi Agent → durable outbox

具体平台通过仓库外的适配包接入。适配器负责原生事件转换和消息发送;核心只接收标准事件、输出标准动作,并按适配器声明的能力做运行时校验。

特性

  • 完整保存未触发机器人的群聊消息,后续回复仍能理解真实上下文。
  • transcript、长期 memory、behavior 三层状态相互独立且可审计。
  • 入站事件幂等、同会话串行、回复与 outbox 原子提交。
  • 支持文本、图片、音频、语音、视频、文件、链接、引用和成员提及。
  • 媒体只保存 AssetRef,二进制内容位于独立的 AssetStore
  • 适配器用版本化 feature 声明收发能力,用强类型 capability 暴露可选操作。
  • capability 不会自动成为模型工具;只有显式配置的 toolProviders 能进入 Pi。
  • 支持按需图片理解、附件检查、知识检索、MCP 工具和语音生成。
  • 群聊触发支持点名、唤醒词、引用、自然续聊、always-on 和关闭模式。
  • 模型可选择沉默,不会向群聊发送内部占位符。

环境

  • Node.js >= 22.13
  • 一个 Pi 支持的模型 API key
npm ci
npm run check

最小用法

import { getModel } from "@earendil-works/pi-ai";
import {
  CHANNEL_PLUGIN_API_VERSION,
  ChannelRuntime,
  GroupAgentCore,
  PiAgentRunner,
  defineChannelPlugin,
} from "pi-bot";

const core = new GroupAgentCore({
  bot: {
    id: "bot-1",
    displayName: "小派",
    wakeWords: ["派派", "小派"],
  },
  runner: new PiAgentRunner({
    model: getModel("anthropic", "claude-sonnet-4-6"),
    apiKey: () => process.env.ANTHROPIC_API_KEY,
    thinkingLevel: "low",
  }),
  databasePath: "./data/agent.sqlite",
  defaultGroupActivation: "mention",
  operatorIds: ["operator-1"],
});

const plugin = defineChannelPlugin({
  apiVersion: CHANNEL_PLUGIN_API_VERSION,
  id: "example-adapter-instance",

  async start(context) {
    sdk.onMessage(async (raw) => {
      await context.ingest({
        type: "message",
        id: raw.eventId,
        transportMessageId: raw.messageId,
        conversation: {
          id: raw.conversationId,
          kind: raw.isGroup ? "group" : "direct",
          title: raw.conversationTitle,
        },
        sender: {
          id: raw.senderId,
          displayName: raw.senderName,
        },
        text: raw.text,
        timestamp: raw.timestamp,
        mentions: raw.mentionedBot ? [{ id: "bot-1" }] : [],
      });
    });
  },

  async send(action) {
    await sdk.send({
      conversationId: action.conversationId,
      text: action.text,
      parts: action.parts,
      replyTo: action.replyToMessageId,
      idempotencyKey: action.id,
    });
  },

  async stop() {
    await sdk.close();
  },
});

const runtime = new ChannelRunti

Related repositories

Similar projects matched by category, topics, and programming language.

TanStack
Featured
TanStack GitHub avatar

router

TanStack Router is a type-safe, data-driven React router with built-in caching, prefetching, and nested layouts, while TanStack Start extends it into a full-stack SSR framework.

Web DevelopmentFrontend Frameworks
14,861
vercel-labs
Featured
vercel-labs GitHub avatar

scriptc

scriptc compiles ordinary TypeScript into small, fast native executables without needing Node.js, V8, or any JavaScript runtime in the binary.

Developer ToolsCode Quality & Build
1,985
Jakubantalik
Featured
Jakubantalik GitHub avatar

thinking-orbs

A React component library that renders six hand-tuned animated thought orb loading indicators on a plain 2D canvas, with two purpose-tuned sizes and automatic theme detection for AI and agent UIs.

AI & Machine LearningAI Agents
1,191