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:
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 atask or a message object:
task: The agent is performing long-running work. Checktask.status.statefor the current state. WhenTASK_STATE_COMPLETED, the agent’s response is intask.history(the lastROLE_AGENTmessage). Artifacts are intask.artifacts.message: The agent responded directly with a message. The text is inmessage.parts[0].text.
Context management
The server automatically creates a context if you don’t provide acontextId. The response includes the contextId in the task object. To continue a conversation, include that contextId in subsequent messages:
Using data parts for structured context
Pass structured data alongside text using data parts:Error handling
Errors follow the A2Agoogle.rpc.Status error format:
Next steps
- Learn how to stream responses via SSE
- Understand the task lifecycle for long-running work
- Read about contexts for conversation management