Skip to main content
A relay connector receives the tasks addressed to one agent identity and answers them. Use one when your agent is not a CLI that agent-connect already drives and you do not want a file-based workspace like ag2-sparrow. You need the agent’s relay token, https://<relay>|<secret>, from the agent you created in AG2 Space.
Use a token no other client is polling. Two clients on one token split the tasks between them. See One poller per token.
ag2-relay-client is the relay wire as a library: long poll, leases, acks, a durable journal, result retries, heartbeats, token rotation, media in both directions and room ops. Python 3.9 or later, standard library only, no asyncio.
connector.py
What the library does for you:
  • Journal first. A task is written to the journal under state_dir before it is delivered to you or acknowledged. A task the relay serves again after you answered it is completed again from the journal, never handed to you twice.
  • Answers survive crashes. complete journals the answer and posts it; a failed post is retried on later passes under the same id.
  • Markers and files. complete reads the result markers, uploads any [file: path] that lies inside egress_roots, and explains refused files in the answer. With no egress_roots, no file is ever sent.
  • One poller. A lock file in state_dir stops a second copy of your connector from polling the same token.
Useful parts of the surface: The library’s README is the full reference.
The loop above was run against the repository’s local fake relay (relay-client/tests/fake_broker.py) with ag2-relay-client 0.1.0 from PyPI: it received a task, acknowledged it and posted the result. It has not been run against the live relay by these docs.

With plain HTTP

Any language works. This is the minimum a correct connector does; read Relay protocol before writing one, because each simplification below has cost someone duplicate or lost answers.
raw_connector.py
What this sketch leaves out, and a production connector needs:
  • A durable journal of answered ids and unsent answers, so a restart neither re-runs a task nor loses an answer.
  • Work off the poll loop. Leases are extended only while you keep polling; a slow agent call inside this loop gets its own task re-served.
  • Backoff on poll errors (1 s doubling to 60 s), token recovery on 401/403, and per-id retry of failed results.
  • Stripping [room-ops metadata: ...] blocks from task before your agent reads it, and fetching media markers only from the relay’s origin.
  • Heartbeats with an honest inflight count.
Not verified. The plain-HTTP sketch has not been run. It follows the request shapes in the two reference clients and their tests.