mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
docs: Update agent builder assistant to query knowledge base through HTTP instead of a2a
Co-authored-by: Xuan Yang <xygoogle@google.com> PiperOrigin-RevId: 825848638
This commit is contained in:
committed by
Copybara-Service
parent
fc15c9a0c3
commit
3814d8b80f
@@ -26,7 +26,6 @@ from google.adk.tools import AgentTool
|
||||
from google.adk.tools import FunctionTool
|
||||
from google.genai import types
|
||||
|
||||
from .sub_agents.adk_knowledge_agent import create_adk_knowledge_agent
|
||||
from .sub_agents.google_search_agent import create_google_search_agent
|
||||
from .sub_agents.url_context_agent import create_url_context_agent
|
||||
from .tools.cleanup_unused_files import cleanup_unused_files
|
||||
@@ -34,6 +33,7 @@ from .tools.delete_files import delete_files
|
||||
from .tools.explore_project import explore_project
|
||||
from .tools.read_config_files import read_config_files
|
||||
from .tools.read_files import read_files
|
||||
from .tools.search_adk_knowledge import search_adk_knowledge
|
||||
from .tools.search_adk_source import search_adk_source
|
||||
from .tools.write_config_files import write_config_files
|
||||
from .tools.write_files import write_files
|
||||
@@ -69,11 +69,9 @@ class AgentBuilderAssistant:
|
||||
# - Maintains compatibility with existing ADK tool ecosystem
|
||||
|
||||
# Built-in ADK tools wrapped as sub-agents
|
||||
adk_knowledge_agent = create_adk_knowledge_agent()
|
||||
google_search_agent = create_google_search_agent()
|
||||
url_context_agent = create_url_context_agent()
|
||||
agent_tools = [
|
||||
AgentTool(adk_knowledge_agent),
|
||||
AgentTool(google_search_agent),
|
||||
AgentTool(url_context_agent),
|
||||
]
|
||||
@@ -99,6 +97,8 @@ class AgentBuilderAssistant:
|
||||
FunctionTool(cleanup_unused_files),
|
||||
# ADK source code search (regex-based)
|
||||
FunctionTool(search_adk_source), # Search ADK source with regex
|
||||
# ADK knowledge search
|
||||
FunctionTool(search_adk_knowledge), # Search ADK knowledge base
|
||||
]
|
||||
|
||||
# Combine all tools
|
||||
|
||||
@@ -272,9 +272,9 @@ tools:
|
||||
|
||||
### ADK Knowledge and Research Tools
|
||||
|
||||
**Default research tool**: Use `adk_knowledge_agent` first for ADK concepts, APIs,
|
||||
**Default research tool**: Use `search_adk_knowledge` first for ADK concepts, APIs,
|
||||
examples, and troubleshooting. Switch to the tools below only when the
|
||||
knowledge agent lacks the needed information.
|
||||
knowledge base lacks the needed information.
|
||||
|
||||
- `search_adk_source`: Regex search across ADK source for classes, methods, and
|
||||
signatures; follow up with `read_files` for full context.
|
||||
@@ -287,7 +287,7 @@ need agent-type clarification, want best practices, hit errors, express
|
||||
uncertainty about architecture, or you otherwise need authoritative guidance.
|
||||
|
||||
**Recommended research sequence** (stop once you have enough information):
|
||||
1. `adk_knowledge_agent`
|
||||
1. `search_adk_knowledge`
|
||||
2. `search_adk_source` → `read_files`
|
||||
3. `google_search_agent`
|
||||
4. `url_context_agent`
|
||||
|
||||
@@ -14,12 +14,10 @@
|
||||
|
||||
"""Sub-agents for Agent Builder Assistant."""
|
||||
|
||||
from .adk_knowledge_agent import create_adk_knowledge_agent
|
||||
from .google_search_agent import create_google_search_agent
|
||||
from .url_context_agent import create_url_context_agent
|
||||
|
||||
__all__ = [
|
||||
'create_adk_knowledge_agent',
|
||||
'create_google_search_agent',
|
||||
'create_url_context_agent',
|
||||
]
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
# 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.
|
||||
|
||||
"""Sub-agent for ADK Knowledge."""
|
||||
|
||||
from google.adk.agents.llm_agent import Agent
|
||||
from google.adk.agents.remote_a2a_agent import AGENT_CARD_WELL_KNOWN_PATH
|
||||
from google.adk.agents.remote_a2a_agent import RemoteA2aAgent
|
||||
|
||||
|
||||
def create_adk_knowledge_agent() -> Agent:
|
||||
"""Create a sub-agent that only uses google_search tool."""
|
||||
return RemoteA2aAgent(
|
||||
name="adk_knowledge_agent",
|
||||
description=(
|
||||
"Agent for performing Vertex AI Search to find ADK knowledge and"
|
||||
" documentation"
|
||||
),
|
||||
agent_card=(
|
||||
f"https://adk-agent-builder-knowledge-service-654646711756.us-central1.run.app/a2a/adk_knowledge_agent{AGENT_CARD_WELL_KNOWN_PATH}"
|
||||
),
|
||||
)
|
||||
@@ -0,0 +1,85 @@
|
||||
# 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.
|
||||
|
||||
"""ADK knowledge search tool."""
|
||||
|
||||
from typing import Any
|
||||
import uuid
|
||||
|
||||
import requests
|
||||
|
||||
KNOWLEDGE_SERVICE_APP_URL = "https://adk-agent-builder-knowledge-service-654646711756.us-central1.run.app"
|
||||
KNOWLEDGE_SERVICE_APP_NAME = "adk_knowledge_agent"
|
||||
KNOWLEDGE_SERVICE_APP_USER_NAME = "agent_builder_assistant"
|
||||
|
||||
HEADERS = {
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json",
|
||||
}
|
||||
|
||||
|
||||
def search_adk_knowledge(
|
||||
query: str,
|
||||
) -> dict[str, Any]:
|
||||
"""Searches ADK knowledge base for relevant information.
|
||||
|
||||
Args:
|
||||
query: The query to search in ADK knowledge base.
|
||||
|
||||
Returns:
|
||||
A dict with status and the response from the knowledge service.
|
||||
"""
|
||||
# Create a new session
|
||||
session_id = uuid.uuid4()
|
||||
create_session_url = f"{KNOWLEDGE_SERVICE_APP_URL}/apps/{KNOWLEDGE_SERVICE_APP_NAME}/users/{KNOWLEDGE_SERVICE_APP_USER_NAME}/sessions/{session_id}"
|
||||
|
||||
try:
|
||||
create_session_response = post_request(
|
||||
create_session_url,
|
||||
{},
|
||||
)
|
||||
except requests.exceptions.RequestException as e:
|
||||
return error_response(f"Failed to create session: {e}")
|
||||
session_id = create_session_response["id"]
|
||||
|
||||
# Search ADK knowledge base
|
||||
search_url = f"{KNOWLEDGE_SERVICE_APP_URL}/run"
|
||||
try:
|
||||
search_response = post_request(
|
||||
search_url,
|
||||
{
|
||||
"app_name": KNOWLEDGE_SERVICE_APP_NAME,
|
||||
"user_id": KNOWLEDGE_SERVICE_APP_USER_NAME,
|
||||
"session_id": session_id,
|
||||
"new_message": {"role": "user", "parts": [{"text": query}]},
|
||||
},
|
||||
)
|
||||
except requests.exceptions.RequestException as e:
|
||||
return error_response(f"Failed to search ADK knowledge base: {e}")
|
||||
return {
|
||||
"status": "success",
|
||||
"response": search_response,
|
||||
}
|
||||
|
||||
|
||||
def error_response(error_message: str) -> dict[str, Any]:
|
||||
"""Returns an error response."""
|
||||
return {"status": "error", "error_message": error_message}
|
||||
|
||||
|
||||
def post_request(url: str, payload: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Executes a POST request."""
|
||||
response = requests.post(url, headers=HEADERS, json=payload, timeout=60)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
Reference in New Issue
Block a user