From e3731084d3500c537a648792da3339e18ed64d43 Mon Sep 17 00:00:00 2001 From: Beth Brown Date: Fri, 27 Nov 2026 17:00:59 +0000 Subject: [PATCH 1/4] feat(agentregistry): add ADK and Agent Engine samples with CI scaffolding --- agentregistry/README.md | 43 ++++++++++ agentregistry/adk/clone_remote_agent.py | 78 ++++++++++++++++++ agentregistry/adk/clone_remote_agent_test.py | 39 +++++++++ agentregistry/adk/compose_multi_agent.py | 81 +++++++++++++++++++ agentregistry/adk/compose_multi_agent_test.py | 37 +++++++++ agentregistry/adk/conftest.py | 51 ++++++++++++ agentregistry/adk/deploy_agent_runtime.py | 56 +++++++++++++ .../adk/deploy_agent_runtime_test.py | 46 +++++++++++ .../adk/discover_agents_and_toolsets.py | 54 +++++++++++++ .../adk/discover_agents_and_toolsets_test.py | 39 +++++++++ agentregistry/adk/noxfile_config.py | 29 +++++++ agentregistry/adk/requirements-test.txt | 1 + agentregistry/adk/requirements.txt | 4 + 13 files changed, 558 insertions(+) create mode 100644 agentregistry/adk/clone_remote_agent.py create mode 100644 agentregistry/adk/clone_remote_agent_test.py create mode 100644 agentregistry/adk/compose_multi_agent.py create mode 100644 agentregistry/adk/compose_multi_agent_test.py create mode 100644 agentregistry/adk/conftest.py create mode 100644 agentregistry/adk/deploy_agent_runtime.py create mode 100644 agentregistry/adk/deploy_agent_runtime_test.py create mode 100644 agentregistry/adk/discover_agents_and_toolsets.py create mode 100644 agentregistry/adk/discover_agents_and_toolsets_test.py create mode 100644 agentregistry/adk/noxfile_config.py create mode 100644 agentregistry/adk/requirements-test.txt create mode 100644 agentregistry/adk/requirements.txt diff --git a/agentregistry/README.md b/agentregistry/README.md index e69de29bb2d..d4106abb32d 100644 --- a/agentregistry/README.md +++ b/agentregistry/README.md @@ -0,0 +1,43 @@ +Agent Registry Python Samples +============================= + +Code samples for `Google Cloud Agent Registry`_, using the Agent Development Kit (ADK) and Vertex AI Agent Engine. + +.. _Google Cloud Agent Registry: https://cloud.google.com/agent-registry + +Quick Start +----------- + +1. Select or create a Google Cloud project. +2. Enable billing for your project. +3. Enable the Agent Registry API (`agentregistry.googleapis.com`) and Vertex AI API (`aiplatform.googleapis.com`). +4. Set up `Application Default Credentials`_. +5. Set the required environment variables and install dependencies: + + .. code-block:: bash + + export GOOGLE_CLOUD_PROJECT="your-project-id" + export GOOGLE_CLOUD_LOCATION="global" + cd adk + pip install -r requirements.txt + +.. _Application Default Credentials: https://googleapis.dev/python/google-api-core/latest/auth.html + +Samples +------- + +* `adk/compose_multi_agent.py`: Initialize the ``AgentRegistry`` client and compose an ``LlmAgent`` orchestrator with a remote A2A agent and an MCP toolset. +* `adk/clone_remote_agent.py`: Fetch a remote A2A agent once and clone it across multiple orchestrator agents. +* `adk/discover_agents_and_toolsets.py`: Discover agents by skill tag and retrieve remote agents and MCP toolsets. +* `adk/deploy_agent_runtime.py`: Deploy an A2A agent to Vertex AI Agent Engine so it is automatically registered in Agent Registry. + +Testing +------- + +Tests require a Google Cloud project with ``agentregistry.googleapis.com`` enabled and the following environment variables set: + +* ``GOOGLE_CLOUD_PROJECT``: Google Cloud project ID. +* ``GOOGLE_CLOUD_LOCATION``: Agent Registry location (defaults to ``global``). +* ``AGENTREGISTRY_TEST_AGENT_ID``: ID of a pre-registered A2A agent fixture. +* ``AGENTREGISTRY_TEST_MCP_SERVER_ID``: ID of a pre-registered MCP server fixture. +* ``AGENTREGISTRY_TEST_STAGING_BUCKET``: Cloud Storage bucket URI (``gs://...``) for the Agent Engine deployment test. diff --git a/agentregistry/adk/clone_remote_agent.py b/agentregistry/adk/clone_remote_agent.py new file mode 100644 index 00000000000..831f060e28f --- /dev/null +++ b/agentregistry/adk/clone_remote_agent.py @@ -0,0 +1,78 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from collections.abc import Iterator +import os + +from google.adk.agents.llm_agent import LlmAgent +from google.adk.integrations.agent_registry import AgentRegistry +import google.auth +from google.auth.transport.requests import Request +import httpx + + +def clone_remote_agent( + agent_name: str = "projects/PROJECT_ID/locations/LOCATION/agents/AGENT_ID", + model: str = "gemini-2.5-flash", +) -> tuple[LlmAgent, LlmAgent]: + """Fetches a remote A2A agent once and clones it across orchestrators.""" + project_id = os.environ.get("GOOGLE_CLOUD_PROJECT") + location = os.environ.get("GOOGLE_CLOUD_LOCATION", "global") + + if not project_id: + raise ValueError("GOOGLE_CLOUD_PROJECT environment variable not set.") + + registry = AgentRegistry( + project_id=project_id, + location=location, + ) + + # [START agentregistry_adk_clone_remote_agent] + class GoogleAuth(httpx.Auth): + def __init__(self) -> None: + self.creds, _ = google.auth.default() + + def auth_flow(self, request: httpx.Request) -> Iterator[httpx.Request]: + if not self.creds.valid: + self.creds.refresh(Request()) + request.headers["Authorization"] = f"Bearer {self.creds.token}" + yield request + + httpx_client = httpx.AsyncClient( + auth=GoogleAuth(), + timeout=httpx.Timeout(60.0), + ) + + base_remote_agent = registry.get_remote_a2a_agent( + agent_name=agent_name, + httpx_client=httpx_client, + ) + + flight_orchestrator = LlmAgent( + model=model, + name="flight_orchestrator", + sub_agents=[base_remote_agent.clone()], + ) + + hotel_orchestrator = LlmAgent( + model=model, + name="hotel_orchestrator", + sub_agents=[base_remote_agent.clone()], + ) + # [END agentregistry_adk_clone_remote_agent] + return flight_orchestrator, hotel_orchestrator + + +if __name__ == "__main__": + clone_remote_agent() diff --git a/agentregistry/adk/clone_remote_agent_test.py b/agentregistry/adk/clone_remote_agent_test.py new file mode 100644 index 00000000000..9017f02e60a --- /dev/null +++ b/agentregistry/adk/clone_remote_agent_test.py @@ -0,0 +1,39 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pytest + +import clone_remote_agent + + +def test_clone_remote_agent( + monkeypatch: pytest.MonkeyPatch, + project_id: str, + location: str, + agent_id: str, +) -> None: + monkeypatch.setenv("GOOGLE_CLOUD_PROJECT", project_id) + monkeypatch.setenv("GOOGLE_CLOUD_LOCATION", location) + + flight_orchestrator, hotel_orchestrator = clone_remote_agent.clone_remote_agent( + agent_name=f"projects/{project_id}/locations/{location}/agents/{agent_id}", + ) + + assert flight_orchestrator.name == "flight_orchestrator" + assert hotel_orchestrator.name == "hotel_orchestrator" + assert len(flight_orchestrator.sub_agents) == 1 + assert len(hotel_orchestrator.sub_agents) == 1 + assert ( + flight_orchestrator.sub_agents[0] is not hotel_orchestrator.sub_agents[0] + ) diff --git a/agentregistry/adk/compose_multi_agent.py b/agentregistry/adk/compose_multi_agent.py new file mode 100644 index 00000000000..7190c2ea561 --- /dev/null +++ b/agentregistry/adk/compose_multi_agent.py @@ -0,0 +1,81 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from collections.abc import Iterator +import os + +from google.adk.agents.llm_agent import LlmAgent +from google.adk.integrations.agent_registry import AgentRegistry +import google.auth +from google.auth.transport.requests import Request +import httpx + + +def compose_multi_agent( + agent_name: str = "agents/AGENT_ID", + mcp_server_name: str = "mcpServers/SERVER_ID", + model: str = "gemini-2.5-flash", +) -> LlmAgent: + """Initializes AgentRegistry and composes an orchestrator LlmAgent.""" + # [START agentregistry_adk_initialize_client] + project_id = os.environ.get("GOOGLE_CLOUD_PROJECT") + location = os.environ.get("GOOGLE_CLOUD_LOCATION", "global") + + if not project_id: + raise ValueError("GOOGLE_CLOUD_PROJECT environment variable not set.") + + # Initialize the client + registry = AgentRegistry( + project_id=project_id, + location=location, + ) + # [END agentregistry_adk_initialize_client] + + # [START agentregistry_adk_compose_multi_agent] + class GoogleAuth(httpx.Auth): + def __init__(self) -> None: + self.creds, _ = google.auth.default() + + def auth_flow(self, request: httpx.Request) -> Iterator[httpx.Request]: + if not self.creds.valid: + self.creds.refresh(Request()) + request.headers["Authorization"] = f"Bearer {self.creds.token}" + yield request + + httpx_client = httpx.AsyncClient( + auth=GoogleAuth(), + timeout=httpx.Timeout(60.0), + ) + my_remote_agent = registry.get_remote_a2a_agent( + agent_name=agent_name, + httpx_client=httpx_client, + ) + my_mcp_toolset = registry.get_mcp_toolset(mcp_server_name=mcp_server_name) + + main_agent = LlmAgent( + model=model, + name="travel_orchestrator", + instruction=( + "You are a travel coordinator. You can use your subagents to book " + "travel and your tools to query historical travel data." + ), + tools=[my_mcp_toolset], + sub_agents=[my_remote_agent], + ) + # [END agentregistry_adk_compose_multi_agent] + return main_agent + + +if __name__ == "__main__": + compose_multi_agent() diff --git a/agentregistry/adk/compose_multi_agent_test.py b/agentregistry/adk/compose_multi_agent_test.py new file mode 100644 index 00000000000..32ba8a11512 --- /dev/null +++ b/agentregistry/adk/compose_multi_agent_test.py @@ -0,0 +1,37 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pytest + +import compose_multi_agent + + +def test_compose_multi_agent( + monkeypatch: pytest.MonkeyPatch, + project_id: str, + location: str, + agent_id: str, + mcp_server_id: str, +) -> None: + monkeypatch.setenv("GOOGLE_CLOUD_PROJECT", project_id) + monkeypatch.setenv("GOOGLE_CLOUD_LOCATION", location) + + orchestrator = compose_multi_agent.compose_multi_agent( + agent_name=f"agents/{agent_id}", + mcp_server_name=f"mcpServers/{mcp_server_id}", + ) + + assert orchestrator.name == "travel_orchestrator" + assert len(orchestrator.sub_agents) == 1 + assert len(orchestrator.tools) == 1 diff --git a/agentregistry/adk/conftest.py b/agentregistry/adk/conftest.py new file mode 100644 index 00000000000..792dfb7d242 --- /dev/null +++ b/agentregistry/adk/conftest.py @@ -0,0 +1,51 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import pytest + + +@pytest.fixture() +def project_id() -> str: + return os.environ["GOOGLE_CLOUD_PROJECT"] + + +@pytest.fixture() +def location() -> str: + return os.environ.get("GOOGLE_CLOUD_LOCATION", "global") + + +@pytest.fixture() +def agent_id() -> str: + value = os.environ.get("AGENTREGISTRY_TEST_AGENT_ID") + if not value: + pytest.skip("AGENTREGISTRY_TEST_AGENT_ID environment variable not set.") + return value + + +@pytest.fixture() +def mcp_server_id() -> str: + value = os.environ.get("AGENTREGISTRY_TEST_MCP_SERVER_ID") + if not value: + pytest.skip("AGENTREGISTRY_TEST_MCP_SERVER_ID environment variable not set.") + return value + + +@pytest.fixture() +def staging_bucket() -> str: + value = os.environ.get("AGENTREGISTRY_TEST_STAGING_BUCKET") + if not value: + pytest.skip("AGENTREGISTRY_TEST_STAGING_BUCKET environment variable not set.") + return value diff --git a/agentregistry/adk/deploy_agent_runtime.py b/agentregistry/adk/deploy_agent_runtime.py new file mode 100644 index 00000000000..4a29b30a69e --- /dev/null +++ b/agentregistry/adk/deploy_agent_runtime.py @@ -0,0 +1,56 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +from typing import Any + +import vertexai +from vertexai.agent_engines.templates.a2a import default_a2a_agent + + +def deploy_agent_runtime( + staging_bucket: str | None = None, + display_name: str = "my-support-agent", +) -> Any: + """Deploys an A2A agent to Vertex AI Agent Engine.""" + project_id = os.environ.get("GOOGLE_CLOUD_PROJECT") + location = os.environ.get("GOOGLE_CLOUD_LOCATION", "us-central1") + + if not project_id: + raise ValueError("GOOGLE_CLOUD_PROJECT environment variable not set.") + + client = vertexai.Client(project=project_id, location=location) + my_a2a_agent = default_a2a_agent() + + config: dict[str, Any] = { + "display_name": display_name, + "description": "An agent that handles support tickets.", + "requirements": ["google-cloud-aiplatform[agent_engines,a2a]"], + } + if staging_bucket: + config["staging_bucket"] = staging_bucket + + # [START agentregistry_deploy_agent_runtime] + # Create and deploy the agent + # This action automatically registers the agent in Agent Registry + remote_agent = client.agent_engines.create( + agent=my_a2a_agent, + config=config, + ) + # [END agentregistry_deploy_agent_runtime] + return remote_agent + + +if __name__ == "__main__": + deploy_agent_runtime() diff --git a/agentregistry/adk/deploy_agent_runtime_test.py b/agentregistry/adk/deploy_agent_runtime_test.py new file mode 100644 index 00000000000..8302b441098 --- /dev/null +++ b/agentregistry/adk/deploy_agent_runtime_test.py @@ -0,0 +1,46 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import uuid + +import pytest +import vertexai + +import deploy_agent_runtime + + +def test_deploy_agent_runtime( + monkeypatch: pytest.MonkeyPatch, + project_id: str, + staging_bucket: str, +) -> None: + location = "us-central1" + monkeypatch.setenv("GOOGLE_CLOUD_PROJECT", project_id) + monkeypatch.setenv("GOOGLE_CLOUD_LOCATION", location) + + display_name = f"agentregistry-test-{uuid.uuid4().hex[:8]}" + remote_agent = None + try: + remote_agent = deploy_agent_runtime.deploy_agent_runtime( + staging_bucket=staging_bucket, + display_name=display_name, + ) + assert remote_agent.api_resource.name + finally: + if remote_agent is not None and getattr(remote_agent, "api_resource", None): + client = vertexai.Client(project=project_id, location=location) + client.agent_engines.delete( + name=remote_agent.api_resource.name, + force=True, + ) diff --git a/agentregistry/adk/discover_agents_and_toolsets.py b/agentregistry/adk/discover_agents_and_toolsets.py new file mode 100644 index 00000000000..b159c5cc5b4 --- /dev/null +++ b/agentregistry/adk/discover_agents_and_toolsets.py @@ -0,0 +1,54 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +from typing import Any + +from google.adk.agents.remote_a2a_agent import RemoteA2aAgent +from google.adk.integrations.agent_registry import AgentRegistry +from google.adk.tools.mcp_tool.mcp_toolset import McpToolset + + +def discover_agents_and_toolsets( + agent_name: str = "agents/AGENT_ID", + mcp_server_name: str = "mcpServers/SERVER_ID", + filter_str: str = 'skills.tags:"translation"', +) -> tuple[dict[str, Any], RemoteA2aAgent, McpToolset]: + """Discovers agents by skill tag and fetches a remote agent and MCP toolset.""" + # [START agentregistry_adk_discover_agents_and_toolsets] + project_id = os.environ.get("GOOGLE_CLOUD_PROJECT") + location = os.environ.get("GOOGLE_CLOUD_LOCATION", "global") + + if not project_id: + raise ValueError("GOOGLE_CLOUD_PROJECT environment variable not set.") + + registry = AgentRegistry( + project_id=project_id, + location=location, + ) + + # Discover agents by a required A2A skill, for example, translation + translator_agents = registry.list_agents(filter_str=filter_str) + + # Connect to a remote A2A agent using its resource name + summarizer_agent = registry.get_remote_a2a_agent(agent_name=agent_name) + + # Retrieve an MCP toolset using its resource name + bq_toolset = registry.get_mcp_toolset(mcp_server_name=mcp_server_name) + # [END agentregistry_adk_discover_agents_and_toolsets] + return translator_agents, summarizer_agent, bq_toolset + + +if __name__ == "__main__": + discover_agents_and_toolsets() diff --git a/agentregistry/adk/discover_agents_and_toolsets_test.py b/agentregistry/adk/discover_agents_and_toolsets_test.py new file mode 100644 index 00000000000..5540c6cb68b --- /dev/null +++ b/agentregistry/adk/discover_agents_and_toolsets_test.py @@ -0,0 +1,39 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pytest + +import discover_agents_and_toolsets + + +def test_discover_agents_and_toolsets( + monkeypatch: pytest.MonkeyPatch, + project_id: str, + location: str, + agent_id: str, + mcp_server_id: str, +) -> None: + monkeypatch.setenv("GOOGLE_CLOUD_PROJECT", project_id) + monkeypatch.setenv("GOOGLE_CLOUD_LOCATION", location) + + agents_response, remote_agent, mcp_toolset = ( + discover_agents_and_toolsets.discover_agents_and_toolsets( + agent_name=f"agents/{agent_id}", + mcp_server_name=f"mcpServers/{mcp_server_id}", + ) + ) + + assert isinstance(agents_response, dict) + assert remote_agent is not None + assert mcp_toolset is not None diff --git a/agentregistry/adk/noxfile_config.py b/agentregistry/adk/noxfile_config.py new file mode 100644 index 00000000000..36c64d8361c --- /dev/null +++ b/agentregistry/adk/noxfile_config.py @@ -0,0 +1,29 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Default TEST_CONFIG_OVERRIDE for python repos. + +TEST_CONFIG_OVERRIDE = { + # You can opt out from the test for specific Python versions. + "ignored_versions": ["3.8", "3.9", "3.11", "3.12", "3.13"], + # Old samples are opted out of enforcing Python type hints. + # All new samples should feature them. + "enforce_type_hints": True, + # An envvar key for determining the project id to use. + "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", + # A dictionary you want to inject into your test. + "envs": { + "GOOGLE_CLOUD_LOCATION": "global", + }, +} diff --git a/agentregistry/adk/requirements-test.txt b/agentregistry/adk/requirements-test.txt new file mode 100644 index 00000000000..c9e154ba440 --- /dev/null +++ b/agentregistry/adk/requirements-test.txt @@ -0,0 +1 @@ +pytest==9.0.3; python_version >= "3.10" diff --git a/agentregistry/adk/requirements.txt b/agentregistry/adk/requirements.txt new file mode 100644 index 00000000000..10ce56b7b64 --- /dev/null +++ b/agentregistry/adk/requirements.txt @@ -0,0 +1,4 @@ +google-adk[a2a,agent-identity,mcp]>=1.29.0 +google-cloud-aiplatform[agent_engines]>=1.112.0 +httpx>=0.28.0 +google-auth>=2.0.0 From 5b3d33744212cff52259703e6ea3ccf2844cfdfa Mon Sep 17 00:00:00 2001 From: Beth Brown Date: Fri, 27 Nov 2026 17:06:59 +0000 Subject: [PATCH 2/4] fix(agentregistry): use creds.before_request, align Python versions, fix lint --- agentregistry/adk/clone_remote_agent.py | 9 ++++++--- agentregistry/adk/clone_remote_agent_test.py | 7 ++----- agentregistry/adk/compose_multi_agent.py | 9 ++++++--- agentregistry/adk/compose_multi_agent_test.py | 3 +-- agentregistry/adk/deploy_agent_runtime_test.py | 3 +-- agentregistry/adk/discover_agents_and_toolsets_test.py | 3 +-- agentregistry/adk/noxfile_config.py | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/agentregistry/adk/clone_remote_agent.py b/agentregistry/adk/clone_remote_agent.py index 831f060e28f..802b449708f 100644 --- a/agentregistry/adk/clone_remote_agent.py +++ b/agentregistry/adk/clone_remote_agent.py @@ -44,9 +44,12 @@ def __init__(self) -> None: self.creds, _ = google.auth.default() def auth_flow(self, request: httpx.Request) -> Iterator[httpx.Request]: - if not self.creds.valid: - self.creds.refresh(Request()) - request.headers["Authorization"] = f"Bearer {self.creds.token}" + self.creds.before_request( + Request(), + request.method, + str(request.url), + request.headers, + ) yield request httpx_client = httpx.AsyncClient( diff --git a/agentregistry/adk/clone_remote_agent_test.py b/agentregistry/adk/clone_remote_agent_test.py index 9017f02e60a..bf8d4f7f7be 100644 --- a/agentregistry/adk/clone_remote_agent_test.py +++ b/agentregistry/adk/clone_remote_agent_test.py @@ -12,9 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import pytest - import clone_remote_agent +import pytest def test_clone_remote_agent( @@ -34,6 +33,4 @@ def test_clone_remote_agent( assert hotel_orchestrator.name == "hotel_orchestrator" assert len(flight_orchestrator.sub_agents) == 1 assert len(hotel_orchestrator.sub_agents) == 1 - assert ( - flight_orchestrator.sub_agents[0] is not hotel_orchestrator.sub_agents[0] - ) + assert flight_orchestrator.sub_agents[0] is not hotel_orchestrator.sub_agents[0] diff --git a/agentregistry/adk/compose_multi_agent.py b/agentregistry/adk/compose_multi_agent.py index 7190c2ea561..3e5543ef114 100644 --- a/agentregistry/adk/compose_multi_agent.py +++ b/agentregistry/adk/compose_multi_agent.py @@ -48,9 +48,12 @@ def __init__(self) -> None: self.creds, _ = google.auth.default() def auth_flow(self, request: httpx.Request) -> Iterator[httpx.Request]: - if not self.creds.valid: - self.creds.refresh(Request()) - request.headers["Authorization"] = f"Bearer {self.creds.token}" + self.creds.before_request( + Request(), + request.method, + str(request.url), + request.headers, + ) yield request httpx_client = httpx.AsyncClient( diff --git a/agentregistry/adk/compose_multi_agent_test.py b/agentregistry/adk/compose_multi_agent_test.py index 32ba8a11512..352bcfe47a1 100644 --- a/agentregistry/adk/compose_multi_agent_test.py +++ b/agentregistry/adk/compose_multi_agent_test.py @@ -12,9 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import pytest - import compose_multi_agent +import pytest def test_compose_multi_agent( diff --git a/agentregistry/adk/deploy_agent_runtime_test.py b/agentregistry/adk/deploy_agent_runtime_test.py index 8302b441098..c460551af57 100644 --- a/agentregistry/adk/deploy_agent_runtime_test.py +++ b/agentregistry/adk/deploy_agent_runtime_test.py @@ -14,11 +14,10 @@ import uuid +import deploy_agent_runtime import pytest import vertexai -import deploy_agent_runtime - def test_deploy_agent_runtime( monkeypatch: pytest.MonkeyPatch, diff --git a/agentregistry/adk/discover_agents_and_toolsets_test.py b/agentregistry/adk/discover_agents_and_toolsets_test.py index 5540c6cb68b..edd622a420a 100644 --- a/agentregistry/adk/discover_agents_and_toolsets_test.py +++ b/agentregistry/adk/discover_agents_and_toolsets_test.py @@ -12,9 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import pytest - import discover_agents_and_toolsets +import pytest def test_discover_agents_and_toolsets( diff --git a/agentregistry/adk/noxfile_config.py b/agentregistry/adk/noxfile_config.py index 36c64d8361c..0c7d3273fa6 100644 --- a/agentregistry/adk/noxfile_config.py +++ b/agentregistry/adk/noxfile_config.py @@ -16,7 +16,7 @@ TEST_CONFIG_OVERRIDE = { # You can opt out from the test for specific Python versions. - "ignored_versions": ["3.8", "3.9", "3.11", "3.12", "3.13"], + "ignored_versions": ["3.8", "3.9", "3.10", "3.11", "3.13"], # Old samples are opted out of enforcing Python type hints. # All new samples should feature them. "enforce_type_hints": True, From 63719a0194120bef533ec7e7c64f2a8d9e139bec Mon Sep 17 00:00:00 2001 From: Beth Brown Date: Mon, 30 Nov 2026 14:34:25 +0000 Subject: [PATCH 3/4] fix(agentregistry): convert README to Markdown, rename root_agent, expand region tags --- agentregistry/README.md | 46 ++++++++----------- agentregistry/adk/clone_remote_agent.py | 4 +- agentregistry/adk/compose_multi_agent.py | 26 +++++++---- agentregistry/adk/deploy_agent_runtime.py | 8 ++-- .../adk/discover_agents_and_toolsets.py | 6 ++- 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/agentregistry/README.md b/agentregistry/README.md index d4106abb32d..717f2038e5d 100644 --- a/agentregistry/README.md +++ b/agentregistry/README.md @@ -1,43 +1,35 @@ -Agent Registry Python Samples -============================= +# Agent Registry Python Samples -Code samples for `Google Cloud Agent Registry`_, using the Agent Development Kit (ADK) and Vertex AI Agent Engine. +Code samples for [Google Cloud Agent Registry](https://cloud.google.com/agent-registry), using the Agent Development Kit (ADK) and Vertex AI Agent Engine. -.. _Google Cloud Agent Registry: https://cloud.google.com/agent-registry - -Quick Start ------------ +## Quick Start 1. Select or create a Google Cloud project. 2. Enable billing for your project. 3. Enable the Agent Registry API (`agentregistry.googleapis.com`) and Vertex AI API (`aiplatform.googleapis.com`). -4. Set up `Application Default Credentials`_. +4. Set up [Application Default Credentials](https://googleapis.dev/python/google-api-core/latest/auth.html). 5. Set the required environment variables and install dependencies: - .. code-block:: bash - - export GOOGLE_CLOUD_PROJECT="your-project-id" - export GOOGLE_CLOUD_LOCATION="global" - cd adk - pip install -r requirements.txt - -.. _Application Default Credentials: https://googleapis.dev/python/google-api-core/latest/auth.html + ```bash + export GOOGLE_CLOUD_PROJECT="your-project-id" + export GOOGLE_CLOUD_LOCATION="global" + cd adk + pip install -r requirements.txt + ``` -Samples -------- +## Samples -* `adk/compose_multi_agent.py`: Initialize the ``AgentRegistry`` client and compose an ``LlmAgent`` orchestrator with a remote A2A agent and an MCP toolset. +* `adk/compose_multi_agent.py`: Initialize the `AgentRegistry` client and compose an `LlmAgent` orchestrator with a remote A2A agent and an MCP toolset. * `adk/clone_remote_agent.py`: Fetch a remote A2A agent once and clone it across multiple orchestrator agents. * `adk/discover_agents_and_toolsets.py`: Discover agents by skill tag and retrieve remote agents and MCP toolsets. * `adk/deploy_agent_runtime.py`: Deploy an A2A agent to Vertex AI Agent Engine so it is automatically registered in Agent Registry. -Testing -------- +## Testing -Tests require a Google Cloud project with ``agentregistry.googleapis.com`` enabled and the following environment variables set: +Tests require a Google Cloud project with `agentregistry.googleapis.com` enabled and the following environment variables set: -* ``GOOGLE_CLOUD_PROJECT``: Google Cloud project ID. -* ``GOOGLE_CLOUD_LOCATION``: Agent Registry location (defaults to ``global``). -* ``AGENTREGISTRY_TEST_AGENT_ID``: ID of a pre-registered A2A agent fixture. -* ``AGENTREGISTRY_TEST_MCP_SERVER_ID``: ID of a pre-registered MCP server fixture. -* ``AGENTREGISTRY_TEST_STAGING_BUCKET``: Cloud Storage bucket URI (``gs://...``) for the Agent Engine deployment test. +* `GOOGLE_CLOUD_PROJECT`: Google Cloud project ID. +* `GOOGLE_CLOUD_LOCATION`: Agent Registry location (defaults to `global`). +* `AGENTREGISTRY_TEST_AGENT_ID`: ID of a pre-registered A2A agent fixture. +* `AGENTREGISTRY_TEST_MCP_SERVER_ID`: ID of a pre-registered MCP server fixture. +* `AGENTREGISTRY_TEST_STAGING_BUCKET`: Cloud Storage bucket URI (`gs://...`) for the Agent Engine deployment test. diff --git a/agentregistry/adk/clone_remote_agent.py b/agentregistry/adk/clone_remote_agent.py index 802b449708f..d5bf5487812 100644 --- a/agentregistry/adk/clone_remote_agent.py +++ b/agentregistry/adk/clone_remote_agent.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +# [START agentregistry_adk_clone_remote_agent] from collections.abc import Iterator import os @@ -38,7 +39,6 @@ def clone_remote_agent( location=location, ) - # [START agentregistry_adk_clone_remote_agent] class GoogleAuth(httpx.Auth): def __init__(self) -> None: self.creds, _ = google.auth.default() @@ -73,8 +73,8 @@ def auth_flow(self, request: httpx.Request) -> Iterator[httpx.Request]: name="hotel_orchestrator", sub_agents=[base_remote_agent.clone()], ) - # [END agentregistry_adk_clone_remote_agent] return flight_orchestrator, hotel_orchestrator +# [END agentregistry_adk_clone_remote_agent] if __name__ == "__main__": diff --git a/agentregistry/adk/compose_multi_agent.py b/agentregistry/adk/compose_multi_agent.py index 3e5543ef114..e77e97c5544 100644 --- a/agentregistry/adk/compose_multi_agent.py +++ b/agentregistry/adk/compose_multi_agent.py @@ -22,12 +22,8 @@ import httpx -def compose_multi_agent( - agent_name: str = "agents/AGENT_ID", - mcp_server_name: str = "mcpServers/SERVER_ID", - model: str = "gemini-2.5-flash", -) -> LlmAgent: - """Initializes AgentRegistry and composes an orchestrator LlmAgent.""" +def initialize_registry_client() -> AgentRegistry: + """Initializes the AgentRegistry client from environment variables.""" # [START agentregistry_adk_initialize_client] project_id = os.environ.get("GOOGLE_CLOUD_PROJECT") location = os.environ.get("GOOGLE_CLOUD_LOCATION", "global") @@ -40,9 +36,19 @@ def compose_multi_agent( project_id=project_id, location=location, ) + return registry # [END agentregistry_adk_initialize_client] - # [START agentregistry_adk_compose_multi_agent] + +# [START agentregistry_adk_compose_multi_agent] +def compose_multi_agent( + agent_name: str = "agents/AGENT_ID", + mcp_server_name: str = "mcpServers/SERVER_ID", + model: str = "gemini-2.5-flash", +) -> LlmAgent: + """Initializes AgentRegistry and composes an orchestrator LlmAgent.""" + registry = initialize_registry_client() + class GoogleAuth(httpx.Auth): def __init__(self) -> None: self.creds, _ = google.auth.default() @@ -66,7 +72,7 @@ def auth_flow(self, request: httpx.Request) -> Iterator[httpx.Request]: ) my_mcp_toolset = registry.get_mcp_toolset(mcp_server_name=mcp_server_name) - main_agent = LlmAgent( + root_agent = LlmAgent( model=model, name="travel_orchestrator", instruction=( @@ -76,8 +82,8 @@ def auth_flow(self, request: httpx.Request) -> Iterator[httpx.Request]: tools=[my_mcp_toolset], sub_agents=[my_remote_agent], ) - # [END agentregistry_adk_compose_multi_agent] - return main_agent + return root_agent +# [END agentregistry_adk_compose_multi_agent] if __name__ == "__main__": diff --git a/agentregistry/adk/deploy_agent_runtime.py b/agentregistry/adk/deploy_agent_runtime.py index 4a29b30a69e..a1aa80d6eab 100644 --- a/agentregistry/adk/deploy_agent_runtime.py +++ b/agentregistry/adk/deploy_agent_runtime.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +# [START agentregistry_deploy_agent_runtime] import os from typing import Any @@ -41,15 +42,14 @@ def deploy_agent_runtime( if staging_bucket: config["staging_bucket"] = staging_bucket - # [START agentregistry_deploy_agent_runtime] - # Create and deploy the agent - # This action automatically registers the agent in Agent Registry + # Create and deploy the agent. + # This action automatically registers the agent in Agent Registry. remote_agent = client.agent_engines.create( agent=my_a2a_agent, config=config, ) - # [END agentregistry_deploy_agent_runtime] return remote_agent +# [END agentregistry_deploy_agent_runtime] if __name__ == "__main__": diff --git a/agentregistry/adk/discover_agents_and_toolsets.py b/agentregistry/adk/discover_agents_and_toolsets.py index b159c5cc5b4..6e9c86ecbeb 100644 --- a/agentregistry/adk/discover_agents_and_toolsets.py +++ b/agentregistry/adk/discover_agents_and_toolsets.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +# [START agentregistry_adk_discover_agents_and_toolsets] import os from typing import Any @@ -20,13 +21,14 @@ from google.adk.tools.mcp_tool.mcp_toolset import McpToolset +# agent_name and mcp_server_name accept short ("agents/AGENT_ID", +# "mcpServers/SERVER_ID") or full resource name format. def discover_agents_and_toolsets( agent_name: str = "agents/AGENT_ID", mcp_server_name: str = "mcpServers/SERVER_ID", filter_str: str = 'skills.tags:"translation"', ) -> tuple[dict[str, Any], RemoteA2aAgent, McpToolset]: """Discovers agents by skill tag and fetches a remote agent and MCP toolset.""" - # [START agentregistry_adk_discover_agents_and_toolsets] project_id = os.environ.get("GOOGLE_CLOUD_PROJECT") location = os.environ.get("GOOGLE_CLOUD_LOCATION", "global") @@ -46,8 +48,8 @@ def discover_agents_and_toolsets( # Retrieve an MCP toolset using its resource name bq_toolset = registry.get_mcp_toolset(mcp_server_name=mcp_server_name) - # [END agentregistry_adk_discover_agents_and_toolsets] return translator_agents, summarizer_agent, bq_toolset +# [END agentregistry_adk_discover_agents_and_toolsets] if __name__ == "__main__": From 4f184c7ed185d21fe9aaf577f331bf5e0733cac3 Mon Sep 17 00:00:00 2001 From: Beth Brown Date: Mon, 30 Nov 2026 17:16:39 +0000 Subject: [PATCH 4/4] docs(agentregistry): clarify short and full resource name formats in comments --- agentregistry/adk/clone_remote_agent.py | 2 ++ agentregistry/adk/compose_multi_agent.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/agentregistry/adk/clone_remote_agent.py b/agentregistry/adk/clone_remote_agent.py index d5bf5487812..95654d43286 100644 --- a/agentregistry/adk/clone_remote_agent.py +++ b/agentregistry/adk/clone_remote_agent.py @@ -23,6 +23,8 @@ import httpx +# agent_name accepts short ("agents/AGENT_ID") or full +# ("projects/{project_id}/locations/{location}/agents/AGENT_ID") format. def clone_remote_agent( agent_name: str = "projects/PROJECT_ID/locations/LOCATION/agents/AGENT_ID", model: str = "gemini-2.5-flash", diff --git a/agentregistry/adk/compose_multi_agent.py b/agentregistry/adk/compose_multi_agent.py index e77e97c5544..d72a885744e 100644 --- a/agentregistry/adk/compose_multi_agent.py +++ b/agentregistry/adk/compose_multi_agent.py @@ -41,6 +41,8 @@ def initialize_registry_client() -> AgentRegistry: # [START agentregistry_adk_compose_multi_agent] +# agent_name and mcp_server_name accept short ("agents/AGENT_ID", +# "mcpServers/SERVER_ID") or full resource name format. def compose_multi_agent( agent_name: str = "agents/AGENT_ID", mcp_server_name: str = "mcpServers/SERVER_ID",