Skip to content

feat(agent): give the Bot a sleep tool that waits for events - #6505

Merged
M4n5ter merged 5 commits into
rust-previewfrom
feat/bot-sleep
Oct 31, 2026
Merged

M4n5ter merged 5 commits into
rust-previewfrom
feat/bot-sleep

Conversation

@liugddx

@liugddx liugddx commented Oct 31, 2026

Copy link
Copy Markdown
Member

What

Stage two of the Always-on Bot discussed in #6464: the Bot gets a sleep tool that waits for events. It has no arguments and no duration (no floor, ceiling or budget), as agreed in the review.

How it works

  • sleep is a Bot-only DirectOnly tool with the engine's existing FinishTurn semantics (the same mechanism as yield_agent_graph). When it succeeds the Turn ends and the model is not called again.
  • Nothing new is needed to wake the Bot: a user message is already queued durably and starts the next Turn, and WorkHub results and scheduled Session effects already retry until the Session is idle.
  • Refusal: sleep fails, with a message to the model, only while a queued message is already bound to this Invocation's next step (a promoted message, which the engine delivers at the next step boundary). Ordinary queued follow-ups are not counted: the model cannot read them mid-Turn, so refusing would make it loop, and they start the next Turn on their own.
  • Like SendUser: granted by Bot identity, always visible, hidden from every other Session, and rejected from a requested tool list.
  • The standing instructions (en, zh-CN, zh-TW) tell the model to call sleep on its own, never in the same step as SendUser, because FinishTurn is exclusive within a step and its siblings are rejected.

Not in this PR

tool_choice: required (all three adapters hardcode auto today, so it would touch the model request path) and a step limit for a Turn that never calls sleep. Without either, a model that ends with plain text still ends the Turn harmlessly, so sleep is mainly an explicit, loggable "waiting for events" state plus the refusal above.

Verification

  • 3 new Bot tests: sleep ends the Turn with no further model call and a later message starts a new Turn that still sees the sleep result; only the Bot sees sleep and ordinary creation cannot request it; a promoted message makes sleep refuse and then arrives with the Turn. Bot tests: 15 pass.
  • cargo clippy -p maka-agent-native --no-deps --all-targets: clean.
  • cargo test -p maka-agent-native: 220 pass, 1 fails. The failing test is approval_park::exclusive_session_retirement_settles_parked_work_without_a_new_activation (MaterialCollected). It fails the same way on rust-preview at 0ee4114 without this change, so it is not caused by this PR.

Not checked here: behaviour with a real model in the desktop app, and whether models reliably call sleep in a separate step.

Compatibility: this changes the Bot's tool set, so a request parked before an upgrade can fail with agent_tools_changed.

🤖 Generated with Claude Code

sleep takes no arguments and has no duration. It ends the Turn through the
engine's existing FinishTurn semantics, and the Bot is woken again by a user
message, a WorkHub result or a scheduled event, each of which already starts
its own Turn. It is refused only while a queued message is already bound for
the running Invocation's next step, so a promoted message is read first.

Like SendUser it is granted by Bot identity, always visible, hidden from
other Sessions and rejected from a requested tool list. The standing
instructions tell the model to call it on its own, not in the same step as
SendUser, which FinishTurn would reject.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@liugddx

liugddx commented Oct 31, 2026

Copy link
Copy Markdown
Member Author

A small check with a real model in the desktop app, on a build of this branch (merged with #6491 and #6503 locally). I read the event log afterwards.

  • Two Turns that ran with sleep: in both, the model sent with SendUser in one step and called sleep alone in the next step. Each Turn made exactly two model calls, and no model call followed sleep.
  • Each Turn ended normally, and each was started by a new user message.

This is two Turns, so it shows the prompt works for that model, not that it always will. I only checked the event structure, not the message text or the Chat view. Not tried with a real model yet: a WorkHub result or a scheduled event waking the Bot, and sleep being refused because a promoted message is waiting. Those two are covered by unit tests only.

简体中文

在桌面应用里用真实模型做了一次小检查,使用的是本分支的构建(本地合并了 #6491 和 #6503),事后读取事件日志。

  • 含 sleep 的两轮:两轮里模型都是在一步里用 SendUser 发消息,下一步单独调用 sleep。每轮正好两次模型调用,sleep 之后没有再调用模型。
  • 每轮都正常结束,并且都是由新的用户消息开启的。

样本只有两轮,只能说明提示词对这个模型有效,不能说明每次都如此。我只核对了事件结构,没有看消息文字和聊天界面。真实模型下还没试的有:WorkHub 结果或定时事件唤醒 Bot,以及因有已提升的消息而拒绝休眠。这两项目前只有单元测试覆盖。

Preserve both the Sleep regressions and workspace-free Bot opening tests.
Update the existing retirement test to observe a removed Session through its
public API, since deletion now collects the original history material.

Generated-by: OpenAI Codex

@Astro-Han Astro-Han 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.

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

I reviewed all five changed files at cfb19672cfcbddb8f8e2c3c6c2cf04569c8ee30e. I found no confirmed P0–P2 issue in this source review. The implementation gives the registered Bot an always-visible, direct-only sleep, rejects requests for it when creating ordinary Sessions, and uses the existing FinishTurn settlement rather than introducing a timer or another wake mechanism. The effect rechecks Bot/Invocation identity and refuses a message already promoted to that Invocation; an ordinary queued follow-up remains a separate Turn. Existing call admission makes sleep exclusive within its step. This is a model-callable way to end a Turn, not a guarantee that the model can end only by sleeping.

Integration remains incomplete: an actual merge calculation against rust-preview at c07c5ac1d60650f9bb73ce9001c713e7870c7b3c conflicts in plugins/agent/native/src/owner/tests/bot_tests.rs. GitHub reports the PR as conflicting and lists no checks on this head. Resolve the test conflict and validate the resulting integration.

P3 — AI attribution: the PR discloses Claude's contribution and the commit has Co-Authored-By, but lacks the Generated-by trailer required by CONTRIBUTING.md. Preserve that trailer in the eventual squash commit.

Validation boundary: I traced the production registration, schema, identity checks, queue predicate, exclusive-step admission, successful-result settlement and recovery paths, and read the three new Rust tests. I did not execute Rust, the Host, a real model or the native UI on this machine. The Bot/full-suite test counts in the PR description are the author's results, not mine.


Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

liugddx and others added 2 commits November 1, 2026 00:13
# Conflicts:
#	plugins/agent/native/src/owner/tests/bot_tests.rs
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.

3 participants