Skip to content

feat: 实现 EventBus subscribe / unsubscribe / emit / flush_events - #1

Merged
taide05 merged 1 commit into
mainfrom
feat/event-bus
Jul 21, 2026
Merged

taide05 merged 1 commit into
mainfrom
feat/event-bus

Conversation

@taide05

@taide05 taide05 commented Jul 21, 2026

Copy link
Copy Markdown
Owner

要解决什么问题

EventBus 模块缺少 publish/subscribe 实现,Agent 循环无法推送事件给 SSE 订阅者。

做了什么

  • 实现 subscribe:注册 asyncio.Queue 到指定 session
  • 实现 unsubscribe:从 session 移除指定队列,不存在时静默返回
  • 实现 emit:构造事件 dict → 推送至订阅队列 → 记入 _pending_events
  • 实现 flush_events:返回并清空待处理事件列表

设计决策

  • 用 hasattr 懒初始化而非 init,各方法独立检查属性存在
  • asyncio.QueueFull 用 pass 静默丢弃,不中断 Agent 循环
  • payload 展开到事件顶层,减少嵌套层级
  • 多队列支持:同一 session 允许多个队列,emit 遍历全部

边界

  • 确定不影响:tool_registry.py / agent_loop.py / routers / services 均未修改
  • 不确定:flush_events 在 agent_loop 集成时消费时机是否合理

验证

  • pytest tests/unit/test_event_bus.py -v → 11 PASS
  • pytest tests/unit/ -v → 27 PASS(8 红均为未实现的 agent_loop)

用 hasattr 懒初始化而非 __init__,各方法独立检查属性存在
asyncio.QueueFull 用 pass 静默丢弃,不中断 Agent 循环
payload 展开到事件顶层,减少嵌套层级
@taide05
taide05 merged commit ebd7952 into main Jul 21, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant