Repository navigation
Description
Context
Anthropic's Managed Agents can delegate tool execution to self-hosted sandboxes while Anthropic runs the agent loop and model. Sprites documents a first-party integration for this: https://docs.sprites.dev/integrations/claude-managed-agents/
The shape is a work queue:
- Anthropic runs the loop, model, and session state, and queues work items.
- Your infra runs a supervised worker that claims work items and spawns a per-session Sprite.
- Tool calls execute inside the Sprite; results flow back. The org API key never reaches the Sprite — the runner authenticates with a scoped environment key.
Per-session Sprite lifecycle from the docs: create-or-reuse, upload and exec Anthropic's runner, register a keep-alive task (5-min expiry, heartbeated every 60s), run the session, then pause-on-idle or DELETE /v1/sprites/{name}. A prepared checkpoint pool is suggested to skip the per-session runner install.
Why this fits chant
That lifecycle is an Op composition over primitives the fly lexicon already ships:
| Integration step | existing primitive |
|---|---|
| spawn per-session Sprite | spriteCreate |
| upload + run the runner | spriteExec |
| 60s heartbeat / 5-min keep-alive | safeHeartbeat |
| prepared-pool fast start | spriteCheckpoint / spriteRestore |
| teardown | spriteDestroy |
So this is a worker Op, not a new resource type. The persistence is per-session, worker-orchestrated, pause-on-idle — not reconciled desired state. This confirms the #762 decision (Sprites are runtime-orchestration primitives) rather than reopening it. Stays inside the fly lexicon; no lexicon-boundary change.
Proposal
A chant Op (and a runnable example) that runs the Managed Agents worker on Sprites.
New pieces beyond the shipped activities:
- the supervised worker loop — claim work items from the Anthropic environments API (poller or webhook), one Sprite per session id;
- the keep-alive idiom — a task with an expiry, heartbeated on an interval, held for the duration of a session (5-min / 60s per the docs), expressed with
safeHeartbeat; - a prepared-checkpoint-pool helper — pre-bake a Sprite with the runner installed,
spriteRestoreper session for fast start.
Credential boundary: the org API key stays with the worker; only the scoped environment key reaches the Sprite. The runner env contract is written to a file, sourced, then deleted (never passed as process args) — mirror that in the Op.
To investigate
- Confirm the Anthropic environments/work API surface used to claim and complete work items (endpoints, beta header, delivery/reclaim semantics).
- Map the keep-alive task (expiry + heartbeat) onto chant's heartbeat semantics — is
safeHeartbeatenough, or is a new interval-task helper warranted? - Prepared-pool: what does
spriteCheckpointcapture, and does restore-from-pool preserve the installed runner cleanly? - Where the worker runs: local Op executor via
chant runvs a Temporal schedule for an always-on poller. - Whether any of this belongs as reusable fly activities vs example-only glue.
Acceptance criteria
- A runnable example (e.g.
examples/sprites-managed-agent-worker) that stands up the worker against the Sprites emulator, claims a work item, spawns a Sprite, runs a trivial session end-to-end, and tears down. - The worker loop and keep-alive expressed as a chant Op over the existing sprite activities; any genuinely reusable glue promoted into the fly lexicon.
- The credential boundary honored (org key never reaches the Sprite; env contract file sourced-then-deleted).
- A skill/docs note showing the pattern, consistent with the existing Sprites Op skill.
Parent epic: #736 (Fly.io apply path). Builds on #762 (Sprite Op activities) and #766 (real Sprites API surface).
Activity
lex00 commentedon Jul 13, 2026
Tracked under epic #736 (Follow-ups).
lex00 commentedon Jul 13, 2026
Keep-alive: use the Sprites Tasks API
Grounding the keep-alive step from the docs (https://docs.sprites.dev/keeping-sprites-running/). The mechanism is the Tasks API, not a generic sleep loop:
POST /v1/tasks— create a hold (201). Body takesexpire(seconds int or duration string e.g."5m"). Max lifetime per task is 1 hour.PUT /v1/tasks/:name— refresh expiry (200).DELETE /v1/tasks/:name— release the hold (204).GET /v1/tasks— list active tasks.While at least one task exists, the Sprite will not pause. For work over an hour, run the refresh loop: short expiry, refreshed on a shorter interval, deleted on exit. Docs recommend 5-min expiry refreshed every 60s (four missed heartbeats of margin), with
trap DELETE EXITso a crash still frees the Sprite (and the task auto-expires if cleanup fails).Map onto chant: the worker Op holds a task for the session's duration, driving the refresh with
safeHeartbeat. Investigate whethersafeHeartbeatalone suffices or whether an interval-task helper (spriteTaskHoldcreate/refresh/release) is worth adding to the fly activities — the 1-hour cap makes the refresh loop mandatory, so a small helper likely earns its place.Related: filesystem activities #848 (stage the env-contract file, retrieve outputs); service-reconcile #849 (the runner runs as a supervised service).
lex00 commentedon Jul 13, 2026
Demo plan — this is the one new tutorial
examples/sprites-managed-agent-workeris the single new example for this batch of Sprite features. It composes the filesystem activities (#848 — stage the runner env-contract file, retrieve outputs) and the reconcile primitives (#849 — runner-as-service, per-session egress allowlist) into one end-to-end story. #848 and #849 add no examples of their own; this is where they surface.Offline-runnability decision: fake the work queue
The other Sprite/fly examples run green offline against the emulator, and this one should too. The Sprite side fakes via
createSpritesFake(), but the Anthropic work-queue side (environments API, work items) has no emulator.Decision: fake the work queue in-example — a tiny stub feeds one work item so the whole tutorial runs offline with no key, proving the orchestration. Document the real path in the README (
ANTHROPIC_API_KEY+ a Sprites token, drop the stub), mirroring howlocal-flyruns against mudflaps offline but the same op hits real Fly unchanged. Do not gate the tutorial on a real key.feat(fly): reconcile a Sprite's network policy + services (#849)
feat(fly): Managed Agents worker Op on Sprites + keep-alive Tasks (#847)
feat(fly): reconcile a Sprite's network policy + services (#849) (#854)
feat(fly): Managed Agents worker Op on Sprites + keep-alive Tasks (#847)
feat(fly): Managed Agents worker Op on Sprites + keep-alive Tasks (#847…
lifecycle: emit --json for the --live diff path (#852) (#857)
fly: pin spritzer 0.4.0 + extend the Sprites contract for fs/policy/s…
release: chant 0.18.8 (#861)
docs: Managed Agents worker tutorial + sidebar (#864)
docs: Managed Agents worker tutorial + sidebar (#864) (#865)