Build Always On Ai Agent
- Source
- openrouter.ai
- Author
- OpenRouter editorial sitemap
- Date

Context
An always-on is a program that wakes on a schedule, checks something with tools, and reports or acts without being asked each time. OpenAI announced its own version, dots, at DevDay 2026, and OpenRouter's tutorial builds one yourself in TypeScript with its Agent SDK, version 0.11.0. The example agent searches Hacker News every 15 minutes for chosen topics, writes a digest of relevant new stories, and can post to a team channel. The schedule is a plain loop in your code; the SDK runs the model and tool calls within each check.
Most of the design is about what happens when nobody is watching. Each check starts a fresh conversation, and a file of story IDs the agent has already seen serves as its memory. The author added the fresh start after noticing that reusing the conversation resent every earlier check to the model, so each run cost more than the last. Every run stops after six steps or five cents, though the SDK checks between rounds of tool calls and can go a call or two over. A credit limit on the API key caps the total. The team-channel tool is marked to require approval, so the run pauses before it executes, saves its state, and resumes only after a person writes the call's ID to a decisions file. That gate is also the tutorial's defence against : story titles are written by strangers, and telling the model to treat them as data lowers the odds that one steers it, without ruling it out, so the worst a hostile title can do alone is put text in the digest.
The tutorial's evidence comes from a few of the author's own runs with Claude Haiku 5.5 in mid-October 2026. A check cost $0.0003 to $0.0012, which works out to roughly $0.86 to $3.46 a month at 96 checks a day, with quiet checks at the bottom of that range. The author also killed the process right after a search, and separately ran a resume with an invalid API key right after approving a post; in both cases the next run continued the saved conversation without losing stories or posting twice. One trade-off is deliberate: while an approval is pending, the agent skips all checks, so an unanswered request stops the watching.
- OpenRouter's SDK 0.11.0 checks stop conditions between rounds of tool calls, then makes one closing call with tools off, so a run can go a model call or two past its step or cost limit. At about $0.0004 per call, that overshoot is a fraction of a cent.
- Story IDs join seen.json only when a run finishes, held in fetched.json until then. When the authors killed the process mid-run, the next run finished the digest from saved results; the tradeoff is that a crash after writing the digest can list a story twice.
- The first build reused the conversation across checks, and each run cost slightly more as earlier checks were resent. Deleting state at the start of every new check keeps per-check cost flat, with seen.json carrying the needed memory.
- In a failure test, an approved post ran and the next model call failed. The saved state stayed in_progress with the tool result in history, so the following run continued the conversation without posting again.
- AI agent — An AI system that doesn't just answer once but works toward a goal in a loop — taking actions, reading the results, and deciding what to do next.
- prompt injection — An attack that hides instructions in content an AI will read — a webpage, email, or document — tricking it into following the attacker instead of the user.
Checking sign-in…
Loading comments…






