The rapid acceleration of AI capabilities has transformed how teams manage information, yet keeping pace with the flood of updates remains a persistent challenge. Many organizations have turned to lightweight agent automations that run on a schedule, silently gathering context from Slack, GitHub, and other tools, then delivering concise briefings directly to the channels where decisions are made. While the promise of these background helpers is clear, building them reliably proves surprisingly difficult: agents can lose credentials, miss updates due to timing windows, or inadvertently repeat information, eroding trust in the very system designed to reduce noise. This guide walks through a battleโtested reference implementation that addresses these pitfalls headโon, offering a concrete blueprint for developers who want to ship dependable, selfโhealing automations without managing infrastructure.
At the core of the solution lies Claude Managed Agents, a beta service that treats an agent as a versioned configuration rather than a longโlived process. Instead of provisioning servers or writing custom schedulers, you declare the agentโs model, system prompt, tools, and memory layout in plain text files. The platform then spins up a fresh sandbox for each run, executes the defined steps, and tears the environment down, guaranteeing isolation between executions. This model eliminates whole classes of bugs caused by lingering state, while still giving the agent the ability to remember critical information across runs via mounted memory stores. For teams accustomed to traditional cron jobs or cloud functions, the shift to a declarative, configurationโfirst approach reduces operational overhead and improves reproducibility.
Security is a primary concern when an agent needs to read from Slack and write back to it, especially when those actions involve privileged tokens. The reference implementation solves this by isolating credentials in a vault that lives outside the agentโs sandbox. When the agent references a secret, it uses an opaque placeholder such as $SLACK_BOT_TOKEN; the platform transparently swaps in the real value only when the request leaves the sandbox and targets an allowed host. This separation means that even if the agentโs code is compromised or misbehaves, the actual token never touches the execution environment. Vaults are created with the ant CLI, populated via the TypeScript SDK, and then linked to the deployment, providing a clear audit trail of which secrets are in use and where they originate.
Integrating with diverse services requires a uniform way to call external APIs without forcing the agent to manage complex authentication flows. For GitHub, the implementation leverages MCP (ModelโContextโProtocol) servers that run as proxies beyond the sandbox. The agent invokes MCP tools through this proxy, which looks up the matching credential in the vault and forwards the request. Because the proxy handles authentication, the agent can be granted blanket permission to call the GitHub toolset (set to always_allow) while still benefiting from readโonly token restrictions. Slack, by contrast, is accessed directly via the bash tool and curl inside the sandbox; the same placeholderโswap mechanism applies, allowing the agent to both read channels and post messages without ever seeing the raw token in its filesystem.
One of the most subtle bugs in scheduled data pulls stems from using fixed time windows like โthe last 24 hours.โ If a run is delayed, new events that arrived during the gap are missed; if it runs early, items from the previous cycle are resent, creating noise and duplication. The reference implementation replaces static windows with perโsource bookmarks. At the end of each execution, the agent writes the timestamp of the newest item it processed from each source into a shared bookmarks.json file. The next run reads these timestamps and treats them as the lower bound, dynamically expanding or contracting its query range to cover exactly what changed since the last successful invocation. This selfโadjusting window guarantees completeness and eliminates repeat work, regardless of schedule drift or temporary pauses.
Even with robust bookmarking, external dependencies can failโAPIs go down, tokens expire, or network issues interrupt connectivity. Rather than letting a single sourceโs outage corrupt the entire briefing, the agent is instructed to treat failures gracefully. If the GitHub MCP server is unavailable or its credential is invalid, the run still starts, the tools for that source are simply absent, and the session logs an error. The agent proceeds to gather what it can from Slack, constructs a brief from the available data, and appends a clear notice such as โpull requests unavailable this run.โ This transparency informs readers that the omission is due to a technical hiccup, not a lack of new activity, preserving trust and enabling quick diagnosis.
Posting the generated brief back to Slack introduces another set of reliability concerns: ensuring the message is delivered exactly once and not duplicated due to uncertain acknowledgments. The implementation adopts three defensive rules in agent.md. First, before sending, the agent scans the target channelโs recent messages for a headline matching todayโs date; if it finds an identical post, it aborts to prevent duplication. Second, it considers the send successful only when Slackโs response payload includes โokโ: true and a message timestamp (ts). Third, the agent updates its internal ledger of reported items and advances its bookmarks only after receiving that confirmed success. If the response is ambiguousโperhaps a network timeoutโthe run is marked โmaybe posted,โ the ledger and bookmarks remain untouched, and no data is lost or spuriously repeated. This idempotent pattern mirrors best practices from distributed systems and guarantees exactlyโonce semantics despite the inherently unreliable nature of HTTP.
Operational visibility is essential for any background automation, and the agent provides it through a lightweight run log stored in the same memory store used for bookmarks. Each execution creates a file named runs/<date>.md, which the agent populates with a short narrative: it marks the run as โpostingโ just before the Slack request, then updates it to โpostedโ with the returned message ID upon confirmation, or to โmaybe postedโ if the outcome is unclear. Over time, these logs form an audit trail that can be queried to detect missed runs, diagnose performance bottlenecks, or verify compliance with internal SLAs. Because the log lives in the platformโmanaged state folder, it persists between runs without requiring external databases, yet remains accessible to the agentโs file tools for reading and appending.
The agentโs behavior is shaped primarily by agent.md, which combines a declarative frontmatter with imperative instructions in the body. The frontmatter specifies the model (typically Claudeโฏ3โฏHaiku or Sonnet for costโefficiency), the enabled tools (bash for Slack, MCP for GitHub), and any external servers. The body contains concise directives: read sources according to preferences, apply exclusions, enforce a length cap, and, crucially, reโcheck the live status of each item just before posting to catch changes that may have occurred during the agentโs processing window. By steering the model toward brevity and explicit verification, the prompt reduces the likelihood of hallucinated summaries or outdated information slipping into the final brief.
Deployment configuration lives in deployment.md, where you bind the agent to its environment, schedule, memory stores, vault, and budget. The schedule uses standard cron syntax, while a dedicated timezone field ensures the agent interprets dates in the correct region, avoiding the common bug where a run stamps โyesterdayโ because it defaulted to UTC. The file also references the previously created vault ID and lists the two memory storesโpreferences (readโonly) and state (readโwrite). Launching a test run outside the scheduled cadence is as simple as invoking ant beta:deployments run –deployment-id <id>, using the identifier recorded in claudeโlock.json after the initial apply. This immediacy lets developers validate changes rapidly without waiting for the next cron tick.
Memory stores separate concerns to prevent stale data from corrupting decisionโmaking. The preferences store holds the userโcurated list of Slack channels, GitHub repositories, notification length limits, destination channel, and optโout rules; it is mounted readโonly so the agent cannot accidentally overwrite it. The state store, conversely, is the agentโs private workspace: it contains bookmarks.json, ledger.md (a running tally of every reported item with timestamps, source IDs, and last known status), perโrun logs, and any notes the agent keeps about source quirks (e.g., โGitHub returns only the newest 50 itemsโ). By requiring the agent to read preferences fresh each executionโrather than baking them into the promptโthe system avoids applying outdated filters after a user updates their configuration, a frequent source of confusion in promptโbased agents.
Running agents continuously on a schedule introduces cost and safety considerations that are often overlooked in early prototypes. The reference implementation enforces strict limits: the GitHub token and preferences store are marked readโonly, the outbound network allowlist includes only slack.com and api.github.com, and the agent lacks any write permissions to GitHub or the ability to alter its own rules. These sandbox controls mitigate promptโinjection risks where malicious text in a Slack message could otherwise coax the agent into performing unwanted actions. Additionally, a budget cap in deployment.md caps the computational spend per run; setting it initially at three to five times the expected cost provides a safety net, and observing actual usage lets you tighten the threshold over time. If a run hits the cap, it pauses with a budget_reached signal rather than failing catastrophically, making the degradation visible and allowing operators to intervene before the automation goes silent.
Putting it all together, the six guiding principles distilled from this reference implementation are: (1) isolate secrets in a vault with placeholderโswap semantics; (2) use perโsource bookmark windows instead of fixed time intervals; (3) handle source failures transparently without aborting the whole run; (4) enforce idempotent posting via preโchecks, strict success criteria, and conditional state updates; (5) maintain detailed, selfโdescribing run logs for observability; and (6) enforce leastโprivilege sandboxing, readโonly defaults, and spend caps to guarantee security and costโcontrol. By following these rules and leveraging the provided claudeโapi skill in Claude Codeโwhich scaffolds the necessary files and provisions resources with a single ant applyโteams can move from fragile adโhoc scripts to robust, selfโhealing agent automations that reliably deliver the right information at the right time, freeing humans to focus on higherโorder work.