Skip to content

feat(sms): schedule with AgentOS from a conversation, with an editable prompt - #3

Merged
HanZijie merged 6 commits into
mainfrom
feat/sms-ask-agentos
Oct 9, 2026
Merged

HanZijie merged 6 commits into
mainfrom
feat/sms-ask-agentos

Conversation

@HanZijie

@HanZijie HanZijie commented Oct 9, 2026

Copy link
Copy Markdown
Owner

做了什么、为什么

短信 App 的会话页新增主按钮“让 AgentOS 安排”:把这个会话里还没处理过的短信原文(没有经过任何 AI 处理;验证码按设置遮蔽)现场交给 AgentOS,建日程、待办和闹钟。这是 :sdk:acp-android 的第二个使用者(第一个是备忘录),网关、状态机、汇总从备忘录改过来。

  • 点按钮先弹预览面板:将发送的短信(带收到时间)、“也包含处理过的短信”开关、“提示词”卡片。
  • 提示词可编辑:展开后是交给 AgentOS 的任务说明(默认值在资源里,跟界面语言走),可以直接改,也可以在末尾加自己的要求;有字数显示(≤4,000)和“恢复默认”;点“开始”才保存。今天的日期与时区、固定规则、安全说明、短信原文由 App 固定附上,不能改:这一段守的是短信发件人的注入,不是用户。
  • 只发没处理过的:AgentOS 正常走完一轮后,发出去的短信 id 记在本地,下次默认不再带上(停止、出错、被取消的不记);气泡上标“已由 AgentOS 处理”。
  • toolScope 固定为 event_create、todo_create、alarm_create,不带读短信 / 发短信的工具:任何人都能给用户发短信,正文比备忘录更不可信。
  • 取舍与已知限制:字数预算 8,000(超出留最新、报告丢了几条);“已处理”只表示 AgentOS 正常走完一轮,不表示每条都建出了东西;已读过 0.1.0 首次对话框的用户不会再看到新的数据去向说明(新说明在状态页 / 设置页 / 预览面板里)。
  • 同时:版本号 0.1.0 → 0.2.0(versionCode 2,五个示例 + AgentOS 共用);docs/release-notes/0.2.0.md;演示用的 sms_demo_seed.py(写 10 条演示短信)。除短信 App 外 app/、core/、sdk/ 没有改动。

验证

  • 本地:./gradlew --stacktrace test lint -Pagentos.skipPiBundle=true 通过(最终提交 5eb50fb);短信模块 236 个 JVM 测试,0 失败
  • 本地:python3 tools/check-i18n.py、tools/tests 137 项、tests/device/acp-channel/unit 175 项通过
  • 本地:assembleDebug assembleRelease :app:assembleReleaseTest 通过;release 包里没有 debug 组件:app 和 5 个示例的 dex 里 Debug(Call|Tool)?Receiver 命中全是 0;短信 release 包里假网关 / raw_prompt / fake_gateway / ask_agent 命中 0
  • 本地:python3 tools/package-samples.py --allow-unsigned 干跑通过(5 个 APK、证书 / 权限 / 版本 / 发布说明检查)
  • CI 全绿(见本 PR 的 checks)

真机测试

  • 设备:Pixel 8 · Android 15 (API 35) · google/shiba/shiba:15/BP1A.250505.005.B1/13277630:user/release-keys · Magisk
  • 被测提交:5eb50fb60f3c787796242a18ab781af573a3c100(origin/main 没有前进,分支已是最新)
  • 跑了什么:python3 tests/device/acp-channel/third_party_sms_e2e.py 38290DLJH0007B → 44/44(最终提交上跑了一轮,开发过程中的前一版也是 44/44):首次授权、从原始短信建日程 + 待办 + 闹钟、只发没处理过的 / include_processed、用户在提示词末尾加的要求被执行、提示注入(要求删除全部日程并给 10086 发短信)无任何删除或发送、always 工具不弹卡、撤销。
  • 用了真实模型:是(minimax-cn / MiniMax-M3,https://api.minimaxi.com/anthropic),模型源只检查、没重配
  • 有人在真机上操作过界面:否。界面(按钮、预览、提示词展开 / 编辑 / 恢复默认 / 取消、运行中、确认通知、完成面板、气泡标记,中英文)是用 uiautomator 脚本点的,截图在 plugins/samples/sms/screenshots/*-14 到 *-19;没有人用手点过
  • key 泄漏扫描:整个 logcat 0 次、结果文件 0 次
  • 手机还原:写入的待办 / 闹钟按 id 删除;三个创建工具的审批模式还原为用户原来的 always;授权记录撤销;演示号码的短信删除。一处意外:脚本第一版在清理时对日历做了 reset,清掉了手机上之前备忘录演示留下的一个日程(“和王总开会”);脚本现已加护栏(日历里有非本次创建的数据时拒绝运行,除非 --allow-calendar-reset),详见 docs/m1-acceptance.md 三之五
  • 没测到的:国内机型;API 36 / 37 真机;用中文输入法在提示词框里直接打字(adb 输入被输入法改写,只验证了数字输入);真实来信与真实 SIM(演示短信是 root 写进系统短信库的);从 0.1.0 的发布包覆盖到 0.2.0 的发布包(发布后用下载的文件在测试机上验证)

文档与契约

  • 改了:plugins/samples/sms/README.md(含截图)、docs/third-party-acp.md 5b、docs/m1-acceptance.md 三之五(如实写了没测的和发现的缺陷)、docs/sample-apps.md、docs/development.md、tests/device/acp-channel/README.md、新增 docs/release-notes/0.2.0.md(中英文,含已知限制)
  • 无不兼容的对外变化(没有改 ACP 协议、IAcpService、两个 SDK 的公开 API、plugin.json、错误码)
  • 新增的导出组件:无(短信 release 清单的导出组件仍是 MainActivity、SmsMcpService(要求 BIND_MCP_SERVICE)和 androidx 的 ProfileInstallReceiver)。新增的是 <queries>(日历、待办、闹钟、AgentOS 包名和 ACP action,只用于“在…中查看”和检测 AgentOS);权限不变(READ_SMS、SEND_SMS)

风险与回滚

  • 影响面:只有短信示例 App(会话页多一个按钮和面板);SmsGraph 多一个懒加载的用例,不点按钮就不连接 AgentOS。
  • 隐私:点按钮后,这个会话的短信原文经 AgentOS 发给用户配置的模型端点;发送前预览面板能看到并修改提示词,数据去向在状态页 / 设置页 / 预览面板都有说明。
  • 回滚:git revert 这个 PR 的合并提交即可(用户本地的“已处理”id 和自定义提示词留在 SharedPreferences 里,无害)。

Hanzijie added 6 commits October 9, 2026 18:08
The SMS app becomes the second third-party user of :sdk:acp-android, after Notes.
This commit is the model and logic behind a new button on the conversation page
(the UI follows in the next commit):

- agentos/: the gateway interface and its thin SDK adapter, the use case state
  machine (Ready, Checking, WaitingAuthorization, Running, Done, Error), and the
  tool-call summary. These are adapted from the Notes app; the tool scope stays
  the three create tools (event, to-do, alarm), never the tools that read or send
  messages, because anyone can text the user.
- SmsSchedulePrompt: four parts. Date, time zone and language, fixed. The task
  instructions, the only part the user can edit (default text lives in resources,
  sms_prompt_default, per UI language). Fixed rules and a safety note that treats
  everything inside <sms> as data from an untrusted sender. The raw messages, each
  with the time it arrived, so relative dates are worked out from that day and not
  from today. Message text, the number and the user's own text are escaped so none
  of them can close or forge the delimiter; a line break in a message is indented
  so it cannot forge the next message's header.
- ScheduleSelection: only unprocessed messages by default, newest kept when the
  8,000 character budget runs out (counted after escaping), older ones reported.
- ProcessedLedger: ids of messages already handled, recorded only after a round
  finished normally (not stopped, not failed, not cancelled by AgentOS) so a
  retry does not lose them and a handled message does not create a second to-do.
- PromptSettings: the user's edited instructions; saving text equal to the default
  clears the store, so a later default update still reaches users who never edited.
- Manifest <queries> for the calendar, to-do, alarm and AgentOS packages; the
  disclosure text now says the raw messages go to AgentOS when the user taps the
  button.

236 JVM tests in the module pass (prompt, injection escaping, size budget,
selection, ledger, prompt storage, every state machine path against the fake
gateway). debug carries the scriptable fake gateway; release only the real one.
…anel

The conversation page gets a primary button, "Schedule with AgentOS", with a
badge counting the messages not handled yet ("All processed" when none). It opens
a bottom panel instead of sending right away:

- Preview of the raw messages that will be sent, each with its arrival time and
  direction; a note if older unprocessed messages did not fit the budget.
- A switch to include already processed messages (shown only when there are some).
- A "Prompt" card: collapsed to one line (Default / Customized), expanded to an
  editable text box with a counter (max 4,000), a hint saying which parts the app
  always adds and cannot be changed, and "Restore default". The edit is saved when
  Start is tapped; Cancel and Back leave nothing behind.
- Then the same stages as the Notes panel: connecting, waiting for the AgentOS
  authorization, running with the streamed text and tool cards, awaiting
  confirmation (with an "Open confirmation" button), done with "View in Calendar /
  To-do / Alarms", and the error states with their next step.
- Bubbles of handled messages carry a "Handled by AgentOS" mark.

The panel lives in SmsRoot, so rotating, switching tabs or leaving the
conversation does not cancel a running round. MainActivity restores a round that
was lost when the process was reclaimed and says so in the panel.
DebugToolReceiver (debug only, DUMP permission, as before) gets the same entry
points the Notes app has, going through the same use case as the button:
ask_agent (--es address, optional include_processed and a one-off instructions
override), ask_agent_status, ask_agent_stop, fake_gateway, raw_prompt, plus
processed (read or clear the handled-message ids) and instructions (read, set or
reset the saved prompt). reset now also clears the handled-message ids.

The report only has counts, the number, the agent's reply and the created items;
no message text and no key. Nothing of this is in the release APK (checked in the
dex: 0 hits for the receiver, the fake gateway, raw_prompt and fake_gateway).
…a demo seeder

third_party_sms_e2e.py drives the real model (minimax-cn / MiniMax-M3) on a rooted
phone through adb only: first-time authorization, creating an event, a to-do and
an alarm from raw messages, sending only unprocessed messages and the
include-processed switch, a one-off prompt override with a user requirement,
prompt injection inside a message, an always-allow tool, and revoking. Messages
are written into the system store with `su -c content insert`, only for made-up
numbers, and deleted by number afterwards. The user's per-tool approval modes are
put on "ask" for the run and restored; alarms and to-dos are removed by id.

The calendar app's debug receiver can only reset everything it holds, so the run
refuses to start when the calendar already contains events unless
--allow-calendar-reset is passed. (A first version without that guard did wipe a
leftover demo event on the test phone; see docs/m1-acceptance.md.)

sms_demo_seed.py writes ten demo messages (flight, credit card bill, parcel code,
a colleague's meeting and report, family messages, a verification code, a
promotion) for screen recording. Timestamps count back from now and weekday names
are computed from the date so "by Thursday" is never today. A colon inside a
message must be escaped for `content insert` (08:20 otherwise rejects the whole
binding); the script does that and fails when an insert is rejected, where it used
to drop a message silently. `clean` only deletes rows of the demo numbers.
…ease notes

- plugins/samples/sms/README.md: a section with screenshots (Chinese and English),
  how the prompt editing works and what stays fixed, what "processed" means, the
  tool scope and the data flow; code structure, debug entry points and how to put
  demo messages on a rooted phone.
- third-party-acp.md 5b: how the SMS app differs from Notes (source, only
  unprocessed messages, size budget, editable prompt vs. the fixed injection guard,
  tool scope without read/send tools).
- m1-acceptance.md "san zhi wu": the real-phone run (44/44), the screen walkthrough,
  the three bugs found and fixed, and what was not verified: screens were driven by
  a script and not tapped by a person, typing in the prompt box with a Chinese
  keyboard, real incoming messages and a real SIM, and the calendar event the first
  version of the script removed from the test phone.
- docs/release-notes/0.2.0.md (bilingual, with known limitations). The upgrade
  paragraph says plainly that the upgrade over the 0.1.0 release package was not
  verified before publishing and is checked afterwards with the downloaded files.
- sample-apps.md and development.md: one sentence each.
The AgentOS app, the module zip and the five sample APKs share one version. Only
the SMS app changes behaviour in this release; the others are rebuilt unchanged
(see docs/release-notes/0.2.0.md).
@HanZijie
HanZijie merged commit 4c74c37 into main Oct 9, 2026
4 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