You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit edd04c1
Browse filesBrowse the repository at this point in the historyBrowse files
docs: add HTTP/JSON-RPC examples to a2a-agents (#742)
* docs: add HTTP/JSON-RPC examples to a2a-agents (#538)
Signed-off-by: Moritz Schmitz von Hülst <mschmitzvonhuelst@gmail.com>
* docs: address review style feedback in a2a-agents HTTP section (#538)
Signed-off-by: Moritz Schmitz von Hülst <mschmitzvonhuelst@gmail.com>
---------
Signed-off-by: Moritz Schmitz von Hülst <mschmitzvonhuelst@gmail.com>
Co-authored-by: Rachael Graham <rachael.graham@solo.io>
The examples in the rest of this page use `grpcurl` to call the gRPC transport. To call the same service over HTTP/JSON-RPC with `curl`, see [Call an agent over HTTP/JSON-RPC](#call-an-agent-over-httpjson-rpc).
58
+
57
59
## Read the agent card
58
60
59
61
An A2A client typically starts by reading the agent card, which tells it what the agent is and which protocol features the agent supports.
@@ -479,6 +481,40 @@ Answering a pause needs the human-in-the-loop extension, which a caller requests
479
481
480
482
A tool approval works in the same way, but the agent sends `tool_approval_request`, and the caller answers with `tool_approval_response`. For the pause kinds, the approval model, and what a nested agent's pause looks like, see [Human in the loop]({{< link path="agents/human-in-the-loop" >}}).
481
483
484
+
## Call an agent over HTTP/JSON-RPC
485
+
486
+
The `grpcurl` examples in this page call the gRPC transport. The controller serves the same service over HTTP/JSON-RPC on the same port `8083`, where the URL path selects the Agent instead of a `tenant` field. Both transports take the same `A2A-Version: 1.0` header.
487
+
488
+
1. Read the Agent's card with the JSON-RPC interface URL.
The card advertises the JSON-RPC URL first, then the gRPC interface. Point every JSON-RPC call at the `supportedInterfaces` entry whose `protocolBinding` is `JSONRPC`. That entry's `url` is `http://<controller>/agents/<namespace>/<name>`. A hand-assembled HTTP call sets the Agent in the URL and needs no `tenant`. A `tenant` that an HTTP request does supply must match its URL.
494
+
495
+
2. Send a message with a JSON-RPC `2.0` request. The body mirrors the `SendMessage` call from [Send a message](#send-a-message): `messageId`, `role`, and at least one `parts` entry. Omitting both a `contextId` and a task ID starts a new Session.
496
+
```bash
497
+
curl -s -X POST localhost:8083/agents/kagent/my-first-agent \
498
+
-H 'Content-Type: application/json' \
499
+
-H 'A2A-Version: 1.0' \
500
+
-d '{
501
+
"jsonrpc": "2.0",
502
+
"id": "request-1",
503
+
"method": "SendMessage",
504
+
"params": {
505
+
"message": {
506
+
"messageId": "'$(uuidgen)'",
507
+
"role": "ROLE_USER",
508
+
"parts": [{"text": "What is 7 times 6? Answer with just the number."}]
509
+
}
510
+
}
511
+
}'
512
+
```
513
+
514
+
The reply is the same task the `SendMessage` gRPC call returns: the answer arrives in `artifacts`, and `contextId` is the Session ID to repeat on a follow-up message.
515
+
516
+
The JSON-RPC surface uses the A2A v1 method names: `SendMessage`, `SendStreamingMessage` (streams events over the same `POST` endpoint), `GetTask`, `ListTasks`, `CancelTask`, `SubscribeToTask`, and `GetExtendedAgentCard`. Older A2A clients called six of them `message/send`, `message/stream`, `tasks/get`, `tasks/list`, `tasks/cancel`, and `tasks/resubscribe`.
517
+
482
518
## Clean up
483
519
484
520
* This example does not create Kubernetes resources, so you have nothing to delete.
The examples in the rest of this page use `grpcurl` to call the gRPC transport. To call the same service over HTTP/JSON-RPC with `curl`, see [Call an agent over HTTP/JSON-RPC](#call-an-agent-over-httpjson-rpc).
58
+
57
59
## Read the agent card
58
60
59
61
An A2A client typically starts by reading the agent card, which tells it what the agent is and which protocol features the agent supports.
@@ -484,6 +486,40 @@ Answering a pause needs the human-in-the-loop extension, which a caller requests
484
486
485
487
A tool approval works in the same way, but the agent sends `tool_approval_request`, and the caller answers with `tool_approval_response`. For the pause kinds, the approval model, and what a nested agent's pause looks like, see [Human in the loop]({{< link path="agents/human-in-the-loop" >}}).
486
488
489
+
## Call an agent over HTTP/JSON-RPC
490
+
491
+
The `grpcurl` examples in this page call the gRPC transport. The controller serves the same service over HTTP/JSON-RPC on the same port `8083`, where the URL path selects the Agent instead of a `tenant` field. Both transports take the same `A2A-Version: 1.0` header.
492
+
493
+
1. Read the Agent's card with the JSON-RPC interface URL.
The card advertises the JSON-RPC URL first, then the gRPC interface. Point every JSON-RPC call at the `supportedInterfaces` entry whose `protocolBinding` is `JSONRPC`. That entry's `url` is `http://<controller>/agents/<namespace>/<name>`. A hand-assembled HTTP call sets the Agent in the URL and needs no `tenant`. A `tenant` that an HTTP request does supply must match its URL.
499
+
500
+
2. Send a message with a JSON-RPC `2.0` request. The body mirrors the `SendMessage` call from [Send a message](#send-a-message): `messageId`, `role`, and at least one `parts` entry. Omitting both a `contextId` and a task ID starts a new Session.
501
+
```bash
502
+
curl -s -X POST localhost:8083/agents/kagent/my-first-agent \
503
+
-H 'Content-Type: application/json' \
504
+
-H 'A2A-Version: 1.0' \
505
+
-d '{
506
+
"jsonrpc": "2.0",
507
+
"id": "request-1",
508
+
"method": "SendMessage",
509
+
"params": {
510
+
"message": {
511
+
"messageId": "'$(uuidgen)'",
512
+
"role": "ROLE_USER",
513
+
"parts": [{"text": "What is 7 times 6? Answer with just the number."}]
514
+
}
515
+
}
516
+
}'
517
+
```
518
+
519
+
The reply is the same task the `SendMessage` gRPC call returns: the answer arrives in `artifacts`, and `contextId` is the Session ID to repeat on a follow-up message.
520
+
521
+
The JSON-RPC surface uses the A2A v1 method names: `SendMessage`, `SendStreamingMessage` (streams events over the same `POST` endpoint), `GetTask`, `ListTasks`, `CancelTask`, `SubscribeToTask`, and `GetExtendedAgentCard`. Older A2A clients called six of them `message/send`, `message/stream`, `tasks/get`, `tasks/list`, `tasks/cancel`, and `tasks/resubscribe`.
522
+
487
523
## Clean up
488
524
489
525
* This example does not create Kubernetes resources, so you have nothing to delete.
0 commit comments