Skip to content

feat(agentregistry): add ADK and Agent Engine samples with CI scaffolding - #15002

Open
fatoboist wants to merge 2 commits into
mainfrom
feat/agentregistry-adk-samples
Open

fatoboist wants to merge 2 commits into
mainfrom
feat/agentregistry-adk-samples

Conversation

@fatoboist

Copy link
Copy Markdown
Contributor

Description

Adds CI scaffolding, README, and core ADK / Vertex AI Agent Engine samples for Agent Registry under agentregistry/adk/ (PR A of migrating inline Agent Registry documentation snippets to GitHub; internal tracking: b/581932768).

Files added / updated

  • agentregistry/README.md: Quickstart, sample index, and test environment variable documentation.
  • agentregistry/adk/requirements.txt & requirements-test.txt
  • agentregistry/adk/noxfile_config.py & conftest.py
  • agentregistry/adk/compose_multi_agent.py + compose_multi_agent_test.py (agentregistry_adk_initialize_client, agentregistry_adk_compose_multi_agent)
  • agentregistry/adk/clone_remote_agent.py + clone_remote_agent_test.py (agentregistry_adk_clone_remote_agent)
  • agentregistry/adk/discover_agents_and_toolsets.py + discover_agents_and_toolsets_test.py (agentregistry_adk_discover_agents_and_toolsets)
  • agentregistry/adk/deploy_agent_runtime.py + deploy_agent_runtime_test.py (agentregistry_deploy_agent_runtime)

API & Test Infrastructure Request

To run the integration tests in CI on the shared test projects (python-docs-samples-tests-310 through python-docs-samples-tests-314, specifically python-docs-samples-tests-314), please:

  1. Enable APIs: Enable agentregistry.googleapis.com (and verify aiplatform.googleapis.com is enabled).
  2. Register test fixtures & configure env vars:
    • Register a mock A2A agent and set AGENTREGISTRY_TEST_AGENT_ID
    • Register an MCP server and set AGENTREGISTRY_TEST_MCP_SERVER_ID
    • Provide a Cloud Storage staging bucket URI in AGENTREGISTRY_TEST_STAGING_BUCKET for deploy_agent_runtime_test.py

(Tests skip cleanly when these fixture environment variables are not yet set.)

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended. (Pending agentregistry.googleapis.com enablement and fixture setup in the shared test project.)

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved

@fatoboist
fatoboist requested review from a team as code owners November 27, 2026 17:01
@snippet-bot

snippet-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 5 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label Bot added api: agentregistry Issues related to the Agent Registry API. samples Issues that are directly related to samples. labels Nov 27, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces Python samples for the Google Cloud Agent Registry using the Agent Development Kit (ADK) and Vertex AI Agent Engine, including sample scripts, tests, and configuration files. The review feedback highlights several improvement opportunities: replacing httpx.AsyncClient with synchronous httpx.Client inside a with statement in synchronous functions, utilizing self.creds.before_request for robust credential application, and updating the Python test configuration in noxfile_config.py to align with the minimum supported Python versions of the project's dependencies.

Comment on lines +52 to +60
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,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Since clone_remote_agent is a synchronous function, using httpx.AsyncClient is inappropriate and can lead to unclosed client warnings or event loop issues. Use the synchronous httpx.Client instead, and wrap it in a with statement to ensure connections are properly closed.

    with httpx.Client(
        auth=GoogleAuth(),
        timeout=httpx.Timeout(60.0),
    ) as httpx_client:
        base_remote_agent = registry.get_remote_a2a_agent(
            agent_name=agent_name,
            httpx_client=httpx_client,
        )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping httpx.AsyncClient without a with block here: AgentRegistry.get_remote_a2a_agent() expects httpx.AsyncClient | None and passes it to ADK's RemoteA2aAgent, which executes async HTTP calls when the returned LlmAgent is invoked. Using a synchronous httpx.Client would fail at runtime, and a with block inside clone_remote_agent() would close the client before the returned orchestrators run.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 from the docs side — get_remote_a2a_agent() requires httpx.AsyncClient and keeping it open for RemoteA2aAgent matches our documented behavior.

Comment on lines +56 to +63
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,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Since compose_multi_agent is a synchronous function, using httpx.AsyncClient is inappropriate and can lead to unclosed client warnings or event loop issues. Use the synchronous httpx.Client instead, and wrap it in a with statement to ensure connections are properly closed.

Suggested change
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,
)
with httpx.Client(
auth=GoogleAuth(),
timeout=httpx.Timeout(60.0),
) as httpx_client:
my_remote_agent = registry.get_remote_a2a_agent(
agent_name=agent_name,
httpx_client=httpx_client,
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping httpx.AsyncClient without a with block here: AgentRegistry.get_remote_a2a_agent() expects httpx.AsyncClient | None and passes it to ADK's RemoteA2aAgent, which executes async HTTP calls when the returned LlmAgent is invoked. Using a synchronous httpx.Client would fail at runtime, and a with block inside compose_multi_agent() would close the client before the returned orchestrator runs.

Comment thread agentregistry/adk/clone_remote_agent.py Resolved
Comment thread agentregistry/adk/noxfile_config.py Resolved

@evelyn-goo evelyn-goo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for setting up the scaffolding and migrating these samples, Beth!

Comment thread agentregistry/README.md
@@ -0,0 +1,43 @@
Agent Registry Python Samples

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (blocking): This file is named README.md, but it's written in reStructuredText syntax (.. _Google Cloud Agent Registry:, .. code-block:: bash, double backticks like AgentRegistry). On GitHub, .md files render as Markdown, so those directives and double backticks will show up as raw literal text. Could we convert this to GitHub-flavored Markdown (or rename to README.rst if that's the preferred convention in this repo)?

Comment on lines +45 to +79
# [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]:
self.creds.before_request(
Request(),
request.method,
str(request.url),
request.headers,
)
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]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (blocking): Two doc-parity items to align with resolve-endpoints-and-build-orchestrators.md before we switch the page to a GitHub include:

  • ADK CLI commands (adk run / adk web) expect the module-level variable to be named root_agent, and the paragraph right below this snippet in resolve-endpoints-and-build-orchestrators.md explicitly says "After saving root_agent in your ADK project's agent.py file...". Could we rename main_agent to root_agent?
  • Our current doc prose and callout note specifically explain GoogleApiAuth(quota_project_id), the https://www.googleapis.com/auth/cloud-platform scope, and the X-Goog-User-Project header (and the "Replace the following" list defines QUOTA_PROJECT_ID). Using self.creds.before_request(...) is cleaner, so either we keep GoogleApiAuth with quota_project_id / scopes here, or we make a note to update the surrounding doc prose in resolve-endpoints-and-build-orchestrators.md when we swap in the include—let me know which you prefer!
  • Right now # [START agentregistry_adk_compose_multi_agent] (and # [START agentregistry_adk_initialize_client] above) excludes the import statements and the function parameters (agent_name, mcp_server_name, model), so readers on cloud.google.com won't see the imports or the placeholder values ("agents/AGENT_ID", "mcpServers/SERVER_ID", "gemini-2.5-flash") that the doc's "Replace the following" list refers to. Could we include the imports and variable/parameter definitions inside the region tags (or wrap the function signature inside the tags per python-docs-samples conventions)?

Comment on lines +36 to +51
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]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (blocking): # [START agentregistry_deploy_agent_runtime] currently starts at line 44, after config is defined. That means the rendered snippet in automatic-registration.md will only show client.agent_engines.create(agent=my_a2a_agent, config=config) without showing display_name, description, or requirements. Could we move # [START agentregistry_deploy_agent_runtime] above config (or include the client/agent setup) so readers can still see the config dictionary?

Comment on lines +29 to +49
# [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]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (blocking): Because agent_name, mcp_server_name, and filter_str are function parameters outside # [START agentregistry_adk_discover_agents_and_toolsets], readers on reference/libraries.md won't see the example filter ('skills.tags:"translation"'), the placeholder formats ("agents/AGENT_ID", "mcpServers/SERVER_ID"), or the AgentRegistry import. Could we include the imports and either the function signature or local placeholder assignments inside the region tag? Also, if possible, keeping the brief comment explaining short ("agents/AGENT_ID") vs. full resource name format is helpful for readers on reference/libraries.md.

Comment on lines +41 to +76
# [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]:
self.creds.before_request(
Request(),
request.method,
str(request.url),
request.headers,
)
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]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking): Similar to the other samples, # [START agentregistry_adk_clone_remote_agent] repeats the GoogleAuth + httpx_client setup, while registry, agent_name, model, and the imports are outside the region tag. It would be more consistent if the region tag either includes the full function (with agent_name / model defaults visible) or stays focused on the get_remote_a2a_agent + .clone() block like resolve-endpoints-and-build-orchestrators.md.

Comment on lines +52 to +60
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,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 from the docs side — get_remote_a2a_agent() requires httpx.AsyncClient and keeping it open for RemoteA2aAgent matches our documented behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: agentregistry Issues related to the Agent Registry API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants