Part 4: Replies and cleanup
The bot answers an issue once. A person who replies should reach the same conversation, with everything the agent already read. And an issue that closes should stop costing anything.
Add a reply to the conversation
Section titled “Add a reply to the conversation”A reply is another input to the issue’s conversation. whenBusy: "steer" adds it to a run that is still going, so the agent sees it before it answers:
yield* conversation.submit({ type: "input", content: `Issue #${issue.number}: ${issue.title}\n\n${issue.body}`, requestId: deliveryId, });}),commented: Effect.fn(function* (text: string, deliveryId: string) { yield* harness.submit("issue", { type: "input", content: text, requestId: deliveryId, whenBusy: "steer", });}),The conversation still has the issue, the files the agent read and its first answer. The sandbox is the same one too, resumed if Boat had stopped it.
Mark the bot’s own comments
Section titled “Mark the bot’s own comments”The bot’s comments are comments too, and GitHub will deliver them. Mark each one with a hidden HTML comment, so the Worker can tell them apart:
import { Repo } from "./Repo.ts";
export const MARKER = "<!-- issue-bot -->";
export class Comment extends AI.Tool<Comment>()("comment", {return Effect.fn(function* ({ body }) { const issue = yield* state.storage.get<number>("issue").pipe(Effect.orDie); const comment = yield* createComment({ issue_number: issue!, body }).pipe(Effect.orDie); const comment = yield* createComment({ issue_number: issue!, body: `${body}\n\n${MARKER}`, }).pipe(Effect.orDie); return { url: comment.html_url };});Consume comments
Section titled “Consume comments”Subscribe to issue_comment as well. event.name says which event arrived, and narrows event.payload to its type:
import Issue from "./Issue.ts";import { owner, repository } from "./Repo.ts";import { MARKER } from "./Comment.tool.ts";yield* GitHub.consumeRepositoryEvents( { owner, repository, events: ["issues"] }, { owner, repository, events: ["issues", "issue_comment"] }, Effect.fn(function* (event) { const { action, issue } = event.payload; if (action === "opened") { yield* issues .getByName(String(issue.number)) .opened({ number: issue.number, title: issue.title, body: issue.body ?? "" }, event.id); } const issue = issues.getByName(String(event.payload.issue.number)); if (event.name === "issues") { const { action, issue: opened } = event.payload; if (action === "opened") { yield* issue.opened( { number: opened.number, title: opened.title, body: opened.body ?? "" }, event.id, ); } return; } const { action, comment } = event.payload; if (action === "created" && !comment.body.includes(MARKER)) { yield* issue.commented(comment.body, event.id); } }, Effect.orDie),);Remove the sandbox when the issue closes
Section titled “Remove the sandbox when the issue closes”A closed issue’s sandbox is no longer needed. Add a method that removes it:
whenBusy: "steer", });}),closed: () => harness.removeSandbox("issue"),And call it when the issue closes:
if (action === "opened") { yield* issue.opened( { number: opened.number, title: opened.title, body: opened.body ?? "" }, event.id, ); } if (action === "closed") yield* issue.closed(); return;}The conversation stays in the Durable Object. An issue that is reopened and replied to gets a new sandbox from the snapshot, and the agent still remembers the conversation.
Deploy and reply
Section titled “Deploy and reply”pnpm alchemy deploybun alchemy deploynpx alchemy deployyarn alchemy deployReply on the issue from Part 3: “How many lines does README.md have? Count them with wc -l.” The agent runs wc -l in the same sandbox and comments with the answer. Close the issue, and its sandbox is gone from your Boat dashboard.
What you built
Section titled “What you built”- A Durable Object for each issue, holding a Pi conversation that survives evictions.
- A sandbox for each issue, started from a snapshot of the repository and removed when the issue closes.
- A tool that comments through a GitHub binding, with the token kept in the Durable Object.
- An event source that turns issues and replies into inputs, each delivered exactly once.
Where next
Section titled “Where next”- Conversations: steer, stop, reset and configure a conversation.
- Surviving a crash: what happens when the object is evicted mid-run.
- Extensions: block a tool call, or keep a run going.
- Webhooks & events: the other GitHub events a Worker can consume.
Tear down
Section titled “Tear down”pnpm alchemy destroybun alchemy destroynpx alchemy destroyyarn alchemy destroy