Skip to main content
This guide shows you how to send a message to an agent and handle the response. You will learn about blocking vs. non-blocking requests, context management, and error handling.

Prerequisites

  • An existing agent (see Create an agent)
  • An access token or client credentials
  • Your tenant name

Send a message

Use the HTTP+JSON binding to send a message:

Message structure

A message contains: The request body also accepts an optional configuration object:

Blocking vs. non-blocking

By default, message:send is blocking: the server waits for the task to complete before returning. Set configuration.returnImmediately to true to return as soon as the task is submitted:
With returnImmediately: true, the response returns immediately with the task in TASK_STATE_SUBMITTED or TASK_STATE_WORKING state. Poll the task endpoint or subscribe via SSE to get updates.

Handling the response

The response contains either a task or a message object:
  • task: The agent is performing long-running work. Check task.status.state for the current state. When TASK_STATE_COMPLETED, the agent’s response is in task.history (the last ROLE_AGENT message). Artifacts are in task.artifacts.
  • message: The agent responded directly with a message. The text is in message.parts[0].text.

Context management

The server automatically creates a context if you don’t provide a contextId. The response includes the contextId in the task object. To continue a conversation, include that contextId in subsequent messages:
See Context and memory for details on how context works.

Using data parts for structured context

Pass structured data alongside text using data parts:

Error handling

Errors follow the A2A google.rpc.Status error format:
Common error codes:

Next steps