Starting April 29, 2025, Gemini 1.5 Pro and Gemini 1.5 Flash models are not available in projects that have no prior usage of these models, including new projects. For details, see Model versions and lifecycle.
You can interact with A2A agents deployed to Agent Engine using the
Vertex AI SDK for Python, using the same syntax.
To set up A2A with Agent Engine, get an instance of the deployed agent. This instance wraps the
underlying A2A endpoints, allowing you to call the endpoints as Python methods.
importvertexaifromgoogle.genaiimporttypes# Replace with your actual valuesPROJECT_ID="your-project-id"LOCATION="your-location"REASONING_ENGINE_ID="your-reasoning-engine-id"AGENT_ENGINE_RESOURCE=f"projects/{PROJECT_ID}/locations/{LOCATION}/reasoningEngines/{REASONING_ENGINE_ID}"client=vertexai.Client(project=PROJECT_ID,location=LOCATION,http_options=types.HttpOptions(api_version="v1beta1"))remote_agent=client.agent_engines.get(name=AGENT_ENGINE_RESOURCE,)
A2A Python SDK
This method uses the official A2A Python SDK, which provides a client
library for interacting with A2A-compliant agents. For more information, see
the A2A Python SDK
documentation.
First, install the SDK:
pipinstalla2a-sdk>=0.3.4
Then, get the agent's card to create a client instance. The A2AClient
handles the discovery and communication for you.
fromgoogle.authimportdefaultfromgoogle.auth.transport.requestsimportRequestfroma2a.clientimportClientConfig,ClientFactoryfroma2a.typesimportTransportProtocolimporthttpx# We assume 'agent_card' is an existing AgentCard object.# Fetch credentials for authentication for demo purpose. Use your own authcredentials,_=default(scopes=['https://www.googleapis.com/auth/cloud-platform'])credentials.refresh(Request())# Create the client by chaining the factory and config initialization.factory=ClientFactory(ClientConfig(supported_transports=[TransportProtocol.http_json],# only support http_jsonuse_client_preference=True,httpx_client=httpx.AsyncClient(headers={"Authorization":f"Bearer {credentials.token}","Content-Type":"application/json",}),))a2a_client=factory.create(agent_card)
Python requests library
The A2A protocol is built on standard HTTP endpoints. You can interact with
these endpoints using any HTTP client.
Retrieve the A2A URL from the agent card and define the request
headers.
fromgoogle.authimportdefaultfromgoogle.auth.transport.requestsimportRequest# We assume 'agent_card' is an existing objecta2a_url=agent_card.url# Get an authentication token for demonstration purposes. Use your own authentication mechanism.credentials,_=default(scopes=['https://www.googleapis.com/auth/cloud-platform'])credentials.refresh(Request())headers={"Authorization":f"Bearer {credentials.token}","Content-Type":"application/json",}
Retrieve the agent card
Note that Agent Engine does not serve the public agent card. To retrieve the
authenticated agent card:
message_data={"messageId":"remote-agent-message-id","role":"user","parts":[{"kind":"text","text":"What is the exchange rate from USD to EUR today?"}],}response=awaitremote_agent.on_message_send(**message_data)
A2A Python SDK
froma2a.typesimportMessage,Part,TextPartimportpprintmessage=Message(message_id="remote-agent-message-id",role="user",parts=[Part(root=TextPart(text="What's the currency rate of USD and EUR"))],)response_iterator=a2a_client.send_message(message)asyncforchunkinresponse_iterator:pprint.pp(chunk)
Python requests library
importhttpximportjsonendpoint=f"{a2a_url}/v1/message:send"payload={"message":{"messageId":"remote-agent-message-id","role":"1","content":[{"text":"What is the exchange rate from USD to EUR today?"}],},"metadata":{"source":"python_script"},}response=httpx.post(endpoint,json=payload,headers=headers)print(json.dumps(response.json(),indent=4))
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-10 UTC."],[],[],null,["| **Preview**\n|\n|\n| This feature is\n|\n| subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section of the\n| [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nIn addition to the general instructions for [using an\nagent](/vertex-ai/generative-ai/docs/agent-engine/use), this page describes features that\nare specific to A2A agents.\n\nBefore you begin\n\nThis tutorial assumes that you have read and followed the instructions in:\n\n- [Develop an Agent2Agent\n Agent](/vertex-ai/generative-ai/docs/agent-engine/develop/a2a) to develop an agent as an instance of `A2aAgent`.\n- [User\n authentication](/vertex-ai/generative-ai/docs/agent-engine/set-up#authentication) to authenticate as a user for querying the agent.\n\nSupported operations\n\nAn A2A agent hosted on Agent Engine exposes a set of operations that correspond\ndirectly to the A2A protocol's API endpoints.\n\n- [`on_message_send`](#send_a_message): Sends a new message to the agent to start a task.\n- [`on_get_task`](#get_a_task): Retrieves the status and artifacts of an existing task.\n- [`on_cancel_task`](#cancel_a_task): Cancels a running task.\n- [`handle_authenticated_agent_card`](#retrieve_the_agent_card): Retrieves the agent's full capabilities and skills.\n\nSetup \n\nVertex AI SDK for Python\n\nYou can interact with A2A agents deployed to Agent Engine using the\nVertex AI SDK for Python, using the same syntax.\n\nTo set up A2A with Agent Engine, get an instance of the deployed agent. This instance wraps the\nunderlying A2A endpoints, allowing you to call the endpoints as Python methods. \n\n import https://cloud.google.com/python/docs/reference/vertexai/latest/\n from google.genai import types\n\n # Replace with your actual values\n PROJECT_ID = \"your-project-id\"\n LOCATION = \"your-location\"\n REASONING_ENGINE_ID = \"your-reasoning-engine-id\"\n AGENT_ENGINE_RESOURCE = f\"projects/{PROJECT_ID}/locations/{LOCATION}/reasoningEngines/{REASONING_ENGINE_ID}\"\n\n client = https://cloud.google.com/python/docs/reference/vertexai/latest/.Client(\n project=PROJECT_ID,\n location=LOCATION,\n http_options=types.HttpOptions(\n api_version=\"v1beta1\")\n )\n\n remote_agent = client.agent_engines.get(\n name=AGENT_ENGINE_RESOURCE,\n )\n\nA2A Python SDK\n\nThis method uses the official A2A Python SDK, which provides a client\nlibrary for interacting with A2A-compliant agents. For more information, see\nthe [A2A Python SDK\ndocumentation](https://a2a-protocol.org/latest/sdk/python/).\n\nFirst, install the SDK: \n\n pip install a2a-sdk\u003e=0.3.4\n\nThen, get the agent's card to create a client instance. The `A2AClient`\nhandles the discovery and communication for you. \n\n from google.auth import default\n from google.auth.transport.requests import Request\n from a2a.client import ClientConfig, ClientFactory\n from a2a.types import TransportProtocol\n import httpx\n\n # We assume 'agent_card' is an existing AgentCard object.\n\n # Fetch credentials for authentication for demo purpose. Use your own auth\n credentials, _ = default(scopes=['https://www.googleapis.com/auth/cloud-platform'])\n credentials.refresh(Request())\n\n # Create the client by chaining the factory and config initialization.\n factory = ClientFactory(\n ClientConfig(\n supported_transports=[TransportProtocol.http_json], # only support http_json\n use_client_preference=True,\n httpx_client=httpx.AsyncClient(\n headers={\n \"Authorization\": f\"Bearer {credentials.token}\",\n \"Content-Type\": \"application/json\",\n }\n ),\n )\n )\n a2a_client = factory.create(agent_card)\n\nPython requests library\n\nThe A2A protocol is built on standard HTTP endpoints. You can interact with\nthese endpoints using any HTTP client.\n\nRetrieve the A2A URL from the agent card and define the request\nheaders. \n\n from google.auth import default\n from google.auth.transport.requests import Request\n\n # We assume 'agent_card' is an existing object\n a2a_url = agent_card.url\n\n # Get an authentication token for demonstration purposes. Use your own authentication mechanism.\n credentials, _ = default(scopes=['https://www.googleapis.com/auth/cloud-platform'])\n credentials.refresh(Request())\n\n headers = {\n \"Authorization\": f\"Bearer {credentials.token}\",\n \"Content-Type\": \"application/json\",\n }\n\nRetrieve the agent card\n\nNote that Agent Engine does not serve the public agent card. To retrieve the\nauthenticated agent card: \n\nVertex AI SDK for Python \n\n response = await remote_agent.handle_authenticated_agent_card()\n\nA2A Python SDK \n\n response = await a2a_client.get_card()\n\nPython requests library \n\n card_endpoint = f\"{a2a_url}/v1/card\"\n response = httpx.get(card_endpoint, headers=headers)\n print(json.dumps(response.json(), indent=4))\n\nSend a message\n\nTo send a message: \n\nVertex AI SDK for Python \n\n message_data = {\n \"messageId\": \"remote-agent-message-id\",\n \"role\": \"user\",\n \"parts\": [{\"kind\": \"text\", \"text\": \"What is the exchange rate from USD to EUR today?\"}],\n }\n\n response = await remote_agent.on_message_send(**message_data)\n\nA2A Python SDK \n\n from a2a.types import Message, Part, TextPart\n import pprint\n\n message = Message(\n message_id=\"remote-agent-message-id\",\n role=\"user\",\n parts=[Part(root=TextPart(text=\"What's the currency rate of USD and EUR\"))],\n )\n\n response_iterator = a2a_client.send_message(message)\n\n async for chunk in response_iterator:\n pprint.pp(chunk)\n\nPython requests library \n\n import httpx\n import json\n\n endpoint = f\"{a2a_url}/v1/message:send\"\n\n payload = {\n \"message\": {\n \"messageId\": \"remote-agent-message-id\",\n \"role\": \"1\",\n \"content\": [{\"text\": \"What is the exchange rate from USD to EUR today?\"}],\n },\n \"metadata\": {\"source\": \"python_script\"},\n }\n\n response = httpx.post(endpoint, json=payload, headers=headers)\n print(json.dumps(response.json(), indent=4))\n\nGet a task\n\nTo get a task and its status \n\nVertex AI SDK for Python \n\n task_data = {\n \"id\": task_id,\n }\n\n response = await remote_agent.on_get_task(**task_data)\n\nA2A Python SDK \n\n from a2a.types import TaskQueryParams\n\n task_data ={\n \"id\":task_id,\n }\n response = await a2a_client.get_task(TaskQueryParams(**task_data))\n\nPython requests library \n\n task_end_point = f\"{a2a_url}/v1/tasks/{task_id}\"\n response = httpx.get(task_end_point, headers=headers)\n print(json.dumps(response.json(), indent=4))\n\nCancel a task\n\nTo cancel a task: \n\nVertex AI SDK for Python \n\n task_data = {\n \"id\": task_id,\n }\n response = await remote_agent.on_cancel_task(**task_data)\n\nA2A Python SDK \n\n from a2a.types import TaskQueryParams\n\n task_data ={\n \"id\":task_id,\n }\n response = await a2a_client.cancel_task(TaskQueryParams(**task_data))\n\nPython requests library \n\n task_end_point = f\"{a2a_url}/v1/tasks/{task_id}:cancel\"\n response = httpx.post(task_end_point, headers=headers)\n print(json.dumps(response.json(), indent=4))\n\nWhat's next\n\n- [Use an agent](/vertex-ai/generative-ai/docs/agent-engine/use).\n- [Evaluate an agent](/vertex-ai/generative-ai/docs/agent-engine/evaluate).\n- [Manage deployed agents](/vertex-ai/generative-ai/docs/agent-engine/manage).\n- [Get support](/vertex-ai/generative-ai/docs/agent-engine/support)."]]