Skip to content

let agents reply to an email in its thread, sent or saved as a draft - #166

Merged
hkonsti merged 1 commit into
mainfrom
hkonsti/agent-email-reply
Oct 30, 2026
Merged

hkonsti merged 1 commit into
mainfrom
hkonsti/agent-email-reply

Conversation

@hkonsti

@hkonsti hkonsti commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

An agent asked to reply to an outreach email couldn't: the email tools only sent new email or drafts with no link to the email answered, and opening an email didn't say its thread or Message-ID, so the best it could do was a new message with "Re:" in the subject, which may not land in the conversation. This adds a replies collection for Gmail and IMAP mailboxes, with two tools built on the reply the home page's Reply to email already writes (replyToGmail, and the IMAP one, now replyToMailbox).

replies_send sends a reply at once and needs Send and Read: a reply reads the email it answers, and Send alone otherwise lets an agent send without seeing the mailbox. replies_draft saves the reply as a draft in the thread, for emails_send to send later, and needs Write drafts, which already requires Read. Both take email (the id a list gives), body and replyAll (Yes or No). Whom it goes to, its subject and its thread come from the email: its Reply-To, else its sender, or, for an email sent from the account, whom it went to; the subject with "Re:" once; In-Reply-To and References, and on Gmail the email's thread id. A reply to all also goes to the others the email went to and copies whom it copied, never the account itself. Each answers whom it went to (To and Cc), its subject and its id: on Gmail the sent message's id or draft-<id> with the thread Gmail put it in; on IMAP the draft's id, or a sent reply's Message-ID, since SMTP gives it no id among email. A draft isn't replied to. IMAP replies now work for sent mail as well as the inbox, as Gmail's already did.

A catalog command can now name an action it requires beside its own. A tool needing one the agent lacks isn't listed, and a run is refused and logged as denied; the agent pages hide its button too. The Send and Write drafts descriptions in the permissions say what they now cover, and the docs for Email and Google say how replies are addressed and which actions they need.

Opening an email (emails_get) now also returns its messageId, the Message-ID header, and on Gmail its thread, so an agent can check a reply landed in the conversation.

Testing

  • bun run typecheck, bun run test, bun run lint
  • New tests: Gmail and IMAP replies sent and saved as drafts through the replies commands, with the id and thread they answer; reply to all leaves out the account and recipients it already has; an IMAP reply to sent mail goes to whom it went; drafts and empty bodies are turned down; replies_send is listed and run only with Send and Read, and refused and logged as denied with Send alone; emails_get returns the Message-ID and Gmail thread
  • Not tried against a real Gmail account or IMAP server

… and open an email with its Message-ID and thread
@hkonsti
hkonsti merged commit c4e9817 into main Oct 30, 2026
3 checks passed
@hkonsti
hkonsti deleted the hkonsti/agent-email-reply branch October 30, 2026 17:37
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