Skip to content

Commit 06a5c2d

Browse files
committed
Readme and Dockerfile for adk agent
1 parent 8024e9c commit 06a5c2d

File tree

3 files changed

+63
-41
lines changed

3 files changed

+63
-41
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/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: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,57 @@
22

33
<!-- TODO: link to devsite doc once it is published -->
44

5-
This sample is an ADK agent instrumented with OpenTelemetry to send traces and logs with GenAI
6-
prompts and responses, and metrics to Google Cloud Observability.
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
76

8-
The Agent is a SQL expert that has full access to an ephemeral SQLite database. The database is
9-
initially empty.
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/`:
1012

11-
## APIs and Permissions
12-
13-
Enable the relevant Cloud Observability APIs if they aren't already enabled.
14-
```sh
15-
gcloud services enable telemetry.googleapis.com logging.googleapis.com monitoring.googleapis.com cloudtrace.googleapis.com
13+
```console
14+
export OTEL_PYTHON_GENAI_UPLOADER_PATH="gs://my-bucket/v1"
1615
```
1716

18-
This sample writes to Cloud Logging, Cloud Monitoring, and Cloud Trace. Grant yourself the
19-
following roles to run the example:
20-
- `roles/logging.logWriter` – see https://cloud.google.com/logging/docs/access-control#permissions_and_roles
21-
- `roles/monitoring.metricWriter` – see https://cloud.google.com/monitoring/access-control#predefined_roles
22-
- `roles/telemetry.writer` – see https://cloud.google.com/trace/docs/iam#telemetry-roles
23-
24-
## Running the example
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)
2522

26-
The sample can easily be run in Cloud Shell. You can also use
27-
[Application Default Credentials][ADC] locally. Clone and set environment variables:
28-
```sh
29-
git clone https://github.com/GoogleCloudPlatform/opentelemetry-operations-python.git
30-
cd opentelemetry-operations-python/samples/adk-sql-agent
23+
## Run the demo
3124

32-
# Capture GenAI prompts and responses
33-
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true
34-
# Capture application logs automatically
35-
export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
36-
```
25+
To run the app, set some environment variables (alternatively can be put in `main.env`):
3726

38-
Create a virtual environment and run the sample:
39-
```sh
40-
python -m venv venv/
41-
source venv/bin/activate
42-
pip install -r requirements.txt
43-
python main.py
44-
```
27+
```console
28+
# Port if not default
29+
export PORT=8000
30+
# Project for ADC
31+
export GOOGLE_CLOUD_PROJECT=my-project
4532

46-
Alternatively if you have [`uv`](https://docs.astral.sh/uv/) installed:
33+
# Configure the upload path
34+
export OTEL_PYTHON_GENAI_UPLOADER_PATH="gs://${GOOGLE_CLOUD_PROJECT}/v1"
4735

48-
```sh
49-
uv run main.py
36+
uv run --env-file main.env main.py
5037
```
5138

52-
## Viewing the results
39+
## Dockerfile
5340

54-
To view the generated traces with [Generative AI
55-
events](https://cloud.google.com/trace/docs/finding-traces#view_generative_ai_events) in the
56-
GCP console, use the [Trace Explorer](https://cloud.google.com/trace/docs/finding-traces). Filter for spans named `invoke agent`.
41+
Build
5742

58-
[ADC]: https://cloud.google.com/docs/authentication/application-default-credentials
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+
```

0 commit comments

Comments
 (0)