Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,70 @@ updates:
patterns:
- "*"

- package-ecosystem: "uv"
directory: "/python/agents/RAG"
schedule:
interval: "weekly"
day: "monday"
time: "02:00"
commit-message:
prefix: "chore"
include: "scope"
labels:
- "dependencies"
groups:
all-dependencies:
patterns:
- "*"

- package-ecosystem: "uv"
directory: "/python/agents/customer-service"
schedule:
interval: "weekly"
day: "monday"
time: "02:00"
commit-message:
prefix: "chore"
include: "scope"
labels:
- "dependencies"
groups:
all-dependencies:
patterns:
- "*"

- package-ecosystem: "uv"
directory: "/python/agents/personalized-shopping"
schedule:
interval: "weekly"
day: "monday"
time: "02:00"
commit-message:
prefix: "chore"
include: "scope"
labels:
- "dependencies"
groups:
all-dependencies:
patterns:
- "*"

- package-ecosystem: "uv"
directory: "/python/agents/travel-concierge"
schedule:
interval: "weekly"
day: "monday"
time: "02:00"
commit-message:
prefix: "chore"
include: "scope"
labels:
- "dependencies"
groups:
all-dependencies:
patterns:
- "*"

# Keep GitHub Actions up to date
- package-ecosystem: "github-actions"
directory: "/"
Expand Down
84 changes: 49 additions & 35 deletions python/agents/RAG/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ This diagram outlines the agent's workflow, designed to provide informed and con
### Prerequisites

* **Google Cloud Account:** You need a Google Cloud account.
* **Python 3.9+:** Ensure you have Python 3.9 or a later version installed.
* **Poetry:** Install Poetry by following the instructions on the official Poetry website: [https://python-poetry.org/docs/](https://python-poetry.org/docs/)
* **Python 3.10+:** Ensure you have Python 3.10 or a later version installed.
* **uv:** For dependency management and packaging. Please follow the instructions on the official [uv website](https://docs.astral.sh/uv/) for installation.

```bash
curl -LsSf https://astral.sh/uv/install.sh | sh
```

* **Git:** Ensure you have git installed.

### Project Setup with Poetry
### Project Setup

1. **Clone the Repository:**

Expand All @@ -49,38 +54,20 @@ This diagram outlines the agent's workflow, designed to provide informed and con
cd adk-samples/python/agents/RAG
```

2. **Install Dependencies with Poetry:**

**Note for Linux users:** If you get an error related to `keyring` during the installation, you can disable it by running the following command:
```bash
poetry config keyring.enabled false
```
This is a one-time setup.
2. **Install Dependencies:**

```bash
poetry install
uv sync
```

This command reads the `pyproject.toml` file and installs all the necessary dependencies into a virtual environment managed by Poetry.
This command reads the `pyproject.toml` file and installs all the necessary dependencies into a virtual environment.

3. **Activate the Poetry Shell:**

```bash
poetry env activate
```

This activates the virtual environment, allowing you to run commands within the project's environment.
Make sure the environment is active. If not, you can also activate it through

```bash
source .venv/bin/activate
```
4. **Set up Environment Variables:**
3. **Set up Environment Variables:**
Rename the file ".env.example" to ".env"
Follow the steps in the file to set up the environment variables.

5. **Setup Corpus:**
If you have an existing corpus in Vertex AI RAG Engine, please set corpus information in your .env file. For example: RAG_CORPUS='projects/123/locations/us-central1/ragCorpora/456'.
4. **Setup Corpus:**
If you have an existing corpus in Vertex AI RAG Engine, please set corpus information in your .env file. For example: RAG_CORPUS='projects/123/locations/us-central1/ragCorpora/456'.

If you don't have a corpus setup yet, please follow "How to upload my file to my RAG corpus" section. The `prepare_corpus_and_data.py` script will automatically create a corpus (if needed) and update the `RAG_CORPUS` variable in your `.env` file with the resource name of the created or retrieved corpus.

Expand All @@ -104,7 +91,7 @@ The `rag/shared_libraries/prepare_corpus_and_data.py` script helps you set up a
* **To use the default behavior (upload Alphabet's 10K PDF):**
Simply run the script:
```bash
python rag/shared_libraries/prepare_corpus_and_data.py
uv run python rag/shared_libraries/prepare_corpus_and_data.py
```
This will create a corpus named `Alphabet_10K_2024_corpus` (if it doesn't exist) and upload the PDF `goog-10-k-2024.pdf` downloaded from the URL specified in the script.

Expand All @@ -122,7 +109,7 @@ The `rag/shared_libraries/prepare_corpus_and_data.py` script helps you set up a
```
c. Run the script:
```bash
python rag/shared_libraries/prepare_corpus_and_data.py
uv run python rag/shared_libraries/prepare_corpus_and_data.py
```

* **To upload a local PDF file:**
Expand Down Expand Up @@ -155,7 +142,7 @@ The `rag/shared_libraries/prepare_corpus_and_data.py` script helps you set up a
```
d. Run the script:
```bash
python rag/shared_libraries/prepare_corpus_and_data.py
uv run python rag/shared_libraries/prepare_corpus_and_data.py
```

More details about managing data in Vertex RAG Engine can be found in the
Expand Down Expand Up @@ -196,8 +183,9 @@ Agent: According to Alphabet's 2024 10-K report, the key business segments are:
The evaluation can be run from the `RAG` directory using
the `pytest` module:

```
poetry run pytest eval
```bash
uv sync --dev
uv run pytest eval
```

### Evaluation Process
Expand Down Expand Up @@ -229,8 +217,8 @@ This evaluation helps ensure the agent correctly leverages the RAG capabilities
The Agent can be deployed to Vertex AI Agent Engine using the following
commands:

```
python deployment/deploy.py
```bash
uv run python deployment/deploy.py
```

After deploying the agent, you'll be able to read the following INFO log message:
Expand Down Expand Up @@ -273,7 +261,7 @@ After deploying the agent, follow these steps to test it:
3. **Test the Remote Agent:**
- Run the test script:
```bash
python deployment/run.py
uv run python deployment/run.py
```
This script will:
- Connect to your deployed agent
Expand All @@ -282,6 +270,32 @@ After deploying the agent, follow these steps to test it:

The test script includes example queries about Alphabet's 10-K report. You can modify the queries in `deployment/run.py` to test different aspects of your deployed agent.

### Alternative: Using Agent Starter Pack

You can also use the [Agent Starter Pack](https://goo.gle/agent-starter-pack) to create a production-ready version of this agent with additional deployment options:

```bash
# Create and activate a virtual environment
python -m venv .venv && source .venv/bin/activate # On Windows: .venv\Scripts\activate

# Install the starter pack and create your project
pip install --upgrade agent-starter-pack
agent-starter-pack create my-rag-agent -a adk@rag
```

<details>
<summary>⚡️ Alternative: Using uv</summary>

If you have [`uv`](https://github.com/astral-sh/uv) installed, you can create and set up your project with a single command:
```bash
uvx agent-starter-pack create my-rag-agent -a adk@rag
```
This command handles creating the project without needing to pre-install the package into a virtual environment.

</details>

The starter pack will prompt you to select deployment options and provides additional production-ready features including automated CI/CD deployment scripts.

## Customization

### Customize Agent
Expand Down
113 changes: 89 additions & 24 deletions python/agents/RAG/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,96 @@ authors = [
{ name = "Hangfei Lin", email = "[email protected]" },
{ name = "Chouaieb Nemri", email = "[email protected]" },
]

license = "Apache License 2.0"
license = "Apache-2.0"
readme = "README.md"
dependencies = [
"google-cloud-aiplatform[adk,agent-engines]>=1.108.0",
"google-adk>=1.10.0",
"pydantic-settings>=2.8.1",
"tabulate>=0.9.0",
"google-auth>=2.36.0",
"requests>=2.32.3",
"llama-index>=0.12",
]

requires-python = ">=3.10,<3.13"

[dependency-groups]
dev = [
"pytest>=8.3.5",
"pytest-mock>=3.14.0",
"scikit-learn>=1.6.1",
"pytest-cov>=6.0.0",
"pytest-asyncio>=0.26.0",
"agent-starter-pack>=0.14.1",
]

[tool.poetry.dependencies]
python = "^3.11"
pydantic-settings = "^2.8.1"
tabulate = "^0.9.0"
google-auth = "^2.36.0"
requests = "^2.32.3"
google-adk = "^1.10.0"
google-cloud-aiplatform = { extras = [
"adk",
"agent-engines",
], version = "^1.108.0" }
llama-index = "^0.12"

[tool.poetry.group.dev.dependencies]
pytest = "^8.3.5"
pytest-mock = "^3.14.0"
scikit-learn = "^1.6.1"
pytest-cov = "^6.0.0"
pytest-asyncio = "^0.26.0"
black = "^25.1.0"
[project.optional-dependencies]
lint = [
"ruff>=0.4.6",
"mypy>=1.15.0",
"codespell>=2.2.0",
"types-pyyaml>=6.0.12.20240917",
"types-requests>=2.32.0.20240914",
]

[tool.ruff]
line-length = 88
target-version = "py310"

[tool.ruff.lint]
select = [
"E", # pycodestyle
"F", # pyflakes
"W", # pycodestyle warnings
"I", # isort
"C", # flake8-comprehensions
"B", # flake8-bugbear
"UP", # pyupgrade
"RUF", # ruff specific rules
]
ignore = ["E501", "C901"] # ignore line too long, too complex

[tool.ruff.lint.isort]
known-first-party = ["rag"]

[tool.mypy]
disallow_untyped_calls = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
no_implicit_optional = true
check_untyped_defs = true
disallow_subclassing_any = true
warn_incomplete_stub = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_unreachable = true
follow_imports = "silent"
ignore_missing_imports = true
explicit_package_bases = true
disable_error_code = ["misc", "no-untyped-call", "no-any-return"]

exclude = [".venv"]

[tool.codespell]
ignore-words-list = "rouge"
skip = "./locust_env/*,uv.lock,.venv,./frontend,**/*.ipynb"

[tool.pytest.ini_options]
pythonpath = "."
asyncio_default_fixture_loop_scope = "function"

[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"
requires = ["uv_build>=0.8.14,<0.9.0"]
build-backend = "uv_build"

[tool.uv.build-backend]
module-root = ""

# This configuration file is used by goo.gle/agent-starter-pack to power remote templating.
# It defines the template's properties and settings.
[tool.agent-starter-pack]
example_question = "What are the key business segments mentioned in Alphabet's 2024 10-K report?"

[tool.agent-starter-pack.settings]
agent_directory = "rag"
9 changes: 9 additions & 0 deletions python/agents/RAG/rag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

import google.auth

_, project_id = google.auth.default()
os.environ.setdefault("GOOGLE_CLOUD_PROJECT", project_id)
os.environ.setdefault("GOOGLE_CLOUD_LOCATION", "global")
os.environ.setdefault("GOOGLE_GENAI_USE_VERTEXAI", "True")

from . import agent
Loading