Skip to content

Commit 420df25

Browse files
xuanyang15copybara-github
authored andcommitted
chore: add a remote A2A knowledge agent for Agent Builder Assistant
PiperOrigin-RevId: 814484204
1 parent a9b76b9 commit 420df25

File tree

5 files changed

+132
-0
lines changed

5 files changed

+132
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Agent Knowledge Agent
2+
3+
An intelligent assistant for performing Vertex AI Search to find ADK knowledge
4+
and documentation.
5+
6+
## Deployment
7+
8+
This agent is deployed to Google Could Run as an A2A agent, which is used by
9+
the parent ADK Agent Builder Assistant.
10+
11+
Here are the steps to deploy the agent:
12+
13+
1. Set environment variables
14+
15+
```bash
16+
export GOOGLE_CLOUD_PROJECT=your-project-id
17+
export GOOGLE_CLOUD_LOCATION=us-central1 # Or your preferred location
18+
export GOOGLE_GENAI_USE_VERTEXAI=True
19+
```
20+
21+
2. Run the deployment command
22+
23+
```bash
24+
$ adk deploy cloud_run --project=your-project-id --region=us-central1 --service_name=adk-agent-builder-knowledge-service --with_ui --a2a ./adk_knowledge_agent
25+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from . import agent
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"capabilities": {},
3+
"defaultInputModes": ["text/plain"],
4+
"defaultOutputModes": ["application/json"],
5+
"description": "Agent for performing Vertex AI Search to find ADK knowledge and documentation",
6+
"name": "adk_knowledge_agent",
7+
"skills": [
8+
{
9+
"id": "adk_knowledge_search",
10+
"name": "ADK Knowledge Search",
11+
"description": "Searches for ADK examples and documentation using the Vertex AI Search tool",
12+
"tags": ["search", "documentation", "knowledge base", "Vertex AI", "ADK"]
13+
}
14+
],
15+
"url": "https://adk-agent-builder-knowledge-service-654646711756.us-central1.run.app/a2a/adk_knowledge_agent",
16+
"version": "1.0.0"
17+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import json
16+
from typing import Optional
17+
18+
from google.adk.agents import LlmAgent
19+
from google.adk.agents.callback_context import CallbackContext
20+
from google.adk.models import LlmResponse
21+
from google.adk.tools.vertex_ai_search_tool import VertexAiSearchTool
22+
from google.genai import types
23+
24+
VERTEXAI_DATASTORE_ID = "projects/adk-agent-builder-assistant/locations/global/collections/default_collection/dataStores/adk-agent-builder-sample-datastore_1758230446136"
25+
26+
27+
def citation_retrieval_after_model_callback(
28+
callback_context: CallbackContext,
29+
llm_response: LlmResponse,
30+
) -> Optional[LlmResponse]:
31+
"""Callback function to retrieve citations after model response is generated."""
32+
grounding_metadata = llm_response.grounding_metadata
33+
if not grounding_metadata:
34+
return None
35+
36+
content = llm_response.content
37+
if not llm_response.content:
38+
return None
39+
40+
parts = content.parts
41+
if not parts:
42+
return None
43+
44+
# Add citations to the response as JSON objects.
45+
parts.append(types.Part(text="References:\n"))
46+
for grounding_chunk in grounding_metadata.grounding_chunks:
47+
retrieved_context = grounding_chunk.retrieved_context
48+
if not retrieved_context:
49+
continue
50+
51+
citation = {
52+
"title": retrieved_context.title,
53+
"uri": retrieved_context.uri,
54+
"snippet": retrieved_context.text,
55+
}
56+
parts.append(types.Part(text=json.dumps(citation)))
57+
58+
return LlmResponse(content=types.Content(parts=parts))
59+
60+
61+
root_agent = LlmAgent(
62+
name="adk_knowledge_agent",
63+
description=(
64+
"Agent for performing Vertex AI Search to find ADK knowledge and"
65+
" documentation"
66+
),
67+
instruction="""You are a specialized search agent for an ADK knowledge base.
68+
69+
You can use the VertexAiSearchTool to search for ADK examples and documentation in the document store.
70+
""",
71+
model="gemini-2.5-flash",
72+
tools=[VertexAiSearchTool(data_store_id=VERTEXAI_DATASTORE_ID)],
73+
after_model_callback=citation_retrieval_after_model_callback,
74+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google-adk[a2a]==1.15.1

0 commit comments

Comments
 (0)