Run A2A Tasks in the BackgroundBeta
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: readpermission, and canceling one also needs theservices: writepermission. 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.
GetTaskreads 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.CancelTaskstops a run and answers with the task. It waits up to 2 seconds for the run to stop, so the task is usually in theTASK_STATE_CANCELEDstate. If the run is still stopping after that, the task is returned as it is. CallGetTaskto read its final state. A task that already ended, a canceled one too, answers with a task-not-cancelable error.SubscribeToTaskstreams updates until the task ends. If the task already ended, it answers with an unsupported-operation error, so useGetTaskinstead. The stream also ends, before the task does, when the run can no longer be read or after 10 minutes. CallGetTask, 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 status | Task state |
|---|---|
| Queued | TASK_STATE_SUBMITTED |
| Running or waiting | TASK_STATE_WORKING |
| Completed | TASK_STATE_COMPLETED |
| Failed | TASK_STATE_FAILED |
| Canceled | TASK_STATE_CANCELED |
Troubleshooting
Background runs return these A2A errors:
| A2A error | Cause and fix |
|---|---|
TaskNotFound | The task doesn't exist, or its run has expired. Start a new task. |
InvalidParams | The 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. |
UnsupportedOperation | The 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. |
TaskNotCancelable | The run already ended, whether it completed, failed, or was canceled. Read the result with GetTask. |
InternalError | A temporary condition: the runtime is unavailable or at capacity, or the active revision changed. Retry the request. |
Related Information
Was this page helpful?