From 420df25f586bd9b48e7990920b26913700cf0a39 Mon Sep 17 00:00:00 2001 From: Xuan Yang Date: Thu, 2 Oct 2025 19:19:53 -0700 Subject: [PATCH] chore: add a remote A2A knowledge agent for Agent Builder Assistant PiperOrigin-RevId: 814484204 --- .../adk_knowledge_agent/README.md | 25 +++++++ .../adk_knowledge_agent/__init__.py | 15 ++++ .../adk_knowledge_agent/agent.json | 17 +++++ .../adk_knowledge_agent/agent.py | 74 +++++++++++++++++++ .../adk_knowledge_agent/requirements.txt | 1 + 5 files changed, 132 insertions(+) create mode 100644 contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/README.md create mode 100644 contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/__init__.py create mode 100644 contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/agent.json create mode 100644 contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/agent.py create mode 100644 contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/requirements.txt diff --git a/contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/README.md b/contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/README.md new file mode 100644 index 00000000..cf0c8901 --- /dev/null +++ b/contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/README.md @@ -0,0 +1,25 @@ +# Agent Knowledge Agent + +An intelligent assistant for performing Vertex AI Search to find ADK knowledge +and documentation. + +## Deployment + +This agent is deployed to Google Could Run as an A2A agent, which is used by +the parent ADK Agent Builder Assistant. + +Here are the steps to deploy the agent: + +1. Set environment variables + +```bash +export GOOGLE_CLOUD_PROJECT=your-project-id +export GOOGLE_CLOUD_LOCATION=us-central1 # Or your preferred location +export GOOGLE_GENAI_USE_VERTEXAI=True +``` + +2. Run the deployment command + +```bash +$ adk deploy cloud_run --project=your-project-id --region=us-central1 --service_name=adk-agent-builder-knowledge-service --with_ui --a2a ./adk_knowledge_agent +``` \ No newline at end of file diff --git a/contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/__init__.py b/contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/__init__.py new file mode 100644 index 00000000..c48963cd --- /dev/null +++ b/contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2025 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 . import agent diff --git a/contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/agent.json b/contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/agent.json new file mode 100644 index 00000000..f5837407 --- /dev/null +++ b/contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/agent.json @@ -0,0 +1,17 @@ +{ + "capabilities": {}, + "defaultInputModes": ["text/plain"], + "defaultOutputModes": ["application/json"], + "description": "Agent for performing Vertex AI Search to find ADK knowledge and documentation", + "name": "adk_knowledge_agent", + "skills": [ + { + "id": "adk_knowledge_search", + "name": "ADK Knowledge Search", + "description": "Searches for ADK examples and documentation using the Vertex AI Search tool", + "tags": ["search", "documentation", "knowledge base", "Vertex AI", "ADK"] + } + ], + "url": "https://adk-agent-builder-knowledge-service-654646711756.us-central1.run.app/a2a/adk_knowledge_agent", + "version": "1.0.0" +} \ No newline at end of file diff --git a/contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/agent.py b/contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/agent.py new file mode 100644 index 00000000..90eb5e66 --- /dev/null +++ b/contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/agent.py @@ -0,0 +1,74 @@ +# Copyright 2025 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 json +from typing import Optional + +from google.adk.agents import LlmAgent +from google.adk.agents.callback_context import CallbackContext +from google.adk.models import LlmResponse +from google.adk.tools.vertex_ai_search_tool import VertexAiSearchTool +from google.genai import types + +VERTEXAI_DATASTORE_ID = "projects/adk-agent-builder-assistant/locations/global/collections/default_collection/dataStores/adk-agent-builder-sample-datastore_1758230446136" + + +def citation_retrieval_after_model_callback( + callback_context: CallbackContext, + llm_response: LlmResponse, +) -> Optional[LlmResponse]: + """Callback function to retrieve citations after model response is generated.""" + grounding_metadata = llm_response.grounding_metadata + if not grounding_metadata: + return None + + content = llm_response.content + if not llm_response.content: + return None + + parts = content.parts + if not parts: + return None + + # Add citations to the response as JSON objects. + parts.append(types.Part(text="References:\n")) + for grounding_chunk in grounding_metadata.grounding_chunks: + retrieved_context = grounding_chunk.retrieved_context + if not retrieved_context: + continue + + citation = { + "title": retrieved_context.title, + "uri": retrieved_context.uri, + "snippet": retrieved_context.text, + } + parts.append(types.Part(text=json.dumps(citation))) + + return LlmResponse(content=types.Content(parts=parts)) + + +root_agent = LlmAgent( + name="adk_knowledge_agent", + description=( + "Agent for performing Vertex AI Search to find ADK knowledge and" + " documentation" + ), + instruction="""You are a specialized search agent for an ADK knowledge base. + + You can use the VertexAiSearchTool to search for ADK examples and documentation in the document store. + """, + model="gemini-2.5-flash", + tools=[VertexAiSearchTool(data_store_id=VERTEXAI_DATASTORE_ID)], + after_model_callback=citation_retrieval_after_model_callback, +) diff --git a/contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/requirements.txt b/contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/requirements.txt new file mode 100644 index 00000000..7065c197 --- /dev/null +++ b/contributing/samples/adk_agent_builder_assistant/remote_agents/adk_knowledge_agent/requirements.txt @@ -0,0 +1 @@ +google-adk[a2a]==1.15.1 \ No newline at end of file