From eb04988cf240c57e15af5fa0b5436cbf8722108f Mon Sep 17 00:00:00 2001 From: Jeff Huang Date: Mon, 9 Nov 2026 05:53:26 -0600 Subject: [PATCH 1/8] fix(py): cap anthropic below 1.0 in genkit-anthropic anthropic 1.0.0 removed temperature/top_p/top_k from messages.create() and moved the transport to httpx2. genkit-anthropic forwards those kwargs and catches httpx exceptions, so every fresh install that resolved anthropic>=1 raised TypeError on sampling config. Cap at <1 until the plugin is adapted (BL-22). --- packages/genkit-anthropic/pyproject.toml | 2 +- .../tests/anthropic_sdk_contract_test.py | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py diff --git a/packages/genkit-anthropic/pyproject.toml b/packages/genkit-anthropic/pyproject.toml index b8cbe74bf..52c8c6954 100644 --- a/packages/genkit-anthropic/pyproject.toml +++ b/packages/genkit-anthropic/pyproject.toml @@ -43,7 +43,7 @@ classifiers = [ "Typing :: Typed", "License :: OSI Approved :: Apache Software License", ] -dependencies = ["genkit>=0.13.0,<2", "anthropic>=0.96.0"] +dependencies = ["genkit>=0.13.0,<2", "anthropic>=0.96.0,<1"] description = "Claude on Genkit" keywords = [ "genkit", diff --git a/packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py b/packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py new file mode 100644 index 000000000..607d14ebd --- /dev/null +++ b/packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py @@ -0,0 +1,53 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +"""What the plugin assumes about the installed ``anthropic`` SDK. + +anthropic 1.0 dropped ``temperature``/``top_p``/``top_k`` from +``messages.create()`` and moved to httpx2. These tests fail if the declared +``anthropic`` range admits such a release before the plugin is adapted. +""" + +import inspect +import re +from collections.abc import Callable +from importlib.metadata import requires + +import httpx +import pytest +from anthropic import DefaultAsyncHttpxClient +from anthropic.resources.beta.messages import AsyncMessages as AsyncBetaMessages +from anthropic.resources.messages import AsyncMessages +from genkit_anthropic import AnthropicConfig + + +@pytest.mark.parametrize('create', [AsyncMessages.create, AsyncBetaMessages.create], ids=['messages', 'beta']) +def test_sdk_create_accepts_every_forwarded_kwarg(create: Callable[..., object]) -> None: + """Every ``CREATE_KWARGS`` key is a named parameter of ``create()``.""" + missing = sorted(AnthropicConfig.CREATE_KWARGS - inspect.signature(create).parameters.keys()) + assert not missing, f'{create.__module__}.create() no longer accepts {missing}' + + +def test_sdk_transport_is_httpx() -> None: + """The ``except httpx.*`` handlers in ``_models.py`` only fire on an httpx transport.""" + assert issubclass(DefaultAsyncHttpxClient, httpx.AsyncClient) + + +def test_declared_anthropic_range_excludes_1x() -> None: + """``genkit-anthropic`` caps ``anthropic`` below 1.0 until it supports 1.x.""" + reqs = [r for r in requires('genkit-anthropic') or [] if re.match(r'anthropic\b', r)] + assert len(reqs) == 1, reqs + assert '<1' in reqs[0].replace(' ', ''), reqs[0] From e833d06a4108ef5d5171e4502a385ee626db22ba Mon Sep 17 00:00:00 2001 From: Jeff Huang Date: Mon, 9 Nov 2026 05:53:26 -0600 Subject: [PATCH 2/8] fix(py): depend on flask[async] in genkit-flask genkit_flask_handler returns an async view. Flask needs asgiref (the async extra) to run it; without it the first request fails with 'Install Flask with the async extra'. The monorepo venv masked this because genkit-django pulls asgiref. --- packages/genkit-flask/pyproject.toml | 2 +- .../tests/flask_dependency_test.py | 32 +++++++++++++++++++ uv.lock | 11 +++++-- 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 packages/genkit-flask/tests/flask_dependency_test.py diff --git a/packages/genkit-flask/pyproject.toml b/packages/genkit-flask/pyproject.toml index 2858cd782..29fa8ce79 100644 --- a/packages/genkit-flask/pyproject.toml +++ b/packages/genkit-flask/pyproject.toml @@ -47,7 +47,7 @@ classifiers = [ dependencies = [ "genkit>=0.13.0,<2", "pydantic>=2.11", - "flask>=3.1.3", + "flask[async]>=3.1.3", ] description = "Hang a Genkit flow on the Flask app you already have" keywords = [ diff --git a/packages/genkit-flask/tests/flask_dependency_test.py b/packages/genkit-flask/tests/flask_dependency_test.py new file mode 100644 index 000000000..5fd9f592d --- /dev/null +++ b/packages/genkit-flask/tests/flask_dependency_test.py @@ -0,0 +1,32 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +"""genkit-flask must pull in Flask's async extra on its own. + +``genkit_flask_handler`` returns an ``async def`` view, which Flask runs only +when ``asgiref`` is installed. The workspace venv gets ``asgiref`` from +genkit-django, so this checks the declared metadata rather than the venv. +""" + +import re +from importlib.metadata import requires + + +def test_declares_flask_async_extra() -> None: + """``genkit-flask`` requires ``flask[async]``, not bare ``flask``.""" + reqs = [r for r in requires('genkit-flask') or [] if re.match(r'flask\b', r, re.IGNORECASE)] + assert len(reqs) == 1, reqs + assert re.match(r'flask\s*\[\s*async\s*\]', reqs[0], re.IGNORECASE), reqs[0] diff --git a/uv.lock b/uv.lock index 047115cf6..bffd72cba 100644 --- a/uv.lock +++ b/uv.lock @@ -1522,6 +1522,11 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/7f/9c/34f6962f9b9e9c71f6e5ed806e0d0ff03c9d1b0b2340088a0cf4bce09b18/flask-3.1.3-py3-none-any.whl", hash = "sha256:f4bcbefc124291925f1a26446da31a5178f9483862233b23c0c96a20701f670c", size = 103424, upload-time = "2026-02-19T05:00:56.027Z" }, ] +[package.optional-dependencies] +async = [ + { name = "asgiref" }, +] + [[package]] name = "flask-hello" version = "0.2.0" @@ -1742,7 +1747,7 @@ dependencies = [ [package.metadata] requires-dist = [ - { name = "anthropic", specifier = ">=0.96.0" }, + { name = "anthropic", specifier = ">=0.96.0,<1" }, { name = "genkit", editable = "packages/genkit" }, ] @@ -1801,14 +1806,14 @@ name = "genkit-flask" version = "0.13.0" source = { editable = "packages/genkit-flask" } dependencies = [ - { name = "flask" }, + { name = "flask", extra = ["async"] }, { name = "genkit" }, { name = "pydantic" }, ] [package.metadata] requires-dist = [ - { name = "flask", specifier = ">=3.1.3" }, + { name = "flask", extras = ["async"], specifier = ">=3.1.3" }, { name = "genkit", editable = "packages/genkit" }, { name = "pydantic", specifier = ">=2.11" }, ] From bcf3c1ace686f9c84721e0091f6d6703a74bab71 Mon Sep 17 00:00:00 2001 From: Jeff Huang Date: Mon, 9 Nov 2026 06:02:12 -0600 Subject: [PATCH 3/8] ci(py): install each wheel in an isolated venv The workspace venv carries every package's dependencies, so a package that forgets one (genkit-flask without flask[async]) passes CI and breaks on PyPI. check_isolated_wheels installs each built genkit wheel into its own venv and imports it, with targeted smokes for genkit-flask (async view request) and genkit-anthropic (SDK create() signature). --- bin/check_isolated_wheels | 103 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100755 bin/check_isolated_wheels diff --git a/bin/check_isolated_wheels b/bin/check_isolated_wheels new file mode 100755 index 000000000..5ead299ee --- /dev/null +++ b/bin/check_isolated_wheels @@ -0,0 +1,103 @@ +#!/usr/bin/env bash +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +# Install each built genkit wheel into its own fresh venv and smoke-test it. +# +# The workspace venv holds every package's dependencies (genkit-django pulls in +# asgiref, for example), which hides a package that forgets to declare one. +# Run after build_dists. Usage: py/bin/check_isolated_wheels [dist_dir] + +set -euo pipefail + +TOP_DIR=$(git rev-parse --show-toplevel) +DIST_DIR=$(cd "${1:-${TOP_DIR}/py/dist}" && pwd) +PYTHON_VERSION=${PYTHON_VERSION:-3.12} +WORK_DIR=$(mktemp -d) +trap 'rm -rf "${WORK_DIR}"' EXIT + +core_wheels=("${DIST_DIR}"/genkit-[0-9]*.whl) +if [[ ! -e "${core_wheels[0]}" ]]; then + echo "Error: no genkit core wheel in ${DIST_DIR}" >&2 + exit 1 +fi + +# Package-specific smoke beyond `import `. Must not touch the network. +smoke_script() { + case "$1" in + genkit_flask) + # Flask runs async views only with asgiref (flask[async]). + cat <<'PY' +from flask import Flask +from genkit import Genkit +from genkit_flask import genkit_flask_handler + +ai = Genkit() +app = Flask(__name__) + + +@app.post('/greet') +@genkit_flask_handler(ai) +@ai.flow() +async def greet(name: str) -> str: + return f'Hello {name}' + + +resp = app.test_client().post('/greet', json={'data': 'Ada'}) +assert resp.status_code == 200, (resp.status_code, resp.get_data(as_text=True)[:500]) +PY + ;; + genkit_anthropic) + # genkit-anthropic forwards these kwargs to messages.create(). + cat <<'PY' +import inspect + +from anthropic.resources.messages import AsyncMessages +from genkit_anthropic import AnthropicConfig + +missing = AnthropicConfig.CREATE_KWARGS - inspect.signature(AsyncMessages.create).parameters.keys() +assert not missing, f'installed anthropic SDK no longer accepts {sorted(missing)}' +PY + ;; + *) + echo "import $1" + ;; + esac +} + +failed=() +for wheel in "${DIST_DIR}"/genkit*.whl; do + module=$(basename "${wheel}" | cut -d- -f1) + venv="${WORK_DIR}/${module}" + echo "==> ${module}" + uv venv --quiet --python "${PYTHON_VERSION}" "${venv}" + # Pass the local core wheel explicitly so it wins over the same version on PyPI. + if ! uv pip install --quiet --python "${venv}/bin/python" --find-links "${DIST_DIR}" \ + "${wheel}" "${core_wheels[0]}"; then + failed+=("${module} (install)") + continue + fi + if ! smoke_script "${module}" | "${venv}/bin/python" -W error::RuntimeWarning -; then + failed+=("${module} (smoke)") + fi +done + +if ((${#failed[@]})); then + echo "Isolated wheel check failed:" >&2 + printf ' - %s\n' "${failed[@]}" >&2 + exit 1 +fi +echo "All wheels install and import in isolation." From 28c570b26498591b8e9e3228de103c44c53b7227 Mon Sep 17 00:00:00 2001 From: Jeff Huang Date: Mon, 9 Nov 2026 12:51:29 -0600 Subject: [PATCH 4/8] ci: add check_isolated_wheels step to python.yml workflow --- .github/workflows/python.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 5762e1181..491b91292 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -212,6 +212,9 @@ jobs: - name: Build and verify distributions run: ./bin/build_dists + - name: Install each wheel in an isolated venv + run: ./bin/check_isolated_wheels + - name: Verify wheel contents run: | cd . From 8f44abfbf035aa4e890b7acb4e09b67b025f0958 Mon Sep 17 00:00:00 2001 From: Jeff Huang Date: Mon, 9 Nov 2026 16:43:41 -0600 Subject: [PATCH 5/8] ci(py): fix dist directory lookup in check_isolated_wheels --- bin/check_isolated_wheels | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/check_isolated_wheels b/bin/check_isolated_wheels index 5ead299ee..417fb5b61 100755 --- a/bin/check_isolated_wheels +++ b/bin/check_isolated_wheels @@ -24,7 +24,11 @@ set -euo pipefail TOP_DIR=$(git rev-parse --show-toplevel) -DIST_DIR=$(cd "${1:-${TOP_DIR}/py/dist}" && pwd) +DEFAULT_DIST="${TOP_DIR}/dist" +if [[ ! -d "${DEFAULT_DIST}" && -d "${TOP_DIR}/py/dist" ]]; then + DEFAULT_DIST="${TOP_DIR}/py/dist" +fi +DIST_DIR=$(cd "${1:-${DEFAULT_DIST}}" && pwd) PYTHON_VERSION=${PYTHON_VERSION:-3.12} WORK_DIR=$(mktemp -d) trap 'rm -rf "${WORK_DIR}"' EXIT From 8588fe1786ca878c8d4eda9491a9a2ab4ae71606 Mon Sep 17 00:00:00 2001 From: Jeff Huang Date: Tue, 10 Nov 2026 01:12:07 -0600 Subject: [PATCH 6/8] ci(py): drop monorepo py/ paths from check_isolated_wheels This repo builds into ./dist. The py/dist fallback and py/bin usage line were carried over from the monorepo port. --- bin/check_isolated_wheels | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/bin/check_isolated_wheels b/bin/check_isolated_wheels index 417fb5b61..a7545c0e5 100755 --- a/bin/check_isolated_wheels +++ b/bin/check_isolated_wheels @@ -19,16 +19,12 @@ # # The workspace venv holds every package's dependencies (genkit-django pulls in # asgiref, for example), which hides a package that forgets to declare one. -# Run after build_dists. Usage: py/bin/check_isolated_wheels [dist_dir] +# Run after build_dists. Usage: bin/check_isolated_wheels [dist_dir] set -euo pipefail TOP_DIR=$(git rev-parse --show-toplevel) -DEFAULT_DIST="${TOP_DIR}/dist" -if [[ ! -d "${DEFAULT_DIST}" && -d "${TOP_DIR}/py/dist" ]]; then - DEFAULT_DIST="${TOP_DIR}/py/dist" -fi -DIST_DIR=$(cd "${1:-${DEFAULT_DIST}}" && pwd) +DIST_DIR=$(cd "${1:-${TOP_DIR}/dist}" && pwd) PYTHON_VERSION=${PYTHON_VERSION:-3.12} WORK_DIR=$(mktemp -d) trap 'rm -rf "${WORK_DIR}"' EXIT From 939ad1d964813a3860afabfac2b39c52e10d60c2 Mon Sep 17 00:00:00 2001 From: huangjeff5 <64040981+huangjeff5@users.noreply.github.com> Date: Tue, 10 Nov 2026 12:08:27 -0600 Subject: [PATCH 7/8] Update packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py Co-authored-by: Jacob Cable <32874567+cabljac@users.noreply.github.com> --- .../genkit-anthropic/tests/anthropic_sdk_contract_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py b/packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py index 607d14ebd..5244fdd21 100644 --- a/packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py +++ b/packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py @@ -48,6 +48,6 @@ def test_sdk_transport_is_httpx() -> None: def test_declared_anthropic_range_excludes_1x() -> None: """``genkit-anthropic`` caps ``anthropic`` below 1.0 until it supports 1.x.""" - reqs = [r for r in requires('genkit-anthropic') or [] if re.match(r'anthropic\b', r)] + reqs = [Requirement(r) for r in requires('genkit-anthropic') or [] if re.match(r'anthropic\b', r)] assert len(reqs) == 1, reqs - assert '<1' in reqs[0].replace(' ', ''), reqs[0] + assert '1.0.0' not in reqs[0].specifier, reqs[0] From 184061fbdf9b4ce3857b84f985db8c24c85b06c7 Mon Sep 17 00:00:00 2001 From: Jeff Huang Date: Tue, 10 Nov 2026 12:14:53 -0600 Subject: [PATCH 8/8] test(anthropic): import Requirement for the specifier check --- packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py b/packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py index 5244fdd21..3636ba861 100644 --- a/packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py +++ b/packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py @@ -32,6 +32,7 @@ from anthropic.resources.beta.messages import AsyncMessages as AsyncBetaMessages from anthropic.resources.messages import AsyncMessages from genkit_anthropic import AnthropicConfig +from packaging.requirements import Requirement @pytest.mark.parametrize('create', [AsyncMessages.create, AsyncBetaMessages.create], ids=['messages', 'beta'])