产品介绍

Integrate with A2A

Use JSON-RPC to send a message to DataAgent, then poll or cancel the Task. To let DataAgent call another agent, configure an outbound connection below. See the A2A reference for request fields, states, and errors.

Discover the agent

Start a local control plane using the quick start. This example uses http://127.0.0.1:8790. To run A2A by itself, use dataagent serve-a2a and substitute its listen address in the commands.

curl -fsS http://127.0.0.1:8790/.well-known/agent-card.json

The Card is public and lists the JSON-RPC endpoint. If your deployment requires authentication, add -H "Authorization: Bearer $DATAAGENT_A2A_AUTH_TOKEN" to each JSON-RPC command below after setting the token in your client terminal. To enable the token on a server you operate, set DATAAGENT_A2A_AUTH_TOKEN in its startup environment and restart. See authentication precedence and scope.

Send a message

Send a text message and ask the server to return a Task for polling:

curl --include -sS http://127.0.0.1:8790/a2a/jsonrpc \
  -H 'Content-Type: application/json' \
  -H 'A2A-Version: 1.0' \
  -d '{
    "jsonrpc": "2.0", "id": "send-1", "method": "SendMessage",
    "params": {
      "message": {
        "role": "ROLE_USER", "messageId": "message-1",
        "parts": [{"text": "Reply with a short greeting."}]
      },
      "configuration": {"returnImmediately": true}
    }
  }'

The result.task object contains three fields for verification and subsequent calls.

Field Use
id Pass it to GetTask or CancelTask
contextId Set message.contextId on a follow-up and generate a new messageId
status.state Distinguish queued, running, paused, and finished tasks

Omit returnImmediately to let SendMessage wait until the turn finishes or pauses. On success, result.task.status.state is TASK_STATE_COMPLETED and result.task.artifacts contains dataagent_result.

Poll or cancel

Replace TASK_ID with the returned Task ID. Poll while its state is TASK_STATE_SUBMITTED or TASK_STATE_WORKING:

curl --include -sS http://127.0.0.1:8790/a2a/jsonrpc \
  -H 'Content-Type: application/json' \
  -H 'A2A-Version: 1.0' \
  -d '{"jsonrpc":"2.0","id":"poll-1","method":"GetTask","params":{"id":"TASK_ID"}}'

When GetTask reports TASK_STATE_COMPLETED, read the text artifact named dataagent_result from result.artifacts. For TASK_STATE_INPUT_REQUIRED, submit a structured answer. To stop a pending or running Task, set method to CancelTask in the same request, then query the Task to confirm its state. Stopping polling does not cancel a Task.

For errors, keep the response's X-Request-ID, the Task ID, and the context ID. The diagnostic fields identify whether the request was rejected or the Task failed during execution.

Call another agent from DataAgent

Add the remote service root to the caller's config.yaml:

a2a:
  remote_agents:
    - id: sales
      url: http://127.0.0.1:9999
      description: Retrieve sales metrics by time, region, and product.

Start the caller with this config and ask it to call a2a__sales. If the peer requires a token or a different timeout, use the outbound configuration fields. Each local thread keeps a separate remote context.

Call directly from Python

Reuse the client for a follow-up in the same remote context. See the Python API for available arguments and errors.

import asyncio

from dataagent.extensions.a2a import A2ACaller


async def ask():
    caller = A2ACaller("http://127.0.0.1:9999")
    first = await caller.send("hello")
    second = await caller.send("continue")
    print(first.text, second.text)


asyncio.run(ask())