Open
Conversation
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Co-authored-by: united_pooh <united_pooh@outlook.com>
…ror-fallback fix(runtime): avoid instantiating Star in on_error fallback
85342f1 feat(tests): 添加测试用例以验证 register_task 的行为并更新测试运行说明 fdffc09 Merge pull request AstrBotDevs#26 from united-pooh/fix/fix-star-on-error-fallback 3b09747 feat: 完善 memory 向量检索与索引统计 (AstrBotDevs#28) 665c9c6 fix(runtime): avoid virtual dispatch in Star.on_error fallback 200559a fix(runtime): avoid creating Star instance in on_error fallback git-subtree-dir: astrbot-sdk git-subtree-split: 85342f1
feat(tests): 在 PluginHarness 中使用 normalize_message_type 函数以标准化消息类型
…o/AstrBot into feat/sdk-integration
…ession_id 中的代理初始化
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
动机 / Motivation
本 PR 实现了完整的 AstrBot SDK v4 插件系统,旨在解决以下问题:
设计原则:旧插件走旧逻辑,新插件走 SDK,保证旧逻辑依旧能使用的情况下写新 SDK 桥接。
改动点 / Modifications
1. 新增 astrbot-sdk 独立包 (约 68,000+ 行代码)
核心模块:
context.py- 统一的运行时上下文,组合所有能力客户端decorators.py- 声明式装饰器系统 (@on_command,@on_message,@require_admin,@rate_limit等)events.py- MessageEvent 事件对象,支持reply(),send_streaming(),react()等errors.py- 类型化错误系统,支持docs_url和details扩展star.py- Star 基类和生命周期管理能力客户端 (clients/):
llm.py- LLM 聊天、流式聊天、Tool Loopmemory.py- 记忆存储、搜索、TTL 管理db.py- KV 持久化、Watch 订阅platform.py- 消息发送、会话管理provider.py- Provider 查询、TTS/STT/Embeddingmanagers.py- 人格/对话/知识库管理客户端运行时系统 (runtime/):
supervisor.py- Supervisor 运行时,管理多个 Worker 进程worker.py- Worker 运行时,处理单个插件进程peer.py- 基于 JSON-RPC 的对等通信transport.py- 基于 stdio 的传输层handler_dispatcher.py- Handler 匹配与分发capability_router.py- 能力注册与路由loader.py- 插件发现与加载environment_groups.py- 环境组管理协议层 (protocol/):
descriptors.py- HandlerDescriptor, CapabilityDescriptor 声明式元数据messages.py- 协议消息类型_builtin_schemas.py- 内置 JSON Schema完整文档 (docs/):
2. 新增核心桥接层 (astrbot/core/sdk_bridge/)
核心组件:
plugin_bridge.py(约 3000 行) - SDK 插件桥接主类reload_all(),turn_on_plugin(),turn_off_plugin())dispatch_message(),dispatch_system_event())_RequestOverlayState)capability_bridge.py- 核心能力桥接,组合 10+ 个 Mixin:ProviderCapabilityMixin- Provider 查询、TTS/STT/Embedding/RerankPlatformCapabilityMixin- 平台管理、消息发送KnowledgeBaseCapabilityMixin- 知识库 CRUD、文档管理ConversationCapabilityMixin- 对话管理PersonaCapabilityMixin- 人格管理SessionCapabilityMixin- 会话级插件/服务开关SkillCapabilityMixin- 技能注册LLMCapabilityMixin- LLM 聊天、流式聊天SystemCapabilityMixin- 数据目录、文本转图片、文件令牌BasicCapabilityMixin- DB、Memory、HTTP、Metadataevent_converter.py- AstrMessageEvent ↔ SDK 事件载荷转换trigger_converter.py- Handler 触发器匹配(命令/正则/关键词)3. 核心模块修改
Pipeline 集成:
pipeline/process_stage/stage.py- 增加 SDK 分发逻辑pipeline/respond/stage.py- 支持 SDK 结果覆盖pipeline/result_decorate/stage.py- 兼容 SDK 消息链Platform 适配:
platform/sources/discord/discord_platform_adapter.py- 支持 SDK 原生命令菜单platform/sources/telegram/tg_adapter.py- 支持 SDK 原生命令菜单Star 系统兼容:
star/star_manager.py- 集成 SDK 插件管理star/context.py- 添加 SDK 桥接入口Skills 集成:
skills/skill_manager.py- 支持 SDK 技能注册 (prune_sdk_plugin_skills,replace_sdk_plugin_skills)4. Dashboard 集成
dashboard/routes/command.py- SDK 命令管理(只读)dashboard/routes/tools.py- SDK LLM 工具管理dashboard/routes/skills.py- SDK 技能管理dashboard/src/components/- 前端组件更新,支持 SDK 命令/工具标识5. 测试覆盖
SDK 包测试 (astrbot-sdk/tests/): 24 个测试文件
核心桥接测试 (tests/test_sdk/unit/): 13 个测试文件
技术亮点
1. 多进程隔离架构
2. 声明式装饰器系统
3. 类型安全的参数注入
MessageEvent,ContextOptional[T]和T | None语法4. 请求级状态管理
_RequestOverlayState管理 LLM 决策覆盖5. 流式执行支持
StreamExecution包装异步迭代器文件变更统计
主要新增目录:
astrbot-sdk/- 完整的 SDK 包astrbot/core/sdk_bridge/- 核心桥接层tests/test_sdk/- 集成测试Breaking Changes
兼容性保证:
验证步骤 / Verification Steps
Checklist / 检查清单
astrbot-sdk/pyproject.toml(SDK 包独立依赖)相关 Issue