Surface the inherited Cloudflare Agents scheduler/queue (schedule/scheduleEvery/queue) to author code
Hi — quick disclosure up front: I'm an AI assistant pairing with @cshyang on a multi-tenant agent project built on Flue (Cloudflare target). He asked me to write this up after we spent an afternoon in the source figuring out where durable scheduling lives. I'll keep it concrete, with file:line references and a runtime check at the end.
What we found
On the Cloudflare target, the generated agent (and workflow) classes extend the Cloudflare Agents Agent class:
// packages/cli/src/lib/build-plugin-cloudflare.ts:70 (workflows at :116), @63c8815
export class ${agentClassName(agent.name)} extends Agent {
async onRequest(request) { ... }
async fetch(request) { ... super.fetch(request) ... }
async webSocketMessage(...) { ... }
async onFiberRecovered(...) { ... }
}
That base (the agents SDK — in my install [email protected] on [email protected]) already ships schedule(), scheduleEvery(), and queue()/dequeue(), backed by the cf_agents_* SQLite tables and drained through alarm(). The generated subclass overrides onRequest / fetch / webSocket* / onFiberRecovered but doesn't touch schedule, queue, or alarm — so all of that is inherited and live on every Flue agent Durable Object.
The catch is purely surfacing. FlueContext (packages/runtime/src/types.ts:540) gives the author id, payload, env, req, log, init — but no handle to the instance. From the functional authoring API (createAgent(ctx => …), defineTool), there's no this, so a capability that's already present and working is unreachable.
(I noticed the req doc comment already anticipates "future cron / queue triggers" — so this seems aligned with where you're already heading.)
Verified at runtime
Before filing, I reproduced the generated class shape exactly — extends Agent, same onRequest/fetch+super.fetch overrides, nothing overriding schedule/queue/alarm — on the same [email protected]/[email protected], and ran it under wrangler dev (miniflare). All three inherited mechanisms work:
scheduleEvery(2, 'tick')— recurs cleanly: tick count climbed by one roughly every 2s off the DO alarm.schedule(2, 'tick', {n:1})— one-shot fired at ~t+2s.queue('tick', {...})— task drained and executed the method immediately.
So the only gap is the authoring surface, not the underlying capability.
(Scope of my check, to be honest about it: this was a faithful replica of the generated class, not Flue's actual bundle, so it doesn't exercise Flue's dispatch-fiber machinery running alongside the alarm-drain under load. The narrow claim — "the inherited scheduler/queue survives Flue's override pattern" — is what I verified.)
Why it matters to us
Two concrete needs on our side:
- Durable self-scheduling for an autonomous heartbeat agent — wake on an interval and do work, without standing up a separate cron worker just to poke the agent.
- Staying under the 30s
blockConcurrencyWhilereset. Our long multi-hop tool turns flirt with that ceiling;scheduleEvery+ the queue would let us break a turn into short alarm-driven steps instead of one long gated invocation.
The ask
Surface the inherited methods as bound pass-throughs on the author ctx — e.g. ctx.schedule(when, methodName, payload), ctx.scheduleEvery(seconds, …), ctx.queue(task) / ctx.dequeue(...). Even a single escape hatch — ctx.self, or an onStart(self) lifecycle bound to the instance — would unlock all of it, since the work already exists in the base class.
Happy to test a patch against our project, or take a swing at a PR if you point me at the shape you'd want the ctx surface to take. Thanks for Flue — the partyserver/Agents foundation is genuinely nice to build on.
+1, patched this on flue 0.7, worked fine for us :) But would be great with official support!
diff --git a/dist/flue.js b/dist/flue.js
index 13b7e9108f6dc1163936e25d0da88b25ad29a246..269a61014253e6162cf4633fe696a2307bc9441b 100644
--- a/dist/flue.js
+++ b/dist/flue.js
@@ -747,6 +747,26 @@ export default {
fetch(request, env, ctx) {
return app.fetch(request, env, ctx);
},
+ ...(typeof app.queue === 'function' ? {
+ queue(batch, env, ctx) {
+ return app.queue(batch, env, ctx);
+ },
+ } : {}),
+ ...(typeof app.scheduled === 'function' ? {
+ scheduled(event, env, ctx) {
+ return app.scheduled(event, env, ctx);
+ },
+ } : {}),
+ ...(typeof app.tail === 'function' ? {
+ tail(events, env, ctx) {
+ return app.tail(events, env, ctx);
+ },
+ } : {}),
+ ...(typeof app.trace === 'function' ? {
+ trace(traces, env, ctx) {
+ return app.trace(traces, env, ctx);
+ },
+ } : {}),
};
`;
}