Skip to main content

Let an outside system call an agent over A2A

By the end of this guide a system that knows nothing about Interlinked has sent a request to your agent over plain HTTP and read the agent's answer. A2A (Agent2Agent) is an open protocol for calling an agent over HTTP; Outside callers explains the ideas.

This guide is for macOS and Linux. In the expected output, text in angle brackets, such as <bob address>, stands for a value that is different on every machine. The relay here runs on your own computer without TLS so that you can try it; a relay on a network address uses TLS, as in Run a relay on your machine with TLS.

Before you start​

  • Interlinked built and on your PATH, as in Install.
  • Python 3, for the stand-in command that plays the agent, and curl.

1. Start a relay​

il-relay serve --store-dir relay-store --host 127.0.0.1 --port 7000 --no-tls
{"address":"il://127.0.0.1:7000","cert_sha256":"","directory":"<address>","impl":"rust","port":7000,"pub":"<id-1>","tls":false}

2. Create the owner and the agent, and register the agent's command​

alice is the owner: she vouches for the agent and mints tokens for callers. bob is the agent. His command reads the waiting messages and prints an answer. Here a short script prints "PR 42 looks good."; with a real agent you register Claude Code or another host instead (Connect Claude Code):

il init alice --relay 127.0.0.1:7000
{"address": "<alice address>", "home": "~/.interlinked", "launcher": "~/.interlinked/bin/il", "name": "alice", "project": "<project folder>", "rooms_found": 1}
il init bob --relay 127.0.0.1:7000
{"address": "<bob address>", "home": "~/.interlinked", "launcher": "~/.interlinked/bin/il", "name": "bob", "project": "<project folder>", "rooms_found": 0}
cat > reply_agent.py <<'EOF'
import sys
sys.stdin.read()
print('PR 42 looks good.')
EOF
il --as bob agent register bob --host custom --run 'python3 reply_agent.py'
(shortened: fields not discussed here are left out)
{"host": "custom", "name": "bob"}

3. Publish the agent's card​

A card is a short public description of an agent, kept in the relay's directory. alice countersigns it (--owner alice), so callers can tell the agent is the one its owner meant:

il --as bob card publish --relay 127.0.0.1:7000 --name bob --owner alice --skill 'review: reviews pull requests' --no-tls
(shortened: fields not discussed here are left out)
{"agent": "<bob address>", "endorsed": true}
il find review --relay 127.0.0.1:7000 --no-tls
[
{
"agent": "<bob address>",
"name": "bob",
"owner": "<alice address>",
"description": "",
"skills": [
"review"
],
"relays": [
"il://127.0.0.1:7000"
],
"verified": true
}
]

Note the agent value: it is bob's address, and part of the address callers use. Set AGENT to it.

4. Mint a token for the caller​

A token lets one named caller call the agent. This one is for a caller called partner-ci:

il card token --name alice --agent bob --sub partner-ci
(shortened: fields not discussed here are left out)
{"sub": "partner-ci", "token": "<token>"}

Anyone who holds the token can call as partner-ci, so send it over a channel you trust and give it a short life with --ttl SECONDS. Set TOKEN to the value printed after "token".

5. Send a request​

This is what the outside system does. It is one HTTP request:

AGENT=THE_AGENT_ADDRESS_FROM_THE_CARD_STEP
TOKEN=THE_TOKEN_FROM_THE_TOKEN_STEP
curl -s -X POST http://127.0.0.1:7000/a2a/$AGENT -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"message/send","params":{"message":{"kind":"message","messageId":"m1","role":"user","parts":[{"kind":"text","text":"Please review PR 42"}]}}}'
(shortened: fields not discussed here are left out)
{"result": {"id": "<id-2>", "status": {"state": "submitted"}}}

The reply is a task with the state submitted: the relay wrote the request into a room it opened for this caller and bob. Copy its id and set TASKID to it.

6. Let the agent answer​

bob's home has to learn about the room the relay just opened, and il init does that when you give it the relay again ("rooms_found": 1). Then il serve runs bob's command for the waiting request. --once handles what is waiting and exits; without it, il serve bob keeps running and answers as requests arrive:

il init bob --relay 127.0.0.1:7000
{"address": "<bob address>", "home": "~/.interlinked", "launcher": "~/.interlinked/bin/il", "name": "bob", "project": "<project folder>", "rooms_found": 1}
il --as bob serve --once bob
(shortened: fields not discussed here are left out)
{"wakes": [{"ran": true, "exit": 0}]}
TASKID=THE_ID_FROM_THE_SEND_STEP
curl -s -X POST http://127.0.0.1:7000/a2a/$AGENT -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":2,"method":"tasks/get","params":{"id":"'"$TASKID"'"}}'
(shortened: fields not discussed here are left out)
{"result": {"status": {"state": "completed"}, "artifacts": [{"artifactId": "<artifact id>-0", "name": "answer", "parts": [{"kind": "text", "text": "PR 42 looks good."}]}]}}

The caller asks for the task again and gets completed, with bob's answer as an artifact.

Next​

Diagnose problems shows how to find out why a request is not being answered.