Your coding agent fixes a bug when you ask. Meanwhile, a ready backlog item waits for someone to start it, and an interrupted investigation loses its owner. Recurring work depends on someone remembering to type another prompt.
Start recurring agent work from events, and save its owner and progress in a durable record. An event such as a production error or a ready backlog item starts the work without a prompt. After a restart, the agent uses the saved record to check what happened and resume safely.
As the work grows, split it into a loop of three roles. Operations investigates production issues, Delivery prepares tested pull requests, and Research resolves blocking uncertainty. People set the scope and approve merge and deployment. Operations then monitors the result and feeds new issues back into the loop.
Choose a repeatable job that needs judgement, such as investigating a new production error or implementing a ready product backlog item (PBI). Use ordinary automation for deterministic steps such as refreshing a dashboard. A one-off question rarely needs a persistent agent.
For the hosting decision, see when to use AI agents in the cloud. Design durable ownership and recovery across runs, whether the agent is hosted locally or in the cloud.
Define the event, eligibility criteria, permitted actions, expected output and human owner before enabling the trigger. For example: when a PBI becomes ready, the Delivery agent may prepare one tested pull request (PR), with the assigned developer responsible for reviewing it.
Prefer a webhook when the source provides one. Scheduled polling is reasonable when it does not, or when delayed detection is acceptable. Check for changes before invoking the model: no relevant change means no new agent work. See GitHub's webhook guidance for event filtering and delivery identifiers.
Start with one agent. Split roles when the work needs different tools or permissions:
| Role | Trigger | Output and next owner |
|---|---|---|
| Operations | Production deployment or error | An investigated bug with reproduction steps and affected release, assigned to Delivery |
| Delivery | Ready PBI or investigated bug | A tested PR for a human reviewer, or a focused question for Research |
| Research | Uncertainty blocks Delivery's implementation | Findings and a recommendation returned to Delivery |
Figure: Operations feeds Delivery, Research resolves uncertainty, and Delivery implements a tested PR. After human review and release, production feedback returns to Operations
Implementation is a Delivery step, with a tested PR as its output. The PR links the PBI or bug, explains how the change meets its acceptance criteria, and records the tests run and their results. Research is optional: when the requirements and approach are clear, Delivery proceeds directly.
For example, Operations investigates a Northwind production error after release 2.4 and hands Delivery the reproduction steps, relevant logs and affected release. If the fix depends on an unclear supplier API behaviour, Delivery asks Research that specific question. Research returns its evidence and recommended approach so Delivery can implement and test the fix.
Agents do not deploy. A human reviews the PR and authorises merge and release through the team's release process. Operations then monitors production for the original error and any regression. Findings become the next investigated bug for Delivery.
Each hand-off includes the work key, acceptance criteria, evidence and next step. Save the new owner and pending hand-off together so a restart cannot lose the transfer. For a Research request, include the blocking question and what decision its answer must support. If the evidence is inconclusive, return the uncertainty to Delivery's human owner instead of guessing or repeating the investigation indefinitely.
Persistence means that work survives a process restart. Store the queue and checkpoints durably. One chat or process does not need to remain open forever. Microsoft's workflow checkpoint documentation explains storage options and resuming saved work. In-memory storage alone cannot survive a process restart.
Use a database table or durable workflow store to record each item's source, revision, owner, status, evidence, next step and output links. Claim work atomically and use an expiring lease so a crashed worker does not leave it stuck forever. Renew leases during long work and reject writes from workers whose lease has expired.
Design for duplicate delivery and interrupted actions. Use a stable work key, such as the source system plus PBI ID and ready revision. A delivery ID identifies a notification; several notifications may describe the same work. Serialise writes for that key.
Before retrying a write, reconcile its outcome or use a destination-supported idempotency key. If the outcome is uncertain, pause for a human instead of writing again. A crash after creating a PR but before saving its URL must not lead to another PR. See how to make handlers safe to retry.
Northwind PBI 314, "Show supplier lead times", becomes ready at revision 7. In both illustrations, Delivery opens PR 82, then crashes before saving its URL.
❌ Figure: Bad example - Lost session state makes the restarted worker repeat the work and open duplicate PR 83
✅ Figure: Good example - Saved ownership and evidence let the replacement worker reconcile PR 82: one work item, one PR
After the lease expires, the replacement worker claims the same work key and checks PRs for agent/northwind-pbi-314-r7, including closed PRs. It saves PR 82's URL and resumes its checks. A repeated revision-7 event adds no second work item.
GitHub's list pull requests API supports filtering by head branch and PR state. If the lookup fails or leaves the outcome uncertain, pause instead of creating another PR.
Give each job limits for attempts, elapsed time and spend. Pause exhausted work and notify its human owner. Provide a way to disable the trigger and stop active runs. Filter agent-generated events so updates cannot trigger an endless cycle.
Validate event sources and treat issue text, logs and retrieved content as untrusted data. Give agents only the tools and credentials their roles need. Keep merge, deploy and delete behind human approval, with a control for each action:
Feature availability depends on the repository and plan. Keep the agent's identity unable to change these controls. A prompt saying "ask first" is insufficient.
Before unattended use, test in a sandbox: deliver the same event twice, restart the worker before and after a write, and exhaust a retry limit. Confirm that each work key produces one intended result, the next owner can resume from saved evidence, and blocked work reaches a human. Also attempt a prohibited action and verify that permissions reject it. Record events, hand-offs, checks and approvals against the PBI so a reviewer can explain why the change happened.