Skip to content

Commit 06f8113

Browse files
committed
Checkout ADK sample from adk-sample-9-29
Get adk sample working working with adk web
1 parent 05bed52 commit 06f8113

File tree

17 files changed

+3011
-0
lines changed

17 files changed

+3011
-0
lines changed

adk-sql-agent/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Dockerfile

adk-sql-agent/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.db

adk-sql-agent/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

adk-sql-agent/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# NOTE: this must be run from the repo root as build context
2+
3+
# Adapted from https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers
4+
# Install uv
5+
FROM python:3.13-slim
6+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
7+
8+
RUN apt-get update && apt-get install -y git
9+
10+
# Change the working directory to the `app` directory
11+
WORKDIR /app
12+
13+
# Copy the project into the image
14+
COPY . ./
15+
16+
WORKDIR /app/adk-sql-agent
17+
18+
# Sync the project
19+
RUN --mount=type=cache,target=/root/.cache/uv uv sync --locked
20+
21+
ENTRYPOINT [ "uv", "run", "--locked", "--env-file=main.env", "main.py" ]

adk-sql-agent/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# OpenTelemetry ADK instrumentation example
2+
3+
<!-- TODO: link to devsite doc once it is published -->
4+
5+
This demo shows does remote uploading and with `.ref` attributes in the telemetry, following OTel semconv 1.37 for GenAI: https://github.com/open-telemetry/semantic-conventions/blob/v1.37.0/docs/gen-ai/gen-ai-events.md
6+
7+
## Configure upload
8+
This demo uses the [fsspec](https://filesystem-spec.readthedocs.io/) library to do the upload
9+
in a vendor agnostic way, which is configured in an environment variable
10+
`OTEL_PYTHON_GENAI_UPLOADER_PATH`. For example, to upload to GCS bucket `my-bucket` with
11+
subdirectory `v1/`:
12+
13+
```console
14+
export OTEL_PYTHON_GENAI_UPLOADER_PATH="gs://my-bucket/v1"
15+
```
16+
17+
This will work with any installed fsspec implementations and also allows using any fsspec
18+
configuration like URL Chaining:
19+
- [Built in implementations](https://filesystem-spec.readthedocs.io/en/latest/api.html#built-in-implementations)
20+
- [Known third party impls](https://filesystem-spec.readthedocs.io/en/latest/api.html#external-implementations)
21+
- [URL Chaining](https://filesystem-spec.readthedocs.io/en/latest/features.html#url-chaining)
22+
23+
## Run the demo
24+
25+
To run the app, set some environment variables (alternatively can be put in `main.env`):
26+
27+
```console
28+
# Port if not default
29+
export PORT=8000
30+
# Project for ADC
31+
export GOOGLE_CLOUD_PROJECT=my-project
32+
33+
# Configure the upload path
34+
export OTEL_PYTHON_GENAI_UPLOADER_PATH="gs://${GOOGLE_CLOUD_PROJECT}/v1"
35+
36+
uv run --env-file main.env main.py
37+
```
38+
39+
## Dockerfile
40+
41+
Build
42+
43+
```console
44+
# from this directory, run with repo root build context
45+
docker build -f ./Dockerfile -t adk-sql-agent-write-aside ..
46+
```
47+
48+
Run:
49+
```console
50+
docker run --rm \
51+
-p 8000:8000 \
52+
-e PORT=8000 \
53+
-e GOOGLE_APPLICATION_CREDENTIALS \
54+
-e GOOGLE_CLOUD_PROJECT \
55+
-e OTEL_PYTHON_GENAI_UPLOADER_PATH="gs://otel-starter-project-genai-refs/v1" \
56+
-v "$GOOGLE_APPLICATION_CREDENTIALS:$GOOGLE_APPLICATION_CREDENTIALS" \
57+
adk-sql-agent-write-aside:latest
58+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
GOOGLE_GENAI_USE_VERTEXAI=1
2+
GOOGLE_CLOUD_PROJECT=otel-starter-project
3+
GOOGLE_CLOUD_LOCATION=us-central1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import agent
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from textwrap import dedent
2+
3+
from google.adk.agents.llm_agent import Agent
4+
5+
root_agent = Agent(
6+
model="gemini-2.5-flash",
7+
name="root_agent",
8+
description="An agent that can describe images",
9+
instruction=dedent("""\
10+
You are an agent that can describe images. You don't have any tools at your disposal.
11+
Some guidelines for you:
12+
13+
- Don't answer any questions that are opinion based or involve emotions.
14+
- Keep it brief and succinct
15+
- But also be descriptive
16+
- Answer in a professional tone
17+
"""),
18+
)

adk-sql-agent/main.env

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
GOOGLE_GENAI_USE_VERTEXAI=TRUE
2+
GOOGLE_CLOUD_LOCATION=us-central1
3+
GOOGLE_CLOUD_PROJECT=otel-starter-project
4+
5+
OTEL_INSTRUMENTATION_GENAI_UPLOAD_FORMAT='jsonl'
6+
OTEL_INSTRUMENTATION_GENAI_COMPLETION_HOOK=upload
7+
OTEL_INSTRUMENTATION_GENAI_UPLOAD_BASE_PATH="gs://otel-starter-project-genai-refs/v3"
8+
OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
9+
OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental

adk-sql-agent/pyproject.toml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
# https://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+
[project]
16+
name = "adk-sql-agent"
17+
version = "0.1.0"
18+
description = "An ADK agent that can run queries on an ephemeral SQLite database"
19+
readme = "README.md"
20+
requires-python = ">=3.13"
21+
dependencies = [
22+
"fsspec>=2025.5.1",
23+
"gcsfs",
24+
"google-adk~=1.14",
25+
"opentelemetry-exporter-gcp-logging>=1.9.0a0",
26+
"opentelemetry-exporter-gcp-monitoring>=1.9.0a0",
27+
"opentelemetry-exporter-otlp-proto-grpc>=1.33.1",
28+
"opentelemetry-instrumentation-aiohttp-client>=0.54b1",
29+
"opentelemetry-instrumentation-google-genai>=0.2b0",
30+
"opentelemetry-instrumentation-httpx>=0.54b1",
31+
"opentelemetry-instrumentation-requests>=0.54b1",
32+
"opentelemetry-instrumentation-sqlite3>=0.54b1",
33+
"opentelemetry-instrumentation-vertexai>=2.0b0",
34+
"opentelemetry-util-genai",
35+
"rich>=14.0.0",
36+
]
37+
38+
[dependency-groups]
39+
dev = ["debugpy>=1.8.17", "ipython>=9.3.0", "pillow>=11.2.1"]
40+
41+
[tool.uv.sources]
42+
fsspec = { git = "https://github.com/fsspec/filesystem_spec.git" }
43+
gcsfs = { git = "https://github.com/aabmass/gcsfs.git", branch = "remove-conflicts" }
44+
opentelemetry-exporter-gcp-logging = { git = "https://github.com/GoogleCloudPlatform/opentelemetry-operations-python.git", branch = "main", subdirectory = "opentelemetry-exporter-gcp-logging" }
45+
opentelemetry-instrumentation-google-genai = { path = "../instrumentation-genai/opentelemetry-instrumentation-google-genai", editable = true }
46+
opentelemetry-util-genai = { path = "../util/opentelemetry-util-genai", editable = true }

0 commit comments

Comments
 (0)