Add reference agent runners (run_worker / serve_queue)#42
Merged
Conversation
The reusable worker loop a served agent runs, shipped once instead of rewritten per agent. hallpass runs no model loop of its own; what a spawned agent still needs is the loop around its work, and that loop is model-agnostic: - serve_queue(queue, worker, handlers, ...) claims from a TaskQueue, dispatches by operation to a handler, and completes each task -- idempotent and lease-safe. A raising handler completes ok=False with only the exception type (never its message), mirroring the orchestrator Worker; an unknown op completes ok=False note 'no handler'. - run_worker(worker, ...) is the same loop over an A2A Worker/channel. - Both take stop / max_idle_rounds (serve-forever or drain-and-return), an injectable sleep (loops test without wall-clock waits), and a heartbeat hook -- wire bus.announce into it to hold a live-roster seat, tying serving and presence together. The handler acts with the agent's scoped token; the auth boundary is unchanged. Demo: examples/reference_agent.py. 320 tests (+10), mypy --strict, ruff, catalog freshness green. v1.9.0. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference agent runners (
run_worker/serve_queue)The reusable worker loop a served agent runs — shipped once instead of rewritten per agent. hallpass provisions the identity, scope, channel, and durable queue, but it runs no model loop of its own (that's deliberate). What a spawned agent still needs is the loop around its work — claim/receive, run, report, heartbeat, stop — and that loop is the same whichever model (or none) sits inside a handler.
serve_queue(queue, worker, handlers, …)— claims one task from aTaskQueueper pass, dispatches tohandlers[task.do], and completes it. The handler's returned mapping becomes the result fields (ok=True); an unknown operation completesok=Falsenote"no handler"; a raising handler completesok=Falsewith only the exception type as the note, never its message (mirrors the orchestratorWorker). Idempotent + lease-safe, so an expired-lease re-run can't overwrite a recorded result.run_worker(worker, …)— the same loop over an A2AWorker/channel.Both take:
stoppredicate and/ormax_idle_rounds— serve-forever or drain-and-return (neither set ⇒ drain once and return, never a busy-spin).sleep— the loops test without wall-clock waits.heartbeathook — wirebus.announceinto it to hold a live-roster seat, tying serving and presence (v1.7) together.The auth boundary is unchanged: a handler acts with the agent's scoped token. The handler is exactly where a model or tool call would go.
Verification
tests/test_runner.py— 10 tests: drain-and-return with no termination, stop predicate,max_idle_roundsends an idle loop (with the right sleep count), heartbeat called each pass, heartbeat holding a roster seat; queue: completes tasks, unknown-op clean fail, handler error reports type only (message not leaked), stop leaves the backlog for another worker, drain-then-return.examples/reference_agent.pyruns and printscompleted 3 tasks; roster now ['resizer-1'].mypy --strict,ruff, catalog freshness all green.Additive. Rounds out the coordination layer (spawn → route → queue → serve), all on the one auth core.