Skip to content
Merged
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
12 changes: 4 additions & 8 deletions .github/workflows/release_rc_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,26 @@ jobs:
with:
enable-cache: true
python-version: "3.12"
version: "0.6.6"

- name: Create release branch & bump version
id: rc
env:
TARGET_VERSION: ${{ inputs.target_version }}
run: |
set -e
set -euo pipefail
TARGET="$TARGET_VERSION"
[[ "$TARGET" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "Error: target_version must be X.Y.Z"; exit 1; }
EXISTING=$(git tag -l "v${TARGET}-rc.*" 2>/dev/null | sed -n 's/.*-rc\.\([0-9]*\)$/\1/p' | sort -n | tail -1)
RC_NUM=$((${EXISTING:-0} + 1))
NEW="${TARGET}-rc.${RC_NUM}"
BRANCH="release/${NEW}"
echo "new=${NEW}" >> $GITHUB_OUTPUT
CUR=$(grep '^version = ' packages/genkit/pyproject.toml | cut -d'"' -f2)
git config user.email "genkit-releaser@google.com" && git config user.name "genkit-releaser"
git checkout -b "${BRANCH}"
for f in packages/genkit/pyproject.toml packages/*/pyproject.toml; do
[ -f "$f" ] && grep -q "version = \"$CUR\"" "$f" && sed -i "s/version = \"$CUR\"/version = \"$NEW\"/" "$f"
done
uv lock
./bin/bump_version "$NEW"
python3 ./scripts/check_consistency.py
git add .
git diff --staged --quiet && { echo "::error::No version changes - $CUR may not match pyproject.toml files"; exit 1; }
git diff --staged --quiet && { echo "::error::No version changes after bump_version $NEW"; exit 1; }
git commit -m "chore: bump version to $NEW"
git push origin HEAD:"refs/heads/${BRANCH}"

Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,15 @@ print(out2.text)

### 4. Agent Loops & Persistent Sessions

Agents are experimental, and `FirestoreSessionStore` needs the `firestore` extra:

```bash
uv add 'genkit-google-cloud[firestore]'
```

```python
from genkit import Genkit
from genkit_google_cloud import FirestoreSessionStore
from genkit.exp import Genkit
from genkit_google_cloud.exp import FirestoreSessionStore
from genkit_google_genai import GoogleAI

ai = Genkit(plugins=[GoogleAI()])
Expand Down
37 changes: 30 additions & 7 deletions bin/bump_version
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ usage() {
echo "Bump version for all Genkit Python packages."
echo ""
echo "Arguments:"
echo " new_version New version number (e.g., 0.5.0, 1.0.0)"
echo " new_version New version number (e.g., 0.5.0, 1.0.0, 1.0.0-rc.1)"
echo ""
echo "Options:"
echo " --major Bump major version (X.0.0)"
Expand All @@ -62,30 +62,52 @@ usage() {
echo " $0 --major # Bump major version (0.4.0 -> 1.0.0)"
}

# Parse current version
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
# Parse current base version (strip any -rc.N suffix)
IFS='.' read -r MAJOR MINOR PATCH <<< "${CURRENT_VERSION%%-rc.*}"

# Parse arguments
DRY_RUN=false
NO_LOCK=false
NEW_VERSION=""

reject_bump_flag_on_rc() {
if [[ "$CURRENT_VERSION" == *-rc.* ]]; then
local base_version="${CURRENT_VERSION%%-rc.*}"
echo -e "${RED}Error${NC}: Cannot use $1 while current version is a release candidate ($CURRENT_VERSION). Pass an explicit version (e.g., $0 $base_version)."
exit 1
fi
}

require_single_target() {
if [ -n "$NEW_VERSION" ]; then
echo "Error: Multiple versions specified"
usage
exit 1
fi
}

while [[ $# -gt 0 ]]; do
case "$1" in
--major)
reject_bump_flag_on_rc "$1"
require_single_target
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
shift
;;
--minor)
reject_bump_flag_on_rc "$1"
require_single_target
MINOR=$((MINOR + 1))
PATCH=0
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
shift
;;
--patch)
reject_bump_flag_on_rc "$1"
require_single_target
PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
shift
Expand Down Expand Up @@ -126,9 +148,10 @@ if [ -z "$NEW_VERSION" ]; then
exit 1
fi

# Validate version format
if ! [[ "$NEW_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo -e "${RED}Error${NC}: Invalid version format '$NEW_VERSION'. Expected format: X.Y.Z"
# Validate version format. X.Y.Z-rc.N is for release_rc_python.yml; PEP 440
Comment thread
huangjeff5 marked this conversation as resolved.
Resolved
# reads it as X.Y.ZrcN, and a pre-release floor lets pip pick sibling RCs.
if ! [[ "$NEW_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]]; then
Comment thread
huangjeff5 marked this conversation as resolved.
Resolved
echo -e "${RED}Error${NC}: Invalid version format '$NEW_VERSION'. Expected format: X.Y.Z or X.Y.Z-rc.N"
exit 1
fi

Expand Down Expand Up @@ -220,7 +243,7 @@ else
if ! $NO_LOCK; then
# Update lock file
echo -e "${CYAN}Updating lock file...${NC}"
uv lock > /dev/null 2>&1
uv lock --quiet
echo -e " ${GREEN}✓${NC} uv.lock updated"
fi

Expand Down
17 changes: 9 additions & 8 deletions packages/genkit-a2ui/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ readme = "README.md"
requires-python = ">=3.10"
version = "0.13.0"

[project.optional-dependencies]
dev = [
"pytest>=8.3.4",
"pytest-asyncio>=0.25.2",
"pytest-cov>=6.0.0",
"pytest-xdist>=3.6.1",
]

[project.urls]
"Bug Tracker" = "https://github.com/genkit-ai/genkit-python/issues"
Changelog = "https://github.com/genkit-ai/genkit-python/releases"
Expand All @@ -79,3 +71,12 @@ requires = ["hatchling"]
[tool.hatch.build.targets.wheel]
only-include = ["src/genkit_a2ui"]
sources = ["src"]

# Test tools stay out of the published wheel metadata (PEP 735).
[dependency-groups]
dev = [
"pytest>=8.3.4",
"pytest-asyncio>=0.25.2",
"pytest-cov>=6.0.0",
"pytest-xdist>=3.6.1",
]
8 changes: 8 additions & 0 deletions packages/genkit-google-cloud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ stored as a snapshot, sessions survive restarts and resume across
processes, and status subscriptions enable features like a cross-process
stop button.

It needs the `firestore` extra; telemetry-only installs skip the Firestore
and gRPC dependencies:

```bash
pip install 'genkit-google-cloud[firestore]'
# or: uv add 'genkit-google-cloud[firestore]'
```

```python
from genkit.exp import Genkit
from genkit_google_cloud.exp import FirestoreSessionStore
Expand Down
5 changes: 4 additions & 1 deletion packages/genkit-google-cloud/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ classifiers = [
dependencies = [
"genkit>=0.13.0,<2",
"genkit-otel>=0.13.0,<2",
"google-cloud-firestore>=2.14.0",
"google-cloud-logging>=3.10.0",
"opentelemetry-api>=1.20.0",
"opentelemetry-sdk>=1.20.0",
Expand All @@ -69,6 +68,10 @@ readme = "README.md"
requires-python = ">=3.10"
version = "0.13.0"

[project.optional-dependencies]
# genkit_google_cloud.exp.FirestoreSessionStore. Telemetry needs none of it.
firestore = ["google-cloud-firestore>=2.14.0"]

[project.urls]
"Bug Tracker" = "https://github.com/genkit-ai/genkit-python/issues"
Changelog = "https://github.com/genkit-ai/genkit-python/releases"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,26 @@
from typing import Any, Generic, Literal

from google.api_core import exceptions as google_exceptions
from google.cloud import firestore
from google.cloud.firestore import (
AsyncClient,
AsyncCollectionReference,
AsyncDocumentReference,
AsyncTransaction,
DocumentSnapshot,
)

try:
from google.cloud import firestore
from google.cloud.firestore import (
AsyncClient,
AsyncCollectionReference,
AsyncDocumentReference,
AsyncTransaction,
DocumentSnapshot,
)
except ImportError as e:
# Only a missing google-cloud-firestore gets the install hint; a broken
# transitive dependency keeps its own error.
if e.name not in ('google.cloud', 'google.cloud.firestore'):
raise
raise ModuleNotFoundError(
'FirestoreSessionStore needs google-cloud-firestore: '
"pip install 'genkit-google-cloud[firestore]' (or uv add 'genkit-google-cloud[firestore]')",
name='google.cloud.firestore',
) from e
from pydantic import BaseModel, ConfigDict, Field, field_validator
from pydantic.alias_generators import to_camel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
for Google Cloud Trace integration.
"""

import warnings
from collections.abc import Callable, Sequence

from google.api_core import exceptions as core_exceptions, retry as retries
Expand All @@ -42,53 +43,63 @@
logger = get_logger(__name__)


class GenkitGCPExporter(CloudTraceSpanExporter):
"""Exports spans to Google Cloud Trace with retry logic.
# opentelemetry-exporter-gcp-trace 1.15 marks CloudTraceSpanExporter
Comment thread
huangjeff5 marked this conversation as resolved.
Resolved
# @deprecated, which emits a DeprecationWarning attributed to this module when
# subclassed. Default Python filters hide non-__main__ DeprecationWarnings, so
# it only surfaces under pytest or -W default / -W error, where users still
# can't act on it. Silence that message for this class statement; constructing
# GenkitGCPExporter doesn't warn (upstream only warns for the base class).
# Moving to the OTLP exporter upstream recommends is a separate change.
with warnings.catch_warnings():
warnings.filterwarnings('ignore', message='CloudTraceSpanExporter is deprecated', category=DeprecationWarning)

This exporter extends the base CloudTraceSpanExporter to add
robust retry handling for transient failures.
class GenkitGCPExporter(CloudTraceSpanExporter):
"""Exports spans to Google Cloud Trace with retry logic.

Note:
The parent class uses google.auth.default() to get the project ID.
"""
This exporter extends the base CloudTraceSpanExporter to add
robust retry handling for transient failures.

def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
"""Export the spans to Cloud Trace with retry logic.
Note:
The parent class uses google.auth.default() to get the project ID.
"""

Iterates through the provided spans and exports them to GCP.
def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
"""Export the spans to Cloud Trace with retry logic.

Note:
Leverages span transformation and formatting from opentelemetry-exporter-gcp-trace.
See: https://cloud.google.com/python/docs/reference/cloudtrace/latest
Iterates through the provided spans and exports them to GCP.

Args:
spans: A sequence of OpenTelemetry ReadableSpan objects to export.
Note:
Leverages span transformation and formatting from opentelemetry-exporter-gcp-trace.
See: https://cloud.google.com/python/docs/reference/cloudtrace/latest

Returns:
SpanExportResult.SUCCESS upon successful processing (does not guarantee
server-side success), or SpanExportResult.FAILURE if an error occurs.
"""
try:
self.client.batch_write_spans(
request=BatchWriteSpansRequest(
name=f'projects/{self.project_id}',
spans=self._translate_to_cloud_trace(spans),
),
retry=retries.Retry(
initial=TRACE_RETRY_INITIAL,
maximum=TRACE_RETRY_MAXIMUM,
multiplier=TRACE_RETRY_MULTIPLIER,
predicate=retries.if_exception_type(
core_exceptions.DeadlineExceeded,
Args:
spans: A sequence of OpenTelemetry ReadableSpan objects to export.

Returns:
SpanExportResult.SUCCESS upon successful processing (does not guarantee
server-side success), or SpanExportResult.FAILURE if an error occurs.
"""
try:
self.client.batch_write_spans(
request=BatchWriteSpansRequest(
name=f'projects/{self.project_id}',
spans=self._translate_to_cloud_trace(spans),
),
deadline=TRACE_RETRY_DEADLINE,
),
)
except Exception as ex:
logger.error('Error while writing to Cloud Trace', exc_info=ex)
return SpanExportResult.FAILURE

return SpanExportResult.SUCCESS
retry=retries.Retry(
initial=TRACE_RETRY_INITIAL,
maximum=TRACE_RETRY_MAXIMUM,
multiplier=TRACE_RETRY_MULTIPLIER,
predicate=retries.if_exception_type(
core_exceptions.DeadlineExceeded,
),
deadline=TRACE_RETRY_DEADLINE,
),
)
except Exception as ex:
logger.error('Error while writing to Cloud Trace', exc_info=ex)
return SpanExportResult.FAILURE

return SpanExportResult.SUCCESS


class TimeAdjustedSpan(RedactedSpan):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

"""Experimental Google Cloud APIs. Durable agent sessions live here.

Needs the ``firestore`` extra: ``pip install 'genkit-google-cloud[firestore]'``
(or ``uv add 'genkit-google-cloud[firestore]'``).

```python
from genkit.exp import Genkit
from genkit_google_cloud.exp import FirestoreSessionStore
Expand Down
Loading
Loading