You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replace placeholders with actual content. Split body into 2–4 logical paragraphs.
77
+
Rules for the initial payload:
78
+
- Include the full original email in `body`. Do not rely on `preview` for review.
79
+
-`preview` is only a short list snippet for the sidebar.
80
+
- Do not generate a reply draft up front unless the user explicitly asked for one before opening the UI.
81
+
- Default to `draft.paragraphs: []` until the user clicks `Reply`.
82
+
- Normalize categories to Gmail-style values when possible: `Primary`, `Social`, `Promotions`, `Updates`, `Forums`.
80
83
81
84
### Step 2: Spawn a monitor sub-agent
82
85
83
86
Use the Task tool to spawn a sub-agent. Pass it:
84
87
- The `SESSION_ID`
85
88
- The full inbox array (exactly as submitted)
86
-
- The original paragraphs array (exactly as submitted)
89
+
- The current draft object (which may start empty)
87
90
88
91
Tell the sub-agent to follow the **Sub-Agent Instructions** section below.
89
92
@@ -100,10 +103,14 @@ You are a dedicated monitor for an AgentClick email review session. You own the
100
103
101
104
You have been given:
102
105
-`SESSION_ID` — the active session
103
-
-`inbox` — the inbox array (never changes)
104
-
-`paragraphs` — the current draft paragraphs (update this in memory after each rewrite)
106
+
-`inbox` — the inbox array
107
+
-`draft` — the current reply draft object, which may be empty until the user clicks `Reply`
105
108
106
109
Maintain a `ROUND` counter starting at 0 and a `LOG` list of actions taken each round.
110
+
Maintain per-email UI state in memory:
111
+
-`reply_loading[emailId]` — true while you are generating a reply draft
112
+
-`reply_ready[emailId]` — true when the draft has arrived
113
+
-`reply_unread[emailId]` — true when a newly generated reply draft is ready but the user has not opened it yet
107
114
108
115
### Your loop
109
116
@@ -131,28 +138,38 @@ echo "$RESULT"
131
138
132
139
#### C. Rewrite and PUT (only when STATUS is `rewriting`)
133
140
134
-
Read `result.actions` and `result.userIntention` from the `/wait` response.
141
+
Read the full `result` object from the `/wait` response.
142
+
143
+
The UI is an email client, not only a final approval page:
144
+
- The user may open multiple emails while you work.
145
+
- The user may click `Reply` on one email while continuing to read others.
146
+
- Do not block the user from browsing other emails while a reply is being prepared.
147
+
- When a reply is requested, update the session payload promptly so the UI can show loading state for that email.
148
+
- When the reply draft is ready, update the same email row so the UI can show a ready ring and an unread red dot for that email.
135
149
136
150
Rewrite rules:
137
-
- Apply the **minimum** change needed to satisfy the feedback
138
-
- Only modify paragraphs referenced in `result.actions`
139
-
- Keep all other paragraph text exactly unchanged
140
-
- Keep `inbox`, `draft.subject`, `draft.to`, and `draft.replyTo` unchanged
151
+
- If `result.readMore` is true, fetch more emails for the requested categories and PUT an updated inbox payload. Keep existing email IDs and append or merge new ones.
152
+
- If the user marked emails as read, reflect that in your local state and sync that status back to the real email system if you control it.
153
+
- If the user requested `Reply` for an email and no draft exists yet, generate the draft then PUT it into the payload for that email.
154
+
- If `result.actions` contains paragraph edits, apply the minimum change needed to satisfy the feedback.
155
+
- Only modify paragraphs referenced in `result.actions` unless the user explicitly requested a full rewrite.
156
+
- Keep all other paragraph text exactly unchanged.
157
+
- Keep `inbox`, `draft.subject`, `draft.to`, and `draft.replyTo` unchanged unless the user explicitly edited them in UI-supported fields.
141
158
142
159
Write the payload to a temp file (required for stability with special characters), then PUT:
If HTTP is not `200`, fix the JSON and retry the PUT. Do not loop back to A with a failed PUT.
172
189
173
-
If HTTP is not `200`, fix the JSON and retry the PUT. Do not loop back to A with a failed PUT.
190
+
When preparing a first reply draft after the user clicks `Reply`, use the same PUT path:
191
+
- First PUT a lightweight state update as soon as possible so the UI can show loading for that email.
192
+
- Then generate the draft.
193
+
- Then PUT the completed draft so the UI shows it as ready.
174
194
175
195
#### D. Report to main agent after each rewrite round
176
196
177
197
After a successful PUT, the server automatically notifies the main agent via webhook with a progress summary. You do not need to call the webhook yourself.
178
198
179
199
However, you must update your local state before looping:
180
200
- Increment `ROUND`
181
-
- Update your in-memory `paragraphs` to the new content
201
+
- Update your in-memory `draft` to the new content
Then **go back to step A**. The user will see the updated draft in the same browser tab.
@@ -193,6 +213,8 @@ Extract from the final `/wait` response:
193
213
-`result.actions` — deletions and rewrites the user marked
194
214
-`result.confirmed` — should be `true`
195
215
- The final paragraph list from the session payload
216
+
- Any emails marked read by the user
217
+
- Any reply draft fields edited by the user in UI
196
218
197
219
Output a structured report for the main agent:
198
220
@@ -210,9 +232,22 @@ FINAL_DRAFT:
210
232
- p1: <final content>
211
233
- p2: <final content>
212
234
- p3: <final content>
213
-
INSTRUCTION_TO_MAIN_AGENT: Send the email using the FINAL_DRAFT above. Do not ask the user again.
235
+
EMAIL_STATE_CHANGES:
236
+
marked_read:
237
+
- <email id>
238
+
INSTRUCTION_TO_MAIN_AGENT: Send the email using the FINAL_DRAFT above, and sync any marked-read state. Do not ask the user again.
214
239
```
215
240
241
+
## UI Behavior Requirements
242
+
243
+
Follow these UI assumptions when preparing or updating payloads:
244
+
- The main email view should show the full email body, not only a preview snippet.
245
+
- The sidebar snippet is only for compact scanning.
246
+
- Reply draft generation is lazy: do not send a ready draft before the user clicks `Reply`, unless the user explicitly asked for an immediate draft.
247
+
- While a reply is being generated, the UI should be able to show loading for that email and still let the user browse other emails.
248
+
- When a reply draft becomes ready, the corresponding email row should show a visible ready state and an unread red dot until the user opens that reply.
249
+
- Fast updates matter. Prefer sending an immediate "loading" payload update, then a second payload update with the completed draft.
0 commit comments