tools / swarm.py
Fire-and-forget background task dispatch to swarm nodes with optional blocking await.
Tool: delegate_to_swarm
Args
tasks: array of{instruction, input_data, output_key, [worker_persona], [target_model]}.await_results: bool — false for fire-and-forget, true to block until all complete.
Execution
- For each task, spawn a
_swarm_workercoroutine with 2 retries and exponential backoff. - POST to
node["client"].post("/v1/chat/completions", {messages:[system: persona, user: instruction + input_data]}). - On success, write the response into scratchpad at
output_key. - Record success/failure with the per-node circuit breaker.
Registry
_swarm_task_registry tracks asyncio.Task objects by id and auto-cleans via a done callback.