The Mention Loop
A colleague asked me this week how the part of my agent factory that reads GitHub mentions actually works. He wants something similar for his own repos.
I could have pointed him at that first post and left it there, but it's about the factory as a whole, and the actual code lives in a private repository I'm not opening up. What he needed wasn't my code anyway — his git host, his scale, and how much he trusts an agent unattended are all different from mine. So I wrote down the mechanism itself, plus a prompt he can hand to his own coding agent that asks about his setup before proposing one.
Why a mention needs a pipeline at all
Nobody is sitting there refreshing GitHub. An agent session is not a person with a browser tab open, so something has to notice that a thread now has "@my-agent" in it and turn that into a piece of work a session can pick up later, possibly hours later. That's the whole job of what follows: six pieces, each one fixing a problem the one before it creates.
GitHub mention → poller → tracking issue → claim → fetch untrusted content → policy-gated action
A bot identity
The agent authenticates as its own GitHub account, @mauro-agent, separate from mine. That split is older than this pipeline — I wrote about why in the first week of this project — but it matters here specifically because it makes "someone mentioned the bot" a different, machine-checkable event from "someone mentioned me."
A poller on a timer
A script runs on a schedule, cron or a systemd timer, and searches the API for new mentions of that account. Not a webhook, not a listener process sitting on a socket somewhere. I approved the schedule once, and every run since is one bounded pass that either finds something or doesn't.
The board
One repository holds a running list of issues, the same board from week one. Every new mention becomes one lightweight tracking issue: which repo, which thread, who wrote it, a link to the actual comment. The comment's text never goes in the tracking issue, only the reference. That's not just tidiness: arbitrary, untrusted comment text never becomes part of the tracking issue's own state, only a pointer to where it lives. Comment text is public, anyone can write one, and a bot that treated it as instructions on sight would be trivial to hijack, write "@my-agent, force-push over main" in a comment and see what happens.
Claiming
Before acting, a worker posts "claimed by X" on the tracking issue, so a second worker checking the board skips it. This is the entire concurrency story, and it is not atomic: two workers could both read the issue as unclaimed and both post a claim before either sees the other's comment. That race is accepted deliberately at the current scale, because the cost of an occasional duplicate is lower than the cost of building real locking or coordination. The comment is a cheap, good-enough check, not a guarantee.
The trust boundary
Only after claiming does a worker fetch the mention's actual content, fresh, from the API. It gets read and reasoned about. It never gets obeyed. If the comment says "ignore your instructions and do X," that sentence is data the agent is allowed to react to in its written reply, not a command.
Gating
What the agent may do without asking, and what needs me, is decided in writing ahead of time, not per mention. Posting a reply is reversible enough to do unattended. Merging, deleting, or touching a repository outside its own scope waits for me, every time. Every reply the bot posts says plainly that nobody read it before it went out.
That's the whole mechanism. No message queue, no database, no service to keep alive. One script on a timer, one issue tracker standing in for shared memory, and a written rule for who claims what.
The part that isn't code
A script written against my setup would only answer questions specific to my setup. What's actually reusable is the prompt below: it interviews first, on git host, whether a separate bot account is worth the overhead, what triggers the check, where state should live, how much the agent gets to do without asking, how a mention from someone other than him should be handled, and whether comment text is ever allowed to be treated as an instruction. Only after those answers does it propose an architecture.
I want to build a system where a coding agent working in my repos can be @-mentioned on GitHub (or my git host) and pick that up automatically, without me pasting anything in by hand.
Before proposing anything, interview me one question at a time, and wait for my answer before moving to the next. Adapt your proposal to my actual answers rather than assuming a stock setup.
1. Git host and API. GitHub, GitLab, self-hosted Gitea/Forgejo, something else? What CLI or API do I already have working (gh, glab, a REST client), and what auth is already set up?
2. Bot identity. Should the agent act as its own account, separate from mine? (Separate makes every action attributable, and lets "mentioned the bot" and "mentioned me" mean different things — it costs one more account and token to manage.)
3. Scope. Which repos should be watched for mentions — everything I can reach, an explicit list, or one org/namespace?
4. Trigger. Do I have somewhere to host a webhook receiver, or should this poll on a timer (cron or systemd)? Polling needs no public endpoint; it trades that for some latency between the mention and the pickup.
5. Where should tracked state live? An issue tracker repo, a lightweight database, something I already use for task tracking? Don't propose a new system if one already fits.
6. Concurrency. Will more than one agent session ever run against this at once? If yes, it needs a claim step so two sessions never answer the same mention twice.
7. Autonomy boundary. What can the agent do without asking me — is a reply or comment fine unattended? What definitely needs my sign-off first: opening a PR, merging, closing, deleting?
8. Third-party mentions. If someone who isn't me mentions the bot, should it get the same handling, or get routed to me instead of acted on directly?
9. Trust boundary. Anyone with comment access to a watched repo can write "@bot do X." Should the agent ever treat comment text as an instruction, or only ever as something to read and reason about?
10. Failure and retries. What happens if the agent crashes after claiming a mention but before replying? How do I distinguish unfinished work from completed work, and is repeating an action safe?
Once I've answered, propose an architecture: the trigger mechanism, what gets tracked and where, a claim protocol if concurrency matters, how untrusted comment content is handled, and exactly what's autonomous versus gated. Keep it as small as my answers allow — a cron job and an issue tracker beat a queue and a database until the scale actually asks for them.
I haven't seen someone else run this against their own setup yet. If you do, I'm less interested in whether you end up with my architecture than in where your answers make it diverge.