Skip to content

feat(agent): 补齐轮次补充、排队、停止和结构化问答 - #239

Merged
xiaoyumuxi merged 4 commits into
mainfrom
feat/agent-turn-interaction
Dec 1, 2026
Merged

xiaoyumuxi merged 4 commits into
mainfrom
feat/agent-turn-interaction

Conversation

@xiaoyumuxi

@xiaoyumuxi xiaoyumuxi commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

关联 Issue

Refs 1lck/Lithe-IDEA#2560

类型

feat

问题与改动

Agent 原生会话缺少运行中补充、下一轮排队和结构化问答,停止与完成竞争时也需要保证剩余任务不会自动启动。本 PR 在 API-45 内补齐通用交互状态机,桌面端只消费投影,工具专属协议由插件翻译。

  • agents.prompt 区分默认 send、queue 和 steer;补充绑定 expectedTurn 并等待工具确认。
  • FIFO 队列最多 8 条、4 MiB,派发中的输入计入限额;只有正常完成自动推进,停止与失败暂停剩余队列,支持移除与显式继续。
  • 停止进入 stopping,等待真实轮次结束;停止与完成同时到达时保留暂停决定。
  • 结构化问答支持单选、多选、文字、取消、撤回及交付失败重试;交付成功才消费问题。
  • 会话使用有界 worker,在 runtime lock 外通知后端;传输等待有界,超时结果不明时不自动重发。
  • 未确认的补充被拒绝或 CLI 退出时恢复原文与附件;主动取消使用 cancelled 分类,不记错误终态。
  • 同步 Rust、Go、Node、Java SDK 的类型、可选接口、成功/失败交付确认与日志责任;更新契约、fixture、API 总表及协议记录。

Review 修复

提交 f8fe577e316caff5c72063083ffede8fe859f413 处理两项 review:

  • Queued prompts multiply in memory:普通 replay 同时受 8192 条/16 MiB 约束,使用紧凑编码事件;每活动会话只持有最新 interaction snapshot,退出时释放,closed worker 不可重建快照。旧快照压缩不算 missed,真实 replay 淘汰才报告缺口。
  • 拒绝补充的原文与附件走独立有界恢复通道:发送前预约最多 64 条/16 MiB,成功释放、失败保留到宿主显式 acknowledge:[seq];推进游标、读取或退出不消费。容量不足时发送前返回 agents.interactionBusy,用户文字仍在草稿。恢复副本不保留任意后端诊断正文,完整诊断仍在普通 replay。
  • Late question blocks stop completion:报告仍原子校验结构、能力和轮次;停止期间有效当前轮次问题/撤回被抑制,不创建 pending 或 actionable 表单,同批 terminal 可以结束并保留队列暂停。畸形或外轮次仍拒绝整批。
  • 修复前失败、修复后通过的回归覆盖重复快照、字节上限与 oversized gap、恢复跨游标/淘汰/退出/显式确认/容量、停止迟到问题(含单独问题与同批终态)、非法报告原子性,消费者由宿主 #2562 对齐。

JSON 保留量基线(不是 native RSS):20×1 MiB replay 从 20,972,952 bytes 降至 15,729,717 bytes;3×128 KiB 排队与 64 次交互从 70 份快照/25,977,855 bytes 降至 1 份/393,591 bytes。16 MiB replay 和 16 MiB recovery 是各自预算,live state/每会话快照另计,不声称整个 runtime 固定 32 MiB。

本轮 agents.waitEvents 是宿主 C ABI 命令扩展,四语 SDK 没有此 wrapper;SDK 源码无需为此变化,现有四语 e2e 16 项已复验通过。契约、API 索引和协议变更记录已在同一提交更新,版本不变。

公共接口

原计划编号 方法 用途
API-45 agents/report 上报交互能力、提问/撤回、回答交付和补充确认;停止期有效迟到问题抑制
API-45 agents/didPrompt 可选 steer 与 input 字段,保留当前轮次身份
API-45 agents/didCancel 停止当前轮次并暂停队列,等待真实结束
API-45 agents/didAnswerQuestion 将已校验答案或取消交给插件,由 SDK 确认交付
API-45 Core agents.prompt 默认发送、排队或立即补充
API-45 Core agents.updateQueue 移除队列条目或显式继续
API-45 Core agents.respondQuestion 回答仍在等待的结构化问题
API-45 Core agents.waitEvents 有界重放和当前快照;recoveries 持续恢复、acknowledge 显式确认

兼容、权限与日志

不提升 pluginAPIVersion、schemaVersion、agents 或 litheFunctions 版本;不写 mode 继续使用原 send 行为,未声明能力的插件不开放 steering/questions。旧 Core 保持严格拒绝新字段和事件,新插件需等待包含扩展的宿主发布后才能稳定交付。本 PR 不发版。

操作沿用用户发起、可信本地工作区和已有 Agent 运行权限约束。Core 新增 agent.interaction.failed 目录事件,只记录插件、session、method、稳定 code;不记录提示、回答、CLI 消息正文。补充失败由 Core 记录唯一终态,问答 handler 失败由 SDK 记录,主动取消不记录错误。

稳定 Core 码包括 steeringUnavailable、turnChanged、queueFull、turnStopping、questionNotPending、invalidQuestionAnswer、inputNotQueued、interactionBusy;未分配新的 JSON-RPC 数字码,既有 host 错误复用原分类。契约逐项说明拒绝、重试与生命周期。

验证

  • cargo test --manifest-path rust/Cargo.toml -p lithe-agent-runtime --all-targets:39 项通过;包括主动取消恢复输入的失败前/修复后回归。
  • 受影响 lithe-agent-runtime、lithe-plugin-rpc clippy:全部 feature、全部 target,通过。
  • Windows MSVC 目标编译/clippy 检查通过;未在 Windows 原生运行。
  • Rust Core 注释门禁、fmt、diff 空白检查通过。
  • Core 命令表、diagnostics catalog、共享 fixture 定向测试通过;日志目录生成检查通过(168 事件)。
  • node shared/plugins/scripts/verify-docs.mjs 通过。
  • node shared/plugins/scripts/sdk-e2e.mjs:四语 SDK 16 项通过。
  • timing runner 逐项记录 39 个 runtime 测试,无失败/超时;字节上限回归 1143 ms(SLOW 提醒,低于 15 s 上限),其余未超 1 s 提醒线。HTML/JUnit:.artifacts/test-stability/agent-turn-review.{html,xml}。

组件与 SDK e2e 不等于真实 CLI 或目标平台原生整机验收;后者仍 pending。仅验证本次受影响范围,其他检查交 CI。

范围与依赖

@xiaoyumuxi
xiaoyumuxi marked this pull request as ready for review November 30, 2026 16:52
devin-ai-integration[bot]

This comment was marked as resolved.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

5 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment on lines +926 to +930
while state.events.len() > MAX_QUEUED_EVENTS || state.replay_bytes > MAX_REPLAY_BYTES {
if let Some(dropped) = state.events.pop_front() {
state.replay_bytes -= dropped.bytes();
state.dropped_through = dropped.sequence;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Replay eviction strands permission requests

When output fills the replay budget, EventQueue::push can evict an unread permission request while the CLI waits. Live::list exposes the request ID but none of the choices. Refreshing cannot recover the prompt or let the user answer it.

Learn more

When a plugin reports a permission request, TurnState::apply_one saves the allowed choices and Live::report puts the full request in replay for the desktop host. The global byte cap can remove that request while the agent is still waiting, even when the event count is far below the count cap. On reopening the agent view, Live::list only returns pending permission IDs; neither the options nor their labels are in the interaction snapshot. respond_permission requires an option ID, and TurnState::decide rejects any ID the plugin did not offer. Replaying from an older cursor cannot recover the choices after eviction.

Example: One agent asks for permission with plugin-defined option IDs while the desktop host is not reading the feed. Another live agent reports 18 tool outputs of about 950 KiB each. When the host catches up, the first agent still waits for the decision, but the full request has been evicted. The host only has its ID and cannot display the choices.

Recommended fix: Retain each full pending permission request as bounded live-session state and expose it in agents.sessions or the current snapshot. Remove it on decision, turn end, or session exit. Test that a host can reconstruct and answer the request after unrelated output evicts its original replay event.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

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