Skip to content

Commit 4752f3f

Browse files
seanzhougooglecopybara-github
authored andcommitted
chore: Add a sample agent for files_retrieval tool
this sample can be used to test the latest gemini embedding model Co-authored-by: Xiang (Sean) Zhou <seanzhougoogle@google.com> PiperOrigin-RevId: 884574396
1 parent 50d6f35 commit 4752f3f

File tree

5 files changed

+196
-0
lines changed

5 files changed

+196
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Files Retrieval Agent
2+
3+
A sample agent that demonstrates using `FilesRetrieval` with the
4+
`gemini-embedding-2-preview` embedding model for retrieval-augmented
5+
generation (RAG) over local files.
6+
7+
## What it does
8+
9+
This agent indexes local text files from the `data/` directory using
10+
`FilesRetrieval` (backed by LlamaIndex's `VectorStoreIndex` and Google's
11+
`gemini-embedding-2-preview` embedding model), then answers user questions
12+
by retrieving relevant documents before generating a response.
13+
14+
## Prerequisites
15+
16+
- Python 3.11+
17+
- `google-genai >= 1.64.0` (required for `gemini-embedding-2-preview`
18+
support via the Vertex AI `embedContent` endpoint)
19+
- `llama-index-embeddings-google-genai >= 0.3.0`
20+
21+
Install dependencies:
22+
23+
```bash
24+
uv sync --all-extras
25+
```
26+
27+
## Authentication
28+
29+
Configure one of the following:
30+
31+
**Google AI API:**
32+
33+
```bash
34+
export GOOGLE_API_KEY="your-api-key"
35+
```
36+
37+
**Vertex AI:**
38+
39+
```bash
40+
export GOOGLE_GENAI_USE_VERTEXAI=1
41+
export GOOGLE_CLOUD_PROJECT="your-project-id"
42+
export GOOGLE_CLOUD_LOCATION="us-central1"
43+
```
44+
45+
Note: `gemini-embedding-2-preview` is currently only available in
46+
`us-central1`.
47+
48+
## Usage
49+
50+
```bash
51+
cd contributing/samples
52+
53+
# Interactive CLI
54+
adk run files_retrieval_agent
55+
56+
# Web UI
57+
adk web .
58+
```
59+
60+
## Example queries
61+
62+
- "What agent types does ADK support?"
63+
- "How does FilesRetrieval work?"
64+
- "What tools are available in ADK?"
65+
66+
## File structure
67+
68+
```
69+
files_retrieval_agent/
70+
├── __init__.py
71+
├── agent.py # Agent definition with FilesRetrieval tool
72+
├── data/
73+
│ ├── adk_overview.txt # ADK architecture overview
74+
│ └── tools_guide.txt # ADK tools documentation
75+
└── README.md
76+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2026 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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2026 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+
"""Sample agent using FilesRetrieval with gemini-embedding-2-preview.
16+
17+
This agent indexes local text files and answers questions about them
18+
using retrieval-augmented generation.
19+
20+
Usage:
21+
cd contributing/samples
22+
adk run files_retrieval_agent
23+
# or
24+
adk web .
25+
"""
26+
27+
import os
28+
29+
from google.adk.agents.llm_agent import Agent
30+
from google.adk.tools.retrieval.files_retrieval import FilesRetrieval
31+
32+
DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
33+
34+
files_retrieval = FilesRetrieval(
35+
name="search_documents",
36+
description=(
37+
"Search through local ADK documentation files to find relevant"
38+
" information. Use this tool when the user asks questions about ADK"
39+
" features, architecture, or tools."
40+
),
41+
input_dir=DATA_DIR,
42+
)
43+
44+
root_agent = Agent(
45+
model="gemini-2.0-flash",
46+
name="files_retrieval_agent",
47+
instruction=(
48+
"You are a helpful assistant that answers questions about the Agent"
49+
" Development Kit (ADK). Use the search_documents tool to find"
50+
" relevant information before answering. Always base your answers"
51+
" on the retrieved documents."
52+
),
53+
tools=[files_retrieval],
54+
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Agent Development Kit (ADK) Overview
2+
3+
ADK is a Python framework for building AI agents powered by large language models.
4+
It provides a structured way to create agents that can reason, use tools, and
5+
collaborate with other agents.
6+
7+
Key Features:
8+
- Multi-agent orchestration with sequential, parallel, and loop patterns
9+
- Built-in tool support including function tools, retrieval, and code execution
10+
- Session management for maintaining conversation state
11+
- Memory services for long-term recall across sessions
12+
- Support for multiple LLM backends including Gemini, Anthropic, and Ollama
13+
14+
Architecture:
15+
The core abstractions are Agent, Runner, Tool, Session, and Memory.
16+
The Runner orchestrates the reason-act loop, processing user turns and
17+
streaming events back to the caller.
18+
19+
Agent Types:
20+
- LlmAgent: Main agent with LLM integration
21+
- SequentialAgent: Runs sub-agents in sequence
22+
- ParallelAgent: Runs sub-agents in parallel
23+
- LoopAgent: Runs sub-agents in a loop
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
ADK Tools Guide
2+
3+
Tools are capabilities that agents can invoke during their reasoning process.
4+
ADK supports several types of tools:
5+
6+
1. Function Tools
7+
Define Python functions and pass them directly to an agent.
8+
The function signature and docstring become the tool schema.
9+
10+
2. Retrieval Tools
11+
- FilesRetrieval: Index and search local files using embeddings.
12+
Uses gemini-embedding-2-preview by default.
13+
- VertexAiRagRetrieval: Search Vertex AI RAG corpora.
14+
15+
3. Code Execution
16+
Agents can generate and execute code in a sandboxed environment.
17+
18+
4. Third-Party Tool Integration
19+
- LangchainTool: Wraps LangChain tools for use in ADK.
20+
- CrewaiTool: Wraps CrewAI tools for use in ADK.
21+
22+
5. MCP Tools
23+
Connect to Model Context Protocol servers for external tool access.
24+
25+
Tool Configuration:
26+
Tools can be configured with authentication, rate limiting, and custom
27+
schemas. The ToolContext provides access to session state, artifacts,
28+
and other contextual information during tool execution.

0 commit comments

Comments
 (0)