chore: add a remote A2A knowledge agent for Agent Builder Assistant

PiperOrigin-RevId: 814484204
This commit is contained in:
Xuan Yang
2025-10-02 19:20:36 -07:00
committed by Copybara-Service
parent a9b76b9061
commit 420df25f58
5 changed files with 132 additions and 0 deletions
@@ -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
```
@@ -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
@@ -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"
}
@@ -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,
)