Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

Run A2A Tasks in the BackgroundBeta

Beta
This is coming — this page describes a feature that's still being rolled out and may not be available to you yet.

Hand a task to a deployed service over A2A and pick up the result later, so the calling agent doesn't have to wait for the answer. Each background task is a durable run of the deployment.


About This Task​

A SendMessage request with returnImmediately starts a durable run and answers at once with a task. You then read, follow, or cancel the task with its ID. The task ID is the run's execution ID.

Prerequisites​

  • A deployment that meets the eligibility requirements in Use Your Pipelines as A2A Agents and runs durable executions. A pipeline route, or a deployment that can't run durable executions, answers with an unsupported-operation error.
  • A workspace API key or bearer token. Shared and external access tokens can't be used.
  • Read access to the service, which is enough to send a message. Reading or following a task also needs the search-history: read permission, and canceling one also needs the services: write permission. Any caller with these permissions can read or cancel any of the deployment's tasks.

Start a Background Task​

Send a SendMessage request to the deployment's A2A interface URL (see Use Your Pipelines as A2A Agents for how to find it) with configuration.returnImmediately set to true. Include your bearer credential, Content-Type: application/json, and the A2A-Version: 1.0 header.

{
"jsonrpc": "2.0",
"id": "request-2",
"method": "SendMessage",
"params": {
"configuration": {"returnImmediately": true},
"message": {
"messageId": "message-2",
"role": "ROLE_USER",
"parts": [{"text": "What is the answer?"}]
}
}
}

The response is a task in the TASK_STATE_SUBMITTED state. If the pipeline maps a messages input, as a chat pipeline with an agent does, the text is also passed as the user's chat message.

Sending the same messageId again returns the same task, so a retried request never starts a second run. returnImmediately isn't accepted on SendStreamingMessage.

Read, Follow, or Cancel a Task​

Call these methods with the task ID, for example {"id": "<task id>"}. The ID is required: an empty or missing one answers with an invalid-params error.

  • GetTask reads the task. A completed task carries the answer as its artifact. A failed task carries the error in its status message. A completed task whose result can no longer be read, or has no text to return, has no artifact and says so in its status message.
  • CancelTask stops a run and answers with the task. It waits up to 2 seconds for the run to stop, so the task is usually in the TASK_STATE_CANCELED state. If the run is still stopping after that, the task is returned as it is. Call GetTask to read its final state. A task that already ended, a canceled one too, answers with a task-not-cancelable error.
  • SubscribeToTask streams updates until the task ends. If the task already ended, it answers with an unsupported-operation error, so use GetTask instead. The stream also ends, before the task does, when the run can no longer be read or after 10 minutes. Call GetTask, or subscribe again, to keep following the task.

A task stays readable for 7 days. These methods act on a run that already exists, so they keep working after a redeploy moves the deployment to a revision that A2A can't serve.

Task States​

The task state follows the status of the durable run:

Run statusTask state
QueuedTASK_STATE_SUBMITTED
Running or waitingTASK_STATE_WORKING
CompletedTASK_STATE_COMPLETED
FailedTASK_STATE_FAILED
CanceledTASK_STATE_CANCELED

Troubleshooting​

Background runs return these A2A errors:

A2A errorCause and fix
TaskNotFoundThe task doesn't exist, or its run has expired. Start a new task.
InvalidParamsThe request is invalid, the task ID is empty or missing, a message ID was reused with a different message, or its submission window closed. Fix the request, or use a new messageId.
UnsupportedOperationThe deployment can't run durable executions, the token isn't allowed, the deployment wasn't found, or you lack a required permission. Check the prerequisites.
TaskNotCancelableThe run already ended, whether it completed, failed, or was canceled. Read the result with GetTask.
InternalErrorA temporary condition: the runtime is unavailable or at capacity, or the active revision changed. Retry the request.