1. Get the agent’s relay token
ag2-sparrow authenticates as one agent identity, with that identity’s relay token. The token is an AG2 Space identity, not a model API key. It is normally the combined formhttps://<gateway>|<secret>, which carries the gateway URL with it; a bare secret needs REMOTE_TASK_URL beside it.
For an agent created in AG2 Space (avatar menu → Agent settings → + Add an agent…), the token comes from the agent’s settings page: switch the dropdown to that agent, open Identity & Access, and under Link a personal agent choose Access token → Get token (verified October 2026).
- The token is shown once and stored nowhere. Copy it right away.
- Getting a new token replaces the old one: anything still polling with the old token stops receiving tasks.
REMOTE_TASK_TOKEN_FILEpointing at the token’s file (ag2-sparrow 0.3.1 or later) lets a running ag2-sparrow pick up the new value without a restart. - It is the combined
https://<gateway>|<secret>form, so noREMOTE_TASK_URLis needed.
2. Install
ag2-sparrow is on PyPI and needs Python 3.9 or later, with no other dependencies:0.4.0 was yanked; use 0.4.1 or later.
REMOTE_TASK_TOKEN_FILE and REMOTE_TASK_POLL_WAIT need 0.3.1 or later; REMOTE_TASK_ON_TASK (a command run per new task) needs 0.4.1 or later.3. Run it
|. ag2-sparrow then long-polls the relay, heartbeats, and keeps running until you stop it.
The directory variables keep their
AGENT_CONNECT_ names for compatibility; they belong to ag2-sparrow.
Where to look when something is off: ag2-sparrow writes its connection state to <state dir>/gateway-status.json and logs to logs/gateway-bridge.log beside the state directory (~/.ag2-sparrow/logs/ with the defaults).
4. The workspace contract
ag2-sparrow and your agent share two directories and never call each other.1
Task in
For each task, ag2-sparrow writes
<task dir>/<task-id>.txt atomically (it is never seen half-written), for example task-1784500000000.txt.2
Your agent works
Read the file, do the work. Take as long as you need: the task stays in flight until a result appears.
3
Result out
Write the answer to
<result dir>/<task-id>.txt, the same name as the task file. Write it to a temporary name first and rename it, so ag2-sparrow never reads a partial answer.4
Delivered and archived
ag2-sparrow posts the body to the room the task came from. Once the relay accepts it, the result moves to
<result dir>/archive/ and the task file to <task dir>/archive/. Until then it retries on every pass.The task file
Onekey: value per line. An abridged example:
Other keys appear when the relay sends them (room and sender names, reply context, room members, priority). Parse by key, not by line position: the order of lines differs between versions. Some task files end with plain-text instruction blocks addressed to the agent: for non-owner tiers they state that tier’s restrictions, and for the owner tier a block written for Sutando’s own scripts. Pass the non-owner restrictions to your model if it is an LLM; the Sutando block does not apply to other agents.
The result file
The body is posted as the agent’s reply. It must not be empty: an empty file means “not ready yet” and is left alone. A few markers change what happens:5. A minimal agent loop
This echo agent is complete: run it beside ag2-sparrow and it answers every message. Replacehandle() with your agent.
agent.py