Skip to content

Commit edd04c1

Browse 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>
1 parent 5c711cf commit edd04c1

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

‎docs-site/content/kagent/latest/examples/a2a-agents.md‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ The following table covers the methods that this example uses. The `TaskPushNoti
5454

5555
{{< reuse "kagent-docs/snippets/grpcurl-prerequisites.md" >}}
5656

57+
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+
5759
## Read the agent card
5860

5961
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
479481
480482
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" >}}).
481483

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.
489+
```bash
490+
curl -s localhost:8083/agents/kagent/my-first-agent/.well-known/agent-card.json
491+
```
492+
493+
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+
482518
## Clean up
483519

484520
* This example does not create Kubernetes resources, so you have nothing to delete.

‎docs-site/content/kagent/main/examples/a2a-agents.md‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ The following table covers the methods that this example uses. The `TaskPushNoti
5454

5555
{{< reuse "kagent-docs/snippets/grpcurl-prerequisites.md" >}}
5656

57+
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+
5759
## Read the agent card
5860

5961
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
484486
485487
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" >}}).
486488

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.
494+
```bash
495+
curl -s localhost:8083/agents/kagent/my-first-agent/.well-known/agent-card.json
496+
```
497+
498+
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+
487523
## Clean up
488524

489525
* This example does not create Kubernetes resources, so you have nothing to delete.

0 commit comments

Comments
 (0)