Repository navigation
Conversation
|
Here is the summary of changes. You are about to add 5 region tags.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
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.
| 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, | ||
| ) |
There was a problem hiding this comment.
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,
)There was a problem hiding this comment.
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.
There was a problem hiding this comment.
+1 from the docs side — get_remote_a2a_agent() requires httpx.AsyncClient and keeping it open for RemoteA2aAgent matches our documented behavior.
| 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, | ||
| ) |
There was a problem hiding this comment.
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.
| 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, | |
| ) |
There was a problem hiding this comment.
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.
evelyn-goo
left a comment
There was a problem hiding this comment.
Thanks so much for setting up the scaffolding and migrating these samples, Beth!
| @@ -0,0 +1,43 @@ | |||
| Agent Registry Python Samples | |||
There was a problem hiding this comment.
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)?
| # [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] |
There was a problem hiding this comment.
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)?
| 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] |
There was a problem hiding this comment.
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?
| # [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] |
There was a problem hiding this comment.
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.
| # [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] |
There was a problem hiding this comment.
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.
| 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, | ||
| ) |
There was a problem hiding this comment.
+1 from the docs side — get_remote_a2a_agent() requires httpx.AsyncClient and keeping it open for RemoteA2aAgent matches our documented behavior.
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.txtagentregistry/adk/noxfile_config.py&conftest.pyagentregistry/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-310throughpython-docs-samples-tests-314, specificallypython-docs-samples-tests-314), please:agentregistry.googleapis.com(and verifyaiplatform.googleapis.comis enabled).AGENTREGISTRY_TEST_AGENT_IDAGENTREGISTRY_TEST_MCP_SERVER_IDAGENTREGISTRY_TEST_STAGING_BUCKETfordeploy_agent_runtime_test.py(Tests skip cleanly when these fixture environment variables are not yet set.)
Checklist
Testing
agentregistry.googleapis.comenablement and fixture setup in the shared test project.)Compliance & Style
Post-Approval Actions