Skip to main content

agent_context/context/events/
outbound.rs

1//! AgentContext → 请求者的通知消息。
2//!
3//! 这些消息由 `AgentContext` Actor 发出,通知变更订阅者或压缩结果订阅者。
4
5use crate::role::Role;
6
7// ---------------------------------------------------------------------------
8// NotifyChange
9// ---------------------------------------------------------------------------
10
11/// incremental 区的变更通知,通过 [`RequestSubscribeChange`](super::subscribe::RequestSubscribeChange) 注册的订阅者接收。
12#[derive(Debug, Clone)]
13pub enum NotifyChange<M> {
14    /// 追加了一条消息
15    Appended(M),
16    /// 更新了指定索引的消息,同时给出旧值和新值
17    Updated {
18        /// incremental 区索引
19        index: usize,
20        /// 旧消息
21        old: M,
22        /// 新消息
23        new: M,
24    },
25    /// 在指定索引插入了消息
26    Inserted {
27        /// incremental 区索引
28        index: usize,
29        /// 插入的消息
30        message: M,
31    },
32    /// 移除了指定索引的消息
33    Removed {
34        /// incremental 区索引
35        index: usize,
36        /// 被移除的消息
37        message: M,
38    },
39    /// 弹出了最后一条消息
40    Popped(M),
41    /// 按角色保留,其余消息被移除
42    Retained {
43        /// 保留的角色
44        role: Role,
45        /// 被移除的消息列表
46        removed: Vec<M>,
47    },
48    /// 清空了整个 incremental 区
49    Cleared {
50        /// 被清空的所有消息
51        removed: Vec<M>,
52    },
53    /// 从 JSONL 批量加载消息替换了 incremental 区
54    Loaded {
55        /// 加载的消息列表
56        messages: Vec<M>,
57    },
58}
59
60// ---------------------------------------------------------------------------
61// NotifyCompressedForReply
62// ---------------------------------------------------------------------------
63
64/// 压缩完成通知,通过 [`RequestSubscribeCompressed`](super::subscribe::RequestSubscribeCompressed) 注册的订阅者处理。
65///
66/// `AgentContext` 压缩完成后将摘要和保留消息发送给订阅者,
67/// 订阅者返回修改后的 `(摘要, 保留)` 对,`AgentContext` 再写入对应区域。
68#[derive(Debug, Clone)]
69pub struct NotifyCompressedForReply<M> {
70    /// LLM 生成的摘要消息
71    pub summary: Vec<M>,
72    /// 保留的最近消息
73    pub kept: Vec<M>,
74}