Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

Run Strands Decider 4B as the chart's default decision model

agent-runner3536098450aee5f
diff --git a/.github/workflows/switch-release.yml b/.github/workflows/switch-release.yml
index abb3597a0..98d9fb28b 100644
--- a/.github/workflows/switch-release.yml
+++ b/.github/workflows/switch-release.yml
@@ -1,7 +1,8 @@
name: switch release
# Builds and publishes the Switch core stack — the switch-core, gateway, setup,
-# switch-decision and switch-hosted-controller container images, the switch and
+# switch-decision, switch-decision-strands and switch-hosted-controller
+# container images, the switch and
# switch-hosted-controller Helm charts, and the standalone Docker Compose file
# (as an OCI artifact) — so adopters can deploy without building from source.
# See RELEASING.md for the full procedure.
@@ -268,9 +269,20 @@ jobs:
PY
grep -m1 '^version = ' core/pyproject.toml
+ - name: Free disk space
+ # A large image (the Strands Decider model server: CUDA and PyTorch,
+ # several GB) does not fit in what the runner leaves free.
+ if: ${{ matrix.large }}
+ run: |
+ df -h /
+ sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL
+ sudo docker image prune --all --force
+ df -h /
+
- name: Set up QEMU
# Enables arm64 emulation so buildx can produce a multi-arch manifest
# from an amd64 runner.
+ if: ${{ contains(matrix.platforms, 'linux/arm64') }}
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
- name: Set up Docker Buildx
@@ -289,7 +301,9 @@ jobs:
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
- platforms: linux/amd64,linux/arm64
+ # From scripts/pin_chart_images.py: both, or amd64 alone for the
+ # CUDA model server.
+ platforms: ${{ matrix.platforms }}
push: ${{ needs.prep.outputs.push == 'true' }}
# Read by Dockerfile.switch only; the other images ignore them.
build-args: |
@@ -298,8 +312,10 @@ jobs:
tags: |
${{ env.REGISTRY }}/${{ needs.prep.outputs.namespace }}/${{ matrix.image }}:${{ needs.prep.outputs.version }}
${{ needs.prep.outputs.latest == 'true' && format('{0}/{1}/{2}:latest', env.REGISTRY, needs.prep.outputs.namespace, matrix.image) || '' }}
- cache-from: type=gha,scope=${{ matrix.image }}
- cache-to: type=gha,scope=${{ matrix.image }},mode=max
+ # A large image stays out of the GitHub Actions cache: its layers alone
+ # would fill the repository's 10 GB and evict every other image's.
+ cache-from: ${{ !matrix.large && format('type=gha,scope={0}', matrix.image) || '' }}
+ cache-to: ${{ !matrix.large && format('type=gha,scope={0},mode=max', matrix.image) || '' }}
# The digest of the multi-arch index, which is what a pod pulls by. The
# chart job writes it into values.yaml, so it has to leave this job.
diff --git a/RELEASING.md b/RELEASING.md
index f8b449517..ca5e4b0c1 100644
--- a/RELEASING.md
+++ b/RELEASING.md
@@ -1,8 +1,8 @@
# Releasing Switch
This describes how to cut a release of the **Switch core stack** — the
-`switch-core`, `gateway`, `setup`, `switch-decision` and
-`switch-hosted-controller` container images, the Helm charts, and the standalone Docker Compose file. The Switch Console desktop app releases separately
+`switch-core`, `gateway`, `setup`, `switch-decision`,
+`switch-decision-strands` and `switch-hosted-controller` container images, the Helm charts, and the standalone Docker Compose file. The Switch Console desktop app releases separately
(see `.github/workflows/switch-console-release.yml` and `console/docs/INSTALL.md`).
## Versioning
@@ -83,7 +83,9 @@ peer still on it, and it can never be raised past what is running in the field.
5. The **`switch-release`** workflow (`.github/workflows/switch-release.yml`)
then, on that tag:
- builds multi-arch (`linux/amd64`, `linux/arm64`) images for `switch-core`,
- `gateway`, `setup` and `switch-decision` (and the hosted controller) and
+ `gateway`, `setup` and `switch-decision` (and the hosted controller), and
+ an amd64-only `switch-decision-strands` (the Strands Decider model server,
+ CUDA and PyTorch, several GB; built without the Actions layer cache), and
pushes them to the container registry tagged
`<version>` and `latest`;
- builds, tests and packs the agent controller at the same version and
@@ -134,7 +136,7 @@ environment runs main from published, digest-pinned artifacts instead of
building from source at deploy time.
- **Separate packages.** Dev builds go to `ghcr.io/<owner>/dev/` (`dev/switch-core`,
- `dev/gateway`, `dev/setup`, `dev/switch-decision`, `dev/switch-hosted-controller`, `dev/charts/switch`,
+ `dev/gateway`, `dev/setup`, `dev/switch-decision`, `dev/switch-decision-strands`, `dev/switch-hosted-controller`, `dev/charts/switch`,
`dev/charts/switch-hosted-controller`), so the release packages' tag lists
hold releases and RCs only. Nothing is ever tagged `latest`.
- **The dev charts carry a moving `main` tag.** Once both charts are pushed,
@@ -180,7 +182,9 @@ switchCore:
and the same for `gateway`, `setup` and `decision` (the `switch-decision`
image, rendered only with `decision.enabled`; the CI render with the optional
-workloads on checks its pin). The hosted controller chart
+workloads on checks its pin), and for `decision.modelServer.strands.image`
+(`switch-decision-strands`, rendered with `decision.enabled` and the default
+`decision.modelServer.kind: strands`). The hosted controller chart
(`charts/switch-hosted-controller`) is pinned through `image.repository` and
`image.digest` instead, so its image renders as
`ghcr.io/<owner>/switch-hosted-controller@sha256:…`, by digest with no tag.
diff --git a/artifacts.yaml b/artifacts.yaml
index d5ec83842..bb0e42581 100644
--- a/artifacts.yaml
+++ b/artifacts.yaml
@@ -122,6 +122,14 @@ artifacts:
version_from: switch-core
published_as: switch-decision
+ switch-decision-strands:
+ description: >-
+ The model server for Strands Decider, the decision service's default
+ model in the Helm chart. NVIDIA GPU, amd64 only; its weights download on
+ first start, never baked in.
+ version_from: switch-core
+ published_as: switch-decision-strands
+
helm-chart:
description: >-
The Kubernetes chart. Its values.yaml is a consumer-facing interface —
diff --git a/console/packages/shared/src/artifacts.ts b/console/packages/shared/src/artifacts.ts
index e13f7266d..183a741eb 100644
--- a/console/packages/shared/src/artifacts.ts
+++ b/console/packages/shared/src/artifacts.ts
@@ -27,6 +27,7 @@ export const ARTIFACT_VERSIONS = {
gateway: '0.31.0',
setup: '0.31.0',
'switch-decision': '0.31.0',
+ 'switch-decision-strands': '0.31.0',
'helm-chart': '0.31.0',
'hosted-controller': '0.31.0',
'hosted-controller-chart': '0.31.0',
diff --git a/console/packages/switch-agent-runtime/src/artifacts.ts b/console/packages/switch-agent-runtime/src/artifacts.ts
index e13f7266d..183a741eb 100644
--- a/console/packages/switch-agent-runtime/src/artifacts.ts
+++ b/console/packages/switch-agent-runtime/src/artifacts.ts
@@ -27,6 +27,7 @@ export const ARTIFACT_VERSIONS = {
gateway: '0.31.0',
setup: '0.31.0',
'switch-decision': '0.31.0',
+ 'switch-decision-strands': '0.31.0',
'helm-chart': '0.31.0',
'hosted-controller': '0.31.0',
'hosted-controller-chart': '0.31.0',
diff --git a/core/switch_core/artifacts.py b/core/switch_core/artifacts.py
index 2b1f6fc3a..483dcbd78 100644
--- a/core/switch_core/artifacts.py
+++ b/core/switch_core/artifacts.py
@@ -27,6 +27,7 @@ ARTIFACT_VERSIONS: Final[dict[str, str]] = {
"gateway": "0.31.0",
"setup": "0.31.0",
"switch-decision": "0.31.0",
+ "switch-decision-strands": "0.31.0",
"helm-chart": "0.31.0",
"hosted-controller": "0.31.0",
"hosted-controller-chart": "0.31.0",
diff --git a/core/tests/test_pin_chart_images.py b/core/tests/test_pin_chart_images.py
index e87b156cc..31b5e1dd7 100644
--- a/core/tests/test_pin_chart_images.py
+++ b/core/tests/test_pin_chart_images.py
@@ -27,9 +27,16 @@ DIGESTS = {
"gateway": "sha256:" + "b" * 64,
"setup": "sha256:" + "c" * 64,
"switch-decision": "sha256:" + "e" * 64,
+ "switch-decision-strands": "sha256:" + "9" * 64,
"switch-hosted-controller": "sha256:" + "f" * 64,
}
-SWITCH_IMAGES = ("switch-core", "gateway", "setup", "switch-decision")
+SWITCH_IMAGES = (
+ "switch-core",
+ "gateway",
+ "setup",
+ "switch-decision",
+ "switch-decision-strands",
+)
def _load(name: str) -> ModuleType:
@@ -52,7 +59,11 @@ def test_the_image_table_matches_the_dockerfiles_and_values() -> None:
values = yaml.safe_load((REPO_ROOT / chart.path / "values.yaml").read_text())
assert (REPO_ROOT / image.dockerfile).is_file(), name
assert (REPO_ROOT / image.context).is_dir(), name
- assert image.values_key in values, name
+ node = values
+ for key in image.values_key.split("."):
+ assert key in node, (name, image.values_key)
+ node = node[key]
+ assert "image" in node or "repository" in node, name
assert set(pin_chart_images.images_of("switch")) == set(SWITCH_IMAGES)
@@ -113,6 +124,13 @@ def test_pins_every_first_party_image_in_the_real_values_file() -> None:
pinned["decision"]["image"]
== f"switch-decision:1.2.3@{DIGESTS['switch-decision']}"
)
+ # Nested: the model server's image, not llama.cpp's beside it.
+ model_server = pinned["decision"]["modelServer"]
+ assert (
+ model_server["strands"]["image"]
+ == f"switch-decision-strands:1.2.3@{DIGESTS['switch-decision-strands']}"
+ )
+ assert model_server["llamacpp"]["image"] == "ghcr.io/ggml-org/llama.cpp:server-cuda"
def test_changes_only_the_pinned_lines() -> None:
@@ -124,7 +142,7 @@ def test_changes_only_the_pinned_lines() -> None:
for a, b in zip(original.splitlines(), pinned.splitlines(), strict=True)
if a != b
]
- assert len(changed) == 5 # the registry, then one image line per image
+ assert len(changed) == 6 # the registry, then one image line per image
# Pull policy is left to the chart, which derives it from the digest.
assert yaml.safe_load(pinned)["switchCore"]["imagePullPolicy"] == ""
@@ -207,6 +225,45 @@ def _render(*extra: str) -> str:
)
+def test_pins_a_nested_key_only_inside_its_own_block() -> None:
+ values = (
+ "a:\n"
+ " image: top\n"
+ " b:\n"
+ " image: b\n"
+ " c:\n"
+ " # a comment\n"
+ " image: old\n"
+ "\n"
+ " other:\n"
+ " image: other\n"
+ " c:\n"
+ " image: not-this-c\n"
+ )
+ lines = values.splitlines(keepends=True)
+ pin_chart_images._set_child(lines, "a.b.c", "image", '"new"')
+ assert yaml.safe_load("".join(lines)) == {
+ "a": {
+ "image": "top",
+ "b": {"image": "b", "c": {"image": "new"}, "other": {"image": "other"}},
+ "c": {"image": "not-this-c"},
+ }
+ }
+ with pytest.raises(pin_chart_images.PinError, match="no key 'd'"):
+ pin_chart_images._set_child(lines, "a.d", "image", "x")
+ with pytest.raises(pin_chart_images.PinError, match="a.b.other.tag"):
+ pin_chart_images._set_child(lines, "a.b.other", "tag", "x")
+
+
+def test_the_strands_model_server_is_built_for_amd64_only() -> None:
+ matrix = {
+ image.dockerfile: (image.platforms, image.large)
+ for image in pin_chart_images.IMAGES.values()
+ }
+ assert matrix["decision/model-servers/strands/Dockerfile"] == ("linux/amd64", True)
+ assert matrix["decision/Dockerfile"] == ("linux/amd64,linux/arm64", False)
+
+
def test_verify_accepts_a_fully_pinned_render() -> None:
assert len(pin_chart_images.verify("switch", _render(), "ghcr.io/acme")) == 3
@@ -252,7 +309,15 @@ def test_verify_accepts_a_render_without_an_optional_image_but_covered_does_not(
with_decision = pin_chart_images.verify(
"switch", _render(_pinned("switch-decision")), "ghcr.io/acme"
)
- pin_chart_images.covered("switch", "\n".join([*refs, *with_decision]))
+ with pytest.raises(pin_chart_images.PinError, match="switch-decision-strands"):
+ pin_chart_images.covered("switch", "\n".join([*refs, *with_decision]))
+
+ with_model_server = pin_chart_images.verify(
+ "switch",
+ _render(_pinned("switch-decision"), _pinned("switch-decision-strands")),
+ "ghcr.io/acme",
+ )
+ pin_chart_images.covered("switch", "\n".join([*refs, *with_model_server]))
def test_record_lists_every_image_and_chart() -> None:
diff --git a/deploy/remote/helm/render-check-optional-values.yaml b/deploy/remote/helm/render-check-optional-values.yaml
index 8e303138e..f287ef594 100644
--- a/deploy/remote/helm/render-check-optional-values.yaml
+++ b/deploy/remote/helm/render-check-optional-values.yaml
@@ -24,6 +24,5 @@ decision:
bedrock:
enabled: true
modelServer:
- model:
- hfTokenSecret:
- name: render-check-hf-token
+ hfTokenSecret:
+ name: render-check-hf-token
diff --git a/deploy/remote/helm/switch/README.md b/deploy/remote/helm/switch/README.md
index 0939b99d4..c155707b2 100644
--- a/deploy/remote/helm/switch/README.md
+++ b/deploy/remote/helm/switch/README.md
@@ -291,16 +291,41 @@ pods to port 8230. It sets `DECISION_ENDPOINT_URL` on switch-core to the
Service, so every workspace's Decision routing settings in Switch Console show
it as the server default with no further setup.
-- **GPU.** The default model (Qwen3.5-4B, 4-bit, on llama.cpp's CUDA server)
- requests `nvidia.com/gpu: 1`, so the cluster needs the NVIDIA device plugin
- and a GPU node. The pod tolerates the usual `nvidia.com/gpu` taint; set
- `decision.nodeSelector` (and `decision.tolerations`) for your nodes. One
- NVIDIA L4 answers in well under a second.
-- **The model.** `decision.modelServer.image`, `.args` and `.model` (a download
- URL, the file name, an optional SHA-256, and an optional Secret with a
- Hugging Face token for a gated model) are all values, so another server with
- the same API can be swapped in. `decision.model` is the name the service
- reports. The image is pinned like the chart's other first-party images.
+- **The model.** `decision.modelServer.kind` picks the model server:
+ - `strands` (default): **Strands Decider 4B** (the E4B checkpoint) on its own
+ server image, `switch-decision-strands`, which the release builds and pins
+ like the chart's other first-party images. On one NVIDIA L4 it scored
+ 92/100 on our routing scenarios with 2 wrong picks, at 0.27 s median.
+ - `llamacpp`: **Qwen3.5-4B** (4-bit) on llama.cpp's CUDA server: 88/100 with
+ 9 wrong picks, at 0.16 s median, in a smaller footprint (8 GiB of RAM).
+
+ The decision service's backend and model name follow the kind
+ (`systemone` and `strands-decider-E4B`, or `llamacpp` and
+ `qwen3.5-4b-q4_k_m`); `decision.backend` and `decision.model` override them.
+ Each kind's image, arguments, probes and resources are under
+ `decision.modelServer.strands` or `decision.modelServer.llamacpp`.
+- **GPU and memory.** Either model server requests `nvidia.com/gpu: 1`, so the
+ cluster needs the NVIDIA device plugin and a GPU node. The pod tolerates the
+ usual `nvidia.com/gpu` taint; set `decision.nodeSelector` (and
+ `decision.tolerations`) for your nodes. Strands Decider 4B also requests
+ 24Gi of memory to load its 16 GB of bf16 weights, so give it a node with
+ 32 GiB (an AWS g6.2xlarge, one L4). The image needs an NVIDIA driver for
+ CUDA 13.0 (580 or later).
+- **Weights and the first start.** Nothing is baked into an image. Strands
+ Decider downloads its checkpoint and base model (about 17 GB) from Hugging
+ Face into the PVC (`decision.persistence.size`, 40Gi) on its first start,
+ then loads them; the port opens only once the model is loaded. Its startup
+ probe allows 30 minutes (`decision.modelServer.strands.startupProbe`), and
+ the decision service reports not ready until then. Later starts only load
+ the weights, a few minutes. For Qwen, an init container downloads the GGUF
+ file (`decision.modelServer.llamacpp.model`: URL, file name, optional
+ SHA-256) first. `decision.modelServer.hfTokenSecret` names a Secret with a
+ Hugging Face token, for a gated checkpoint or higher Hub rate limits.
+- **Licence.** Strands Decider is Apache-2.0, but its 4B checkpoint is built on
+ Google's Gemma 4 (`google/gemma-4-E4B-it`), whose terms apply to anyone
+ deploying it. The chart downloads the weights at deploy time from Hugging
+ Face; Switch does not redistribute them. Choose `llamacpp` if those terms
+ don't suit you.
- **Haiku on Bedrock.** `decision.bedrock.enabled` lets workspaces choose Claude
Haiku on Amazon Bedrock (`DECISION_BEDROCK_ENABLED` on the service and on
switch-core). The service calls Bedrock with the pod's credentials: give it
diff --git a/deploy/remote/helm/switch/templates/_helpers.tpl b/deploy/remote/helm/switch/templates/_helpers.tpl
index 975bc2b0f..ff9828919 100644
--- a/deploy/remote/helm/switch/templates/_helpers.tpl
+++ b/deploy/remote/helm/switch/templates/_helpers.tpl
@@ -1195,12 +1195,66 @@ Usage: {{ include "switch.waitForHttp" (dict "name" "gateway" "url" "http://host
{{- end }}
{{/*
-The weights file name inside /models: decision.modelServer.model.file.
+The weights file name inside /models: decision.modelServer.llamacpp.model.file.
*/}}
{{- define "switch.decisionModelFile" -}}
-{{- $file := required "decision.modelServer.model.file is required" .Values.decision.modelServer.model.file -}}
+{{- $file := required "decision.modelServer.llamacpp.model.file is required" .Values.decision.modelServer.llamacpp.model.file -}}
{{- if contains "/" $file -}}
-{{- fail (printf "decision.modelServer.model.file must be a file name, not a path: %q" $file) -}}
+{{- fail (printf "decision.modelServer.llamacpp.model.file must be a file name, not a path: %q" $file) -}}
{{- end -}}
{{- $file -}}
{{- end }}
+
+{{/*
+Which model server runs beside the decision service: decision.modelServer.kind,
+strands or llamacpp.
+*/}}
+{{- define "switch.decisionModelServerKind" -}}
+{{- $kind := .Values.decision.modelServer.kind -}}
+{{- if not (has $kind (list "strands" "llamacpp")) -}}
+{{- fail (printf "decision.modelServer.kind must be strands or llamacpp, not %q" $kind) -}}
+{{- end -}}
+{{- $kind -}}
+{{- end }}
+
+{{/*
+DECISION_BACKEND: decision.backend, or else the API the model server speaks
+(systemone for strands, llamacpp for llamacpp). Without a model server there is
+nothing to derive it from, so it must be set (anthropic or bedrock).
+*/}}
+{{- define "switch.decisionBackend" -}}
+{{- $d := .Values.decision -}}
+{{- if $d.backend -}}
+{{- $d.backend -}}
+{{- else if $d.modelServer.enabled -}}
+{{- ternary "systemone" "llamacpp" (eq (include "switch.decisionModelServerKind" .) "strands") -}}
+{{- else -}}
+{{- fail "decision.backend is required when decision.modelServer.enabled is false: anthropic or bedrock, say." -}}
+{{- end -}}
+{{- end }}
+
+{{/*
+DECISION_MODEL: decision.model, or else the model server's modelName. Empty
+(without a model server) keeps the service's default for its backend.
+*/}}
+{{- define "switch.decisionModel" -}}
+{{- $d := .Values.decision -}}
+{{- if $d.model -}}
+{{- $d.model -}}
+{{- else if $d.modelServer.enabled -}}
+{{- (get $d.modelServer (include "switch.decisionModelServerKind" .)).modelName -}}
+{{- end -}}
+{{- end }}
+
+{{/*
+HF_TOKEN env entry from decision.modelServer.hfTokenSecret, or nothing.
+*/}}
+{{- define "switch.decisionHfToken" -}}
+{{- with .Values.decision.modelServer.hfTokenSecret.name }}
+- name: HF_TOKEN
+ valueFrom:
+ secretKeyRef:
+ name: {{ . }}
+ key: {{ $.Values.decision.modelServer.hfTokenSecret.key }}
+{{- end }}
+{{- end }}
diff --git a/deploy/remote/helm/switch/templates/decision/deployment.yaml b/deploy/remote/helm/switch/templates/decision/deployment.yaml
index c41b980c7..48de7090b 100644
--- a/deploy/remote/helm/switch/templates/decision/deployment.yaml
+++ b/deploy/remote/helm/switch/templates/decision/deployment.yaml
@@ -1,5 +1,11 @@
{{- if .Values.decision.enabled }}
{{- $d := .Values.decision }}
+{{- $ms := $d.modelServer }}
+{{- $kind := "" }}
+{{- if $ms.enabled }}
+{{- $kind = include "switch.decisionModelServerKind" . }}
+{{- end }}
+{{- $backend := include "switch.decisionBackend" . }}
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -27,7 +33,8 @@ spec:
{{- end }}
serviceAccountName: {{ include "switch.decisionHost" . }}
securityContext:
- # The decision image's user; the downloader writes the weights as it.
+ # The decision images' user; the model server or the downloader writes
+ # the weights as it.
fsGroup: 10001
fsGroupChangePolicy: OnRootMismatch
seccompProfile:
@@ -40,12 +47,13 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
- {{- if $d.modelServer.enabled }}
+ {{- if eq $kind "llamacpp" }}
+ {{- $llama := $ms.llamacpp }}
initContainers:
# Downloads the weights into the volume unless they are already there,
# resuming a download a restart interrupted.
- name: download-model
- image: {{ $d.modelServer.model.downloaderImage }}
+ image: {{ $llama.model.downloaderImage }}
command: ["sh", "-c"]
args:
- |
@@ -67,17 +75,13 @@ spec:
fi
env:
- name: MODEL_URL
- value: {{ required "decision.modelServer.model.url is required" $d.modelServer.model.url | quote }}
+ value: {{ required "decision.modelServer.llamacpp.model.url is required" $llama.model.url | quote }}
- name: MODEL_FILE
value: {{ include "switch.decisionModelFile" . | quote }}
- name: MODEL_SHA256
- value: {{ $d.modelServer.model.sha256 | quote }}
- {{- with $d.modelServer.model.hfTokenSecret.name }}
- - name: HF_TOKEN
- valueFrom:
- secretKeyRef:
- name: {{ . }}
- key: {{ $d.modelServer.model.hfTokenSecret.key }}
+ value: {{ $llama.model.sha256 | quote }}
+ {{- with include "switch.decisionHfToken" . }}
+ {{- . | trim | nindent 12 }}
{{- end }}
securityContext:
runAsNonRoot: true
@@ -109,14 +113,17 @@ spec:
- name: PORT
value: {{ $d.port | quote }}
- name: DECISION_BACKEND
- value: {{ $d.backend | quote }}
- {{- with $d.model }}
+ value: {{ $backend | quote }}
+ {{- with include "switch.decisionModel" . }}
- name: DECISION_MODEL
value: {{ . | quote }}
{{- end }}
- {{- if $d.modelServer.enabled }}
+ {{- if eq $kind "strands" }}
+ - name: SYSTEMONE_URL
+ value: "http://127.0.0.1:{{ $ms.strands.port }}/v1/systemone"
+ {{- else if eq $kind "llamacpp" }}
- name: LLAMACPP_URL
- value: "http://127.0.0.1:{{ $d.modelServer.port }}"
+ value: "http://127.0.0.1:{{ $ms.llamacpp.port }}"
{{- end }}
{{- with $d.confidenceThreshold }}
- name: DECISION_CONFIDENCE_THRESHOLD
@@ -161,11 +168,65 @@ spec:
volumeMounts:
- name: tmp
mountPath: /tmp
- {{- if $d.modelServer.enabled }}
+ {{- if eq $kind "strands" }}
+ {{- $st := $ms.strands }}
+ - name: model-server
+ image: {{ include "switch.image" (dict "global" .Values.global "image" $st.image) }}
+ imagePullPolicy: {{ include "switch.imagePullPolicy" (dict "policy" $st.imagePullPolicy "image" $st.image) }}
+ {{- with $st.args }}
+ # Appended to the image's `strands-decider serve` command.
+ args:
+ {{- range . }}
+ - {{ . | quote }}
+ {{- end }}
+ {{- end }}
+ env:
+ - name: STRANDS_CHECKPOINT
+ value: {{ required "decision.modelServer.strands.checkpoint is required" $st.checkpoint | quote }}
+ - name: STRANDS_MODEL_NAME
+ value: {{ required "decision.modelServer.strands.modelName is required" $st.modelName | quote }}
+ {{- with include "switch.decisionHfToken" . }}
+ {{- . | trim | nindent 12 }}
+ {{- end }}
+ {{- with $st.env }}
+ {{- toYaml . | nindent 12 }}
+ {{- end }}
+ ports:
+ - name: model
+ containerPort: {{ $st.port }}
+ protocol: TCP
+ # The port opens only once the checkpoint is downloaded (first start)
+ # and loaded, which takes minutes.
+ startupProbe:
+ httpGet:
+ path: /health
+ port: model
+ periodSeconds: {{ $st.startupProbe.periodSeconds }}
+ failureThreshold: {{ $st.startupProbe.failureThreshold }}
+ livenessProbe:
+ httpGet:
+ path: /health
+ port: model
+ periodSeconds: 20
+ timeoutSeconds: 5
+ failureThreshold: 3
+ securityContext:
+ runAsNonRoot: true
+ allowPrivilegeEscalation: false
+ capabilities:
+ drop: ["ALL"]
+ resources:
+ {{- toYaml $st.resources | nindent 12 }}
+ # Hugging Face's cache (HF_HOME): written on the first start.
+ volumeMounts:
+ - name: weights
+ mountPath: /models
+ {{- else if eq $kind "llamacpp" }}
+ {{- $llama := $ms.llamacpp }}
- name: model-server
- image: {{ $d.modelServer.image }}
- imagePullPolicy: {{ $d.modelServer.imagePullPolicy }}
- {{- with $d.modelServer.args }}
+ image: {{ $llama.image }}
+ imagePullPolicy: {{ $llama.imagePullPolicy }}
+ {{- with $llama.args }}
args:
{{- range . }}
- {{ . | quote }}
@@ -176,15 +237,15 @@ spec:
value: "/models/{{ include "switch.decisionModelFile" . }}"
ports:
- name: model
- containerPort: {{ $d.modelServer.port }}
+ containerPort: {{ $llama.port }}
protocol: TCP
# llama.cpp's /health is 503 until the model is loaded.
startupProbe:
httpGet:
path: /health
port: model
- periodSeconds: 5
- failureThreshold: 120
+ periodSeconds: {{ $llama.startupProbe.periodSeconds }}
+ failureThreshold: {{ $llama.startupProbe.failureThreshold }}
livenessProbe:
httpGet:
path: /health
@@ -196,7 +257,7 @@ spec:
capabilities:
drop: ["ALL"]
resources:
- {{- toYaml $d.modelServer.resources | nindent 12 }}
+ {{- toYaml $llama.resources | nindent 12 }}
volumeMounts:
- name: weights
mountPath: /models
@@ -205,7 +266,7 @@ spec:
volumes:
- name: tmp
emptyDir: {}
- {{- if $d.modelServer.enabled }}
+ {{- if $ms.enabled }}
- name: weights
persistentVolumeClaim:
claimName: {{ include "switch.decisionHost" . }}-weights
diff --git a/deploy/remote/helm/switch/values.yaml b/deploy/remote/helm/switch/values.yaml
index 5eae1c238..1706bed5a 100644
--- a/deploy/remote/helm/switch/values.yaml
+++ b/deploy/remote/helm/switch/values.yaml
@@ -865,14 +865,16 @@ mattermost:
#
# decision the switch-decision image: POST /decide and GET /health on
# `port`. CPU only. The Service exposes this port and no other.
-# model-server the self-hosted decision model (llama.cpp's server by
-# default), reached by the decision container on localhost. Its
-# weights are downloaded at first start into a PVC, never baked
-# into an image.
+# model-server the self-hosted decision model (modelServer.kind: Strands
+# Decider 4B by default, or Qwen3.5-4B on llama.cpp), reached
+# by the decision container on localhost. Its weights are
+# downloaded at first start into a PVC, never baked into an
+# image.
#
-# The default model needs one NVIDIA GPU (an L4 answers in well under a
-# second): the model server requests nvidia.com/gpu, so the cluster needs the
-# NVIDIA device plugin and a GPU node; point nodeSelector/tolerations at it.
+# The model server needs one NVIDIA GPU (an L4 answers in well under a
+# second): it requests nvidia.com/gpu, so the cluster needs the NVIDIA device
+# plugin and a GPU node; point nodeSelector/tolerations at it. Strands Decider
+# 4B also requests 24Gi of memory, so the node needs 32 GiB (a g6.2xlarge).
# Turn on the "decision_routing" and "follow_the_conversation" feature flags
# (switchCore.featureFlags.enabled) for auto-route to be offered in rooms.
decision:
@@ -882,13 +884,14 @@ decision:
# chart), Always otherwise. Set it to override.
imagePullPolicy: ""
port: 8230
- # DECISION_BACKEND: llamacpp reads the model server's probabilities over the
- # candidate agents. systemone, anthropic and bedrock are the others; with
- # anthropic or bedrock, turn modelServer.enabled off and pass their settings
- # in `env`.
- backend: llamacpp
+ # DECISION_BACKEND. Empty: the API the model server speaks (systemone for
+ # modelServer.kind strands, llamacpp for llamacpp). To run without a GPU,
+ # turn modelServer.enabled off and set anthropic or bedrock (their settings
+ # in `env`).
+ backend: ""
# DECISION_MODEL, the name /health reports and the decision log records.
- model: qwen3.5-4b-q4_k_m
+ # Empty: the model server's modelName.
+ model: ""
# DECISION_CONFIDENCE_THRESHOLD; empty keeps the service's default (0.6).
confidenceThreshold: ""
# Claude Haiku on Amazon Bedrock as a per-workspace choice. Sets
@@ -910,54 +913,99 @@ decision:
limits:
memory: "1Gi"
cpu: "1000m"
- # The model server, a sidecar in the decision pod. Any server with llama.cpp's
- # OpenAI-compatible API and GET /health works; swap image and args for
- # another (a SystemOne server for Strands Decider or Clef, say, with
- # backend: systemone and SYSTEMONE_URL in env).
+ # The model server, a sidecar in the decision pod on one GPU, reached on
+ # localhost. Its weights live in the PVC below, downloaded on the first start.
modelServer:
enabled: true
- image: ghcr.io/ggml-org/llama.cpp:server-cuda
- imagePullPolicy: IfNotPresent
- port: 8300
- # $(MODEL_PATH) is /models/<model.file>, expanded by Kubernetes.
- args:
- - -m
- - $(MODEL_PATH)
- - --host
- - 0.0.0.0
- - --port
- - "8300"
- - -ngl
- - "99"
- - -c
- - "16384"
- - -np
- - "4"
- - --jinja
- # The weights, downloaded into the PVC by an init container when the file
- # is not there yet. Changing them downloads the new file on the next start.
- model:
- url: https://huggingface.co/unsloth/Qwen3.5-4B-GGUF/resolve/main/Qwen3.5-4B-Q4_K_M.gguf
- file: Qwen3.5-4B-Q4_K_M.gguf
- # Optional hex SHA-256 of the file, checked after the download.
- sha256: ""
- # A Secret holding a Hugging Face token, for a gated model (one whose
- # licence the token's account has accepted). Empty name: no token.
- hfTokenSecret:
- name: ""
- key: HF_TOKEN
- downloaderImage: curlimages/curl:8.11.1
- resources:
- requests:
- memory: "8Gi"
- cpu: "2"
- nvidia.com/gpu: 1
- limits:
- memory: "14Gi"
- nvidia.com/gpu: 1
+ # strands: Strands Decider 4B (E4B), the default. 92/100 on our routing
+ # scenarios with 2 wrong picks, 0.27 s median on one NVIDIA L4. Needs a
+ # 24 GB GPU and about 24 GiB of RAM to load (a g6.2xlarge, say).
+ # llamacpp: Qwen3.5-4B in 4-bit on the llama.cpp server. 88/100 with 9
+ # wrong picks, 0.16 s; a smaller footprint (8 GiB of RAM).
+ kind: strands
+ # A Secret holding a Hugging Face token (key below), passed to whichever
+ # model server downloads: for a gated checkpoint (one whose licence the
+ # token's account has accepted) or higher Hub rate limits. Empty name: none.
+ hfTokenSecret:
+ name: ""
+ key: HF_TOKEN
+ strands:
+ # The release pins this image (switch-decision-strands) by digest.
+ image: switch-decision-strands:latest
+ # Empty: IfNotPresent when pinned by digest, Always otherwise.
+ imagePullPolicy: ""
+ port: 8400
+ # The Hugging Face checkpoint, downloaded into the PVC (HF_HOME) on the
+ # first start with its base model (google/gemma-4-E4B-it, about 16 GB,
+ # under the Gemma terms). Later starts only load it.
+ checkpoint: StrandsAgents/strands-decider-E4B-gemma4-v1-2610
+ # --model-name, and DECISION_MODEL unless `model` above is set.
+ modelName: strands-decider-E4B
+ # Extra arguments for `strands-decider serve` (e.g. --max-batch 8).
+ args: []
+ # Extra container env, as Kubernetes env entries.
+ env: []
+ # The port opens only once the model is loaded: the first start
+ # downloads about 16 GB and then loads it (a few minutes with 32 GiB of
+ # RAM). 10 s x 180 allows 30 minutes before the container is restarted.
+ startupProbe:
+ periodSeconds: 10
+ failureThreshold: 180
+ resources:
+ requests:
+ memory: "24Gi"
+ cpu: "2"
+ nvidia.com/gpu: 1
+ limits:
+ memory: "28Gi"
+ nvidia.com/gpu: 1
+ llamacpp:
+ image: ghcr.io/ggml-org/llama.cpp:server-cuda
+ imagePullPolicy: IfNotPresent
+ port: 8300
+ # DECISION_MODEL unless `model` above is set.
+ modelName: qwen3.5-4b-q4_k_m
+ # $(MODEL_PATH) is /models/<model.file>, expanded by Kubernetes.
+ args:
+ - -m
+ - $(MODEL_PATH)
+ - --host
+ - 0.0.0.0
+ - --port
+ - "8300"
+ - -ngl
+ - "99"
+ - -c
+ - "16384"
+ - -np
+ - "4"
+ - --jinja
+ # The weights, downloaded into the PVC by an init container when the
+ # file is not there yet. Changing them downloads the new file on the
+ # next start.
+ model:
+ url: https://huggingface.co/unsloth/Qwen3.5-4B-GGUF/resolve/main/Qwen3.5-4B-Q4_K_M.gguf
+ file: Qwen3.5-4B-Q4_K_M.gguf
+ # Optional hex SHA-256 of the file, checked after the download.
+ sha256: ""
+ downloaderImage: curlimages/curl:8.11.1
+ # llama.cpp's /health is 503 until the model is loaded (seconds).
+ startupProbe:
+ periodSeconds: 5
+ failureThreshold: 120
+ resources:
+ requests:
+ memory: "8Gi"
+ cpu: "2"
+ nvidia.com/gpu: 1
+ limits:
+ memory: "14Gi"
+ nvidia.com/gpu: 1
# The weights volume. Empty storageClass uses global.storageClass.
+ # 40Gi holds Strands Decider's Hugging Face cache (about 17 GB) with room
+ # for a second checkpoint; Qwen's file is 2.7 GB.
persistence:
- size: 20Gi
+ size: 40Gi
storageClass: ""
nodeSelector: {}
tolerations:
diff --git a/scripts/check_chart_decision.py b/scripts/check_chart_decision.py
index ecce9a79f..3c378cf2c 100755
--- a/scripts/check_chart_decision.py
+++ b/scripts/check_chart_decision.py
@@ -2,7 +2,8 @@
"""Render the switch chart with its decision service off and on, and check it.
The decision service (auto-route) is optional in the chart. Off, nothing of it
-renders and switch-core gets no endpoint. On, the chart runs it, points
+renders and switch-core gets no endpoint. On, the chart runs it beside its
+model server (Strands Decider by default, or Qwen on llama.cpp), points
switch-core at it and admits only switch-core to it. An endpoint run elsewhere
can be named instead, but not as well as the chart's own. These are the
promises deploy/remote/helm/switch/README.md makes about `decision.*`; a render
@@ -118,12 +119,7 @@ def test_on_runs_the_service_and_points_switch_core_at_it() -> None:
} in pod["tolerations"]
by_name = containers(deployment)
assert set(by_name) == {"decision", "model-server"}
- assert env_of(by_name["decision"])["LLAMACPP_URL"] == "http://127.0.0.1:8300"
- assert env_of(by_name["decision"])["DECISION_BACKEND"] == "llamacpp"
- gpu = by_name["model-server"]["resources"]
- assert gpu["limits"]["nvidia.com/gpu"] == 1
assert "nvidia.com/gpu" not in by_name["decision"]["resources"].get("limits", {})
- assert [c["name"] for c in pod["initContainers"]] == ["download-model"]
assert {
v["name"]: v["persistentVolumeClaim"]["claimName"]
for v in pod["volumes"]
@@ -152,6 +148,105 @@ def test_on_runs_the_service_and_points_switch_core_at_it() -> None:
]
+def test_strands_decider_is_the_default_model_server() -> None:
+ docs = render("--set", "decision.enabled=true", *FLAGS)
+ objects = decision_objects(docs)
+ pod = objects["Deployment"]["spec"]["template"]["spec"]
+ by_name = containers(objects["Deployment"])
+
+ env = env_of(by_name["decision"])
+ assert env["DECISION_BACKEND"] == "systemone"
+ assert env["SYSTEMONE_URL"] == "http://127.0.0.1:8400/v1/systemone"
+ assert env["DECISION_MODEL"] == "strands-decider-E4B"
+ assert "LLAMACPP_URL" not in env
+
+ server = by_name["model-server"]
+ # Its own first-party image, which the release pins by digest.
+ assert server["image"] == "switch-decision-strands:latest"
+ assert env_of(server) == {
+ "STRANDS_CHECKPOINT": "StrandsAgents/strands-decider-E4B-gemma4-v1-2610",
+ "STRANDS_MODEL_NAME": "strands-decider-E4B",
+ }
+ assert [p["containerPort"] for p in server["ports"]] == [8400]
+ resources = server["resources"]
+ assert resources["limits"]["nvidia.com/gpu"] == 1
+ assert resources["requests"]["memory"] == "24Gi"
+
+ # It downloads its own weights into the Hugging Face cache on the volume,
+ # so no init container and a writable mount; the first start downloads
+ # and loads about 16 GB, so the startup probe waits at least 20 minutes.
+ assert "initContainers" not in pod
+ assert server["volumeMounts"] == [{"name": "weights", "mountPath": "/models"}]
+ probe = server["startupProbe"]
+ assert probe["httpGet"] == {"path": "/health", "port": "model"}
+ assert probe["periodSeconds"] * probe["failureThreshold"] >= 20 * 60
+
+
+def test_qwen_on_llama_cpp_is_the_alternative() -> None:
+ docs = render(
+ "--set", "decision.enabled=true", "--set", "decision.modelServer.kind=llamacpp"
+ )
+ objects = decision_objects(docs)
+ pod = objects["Deployment"]["spec"]["template"]["spec"]
+ by_name = containers(objects["Deployment"])
+ env = env_of(by_name["decision"])
+ assert env["DECISION_BACKEND"] == "llamacpp"
+ assert env["DECISION_MODEL"] == "qwen3.5-4b-q4_k_m"
+ assert env["LLAMACPP_URL"] == "http://127.0.0.1:8300"
+ assert "SYSTEMONE_URL" not in env
+
+ server = by_name["model-server"]
+ assert server["image"] == "ghcr.io/ggml-org/llama.cpp:server-cuda"
+ assert env_of(server) == {"MODEL_PATH": "/models/Qwen3.5-4B-Q4_K_M.gguf"}
+ assert server["resources"]["limits"]["nvidia.com/gpu"] == 1
+ assert server["volumeMounts"] == [
+ {"name": "weights", "mountPath": "/models", "readOnly": True}
+ ]
+ assert [c["name"] for c in pod["initContainers"]] == ["download-model"]
+ assert "PersistentVolumeClaim" in objects
+
+
+def test_the_hugging_face_token_reaches_whichever_server_downloads() -> None:
+ token = "decision.modelServer.hfTokenSecret.name=hf"
+ secret_ref = {"secretKeyRef": {"name": "hf", "key": "HF_TOKEN"}}
+
+ def hf_token(container: dict[str, Any]) -> Any:
+ return next(
+ e.get("valueFrom") for e in container["env"] if e["name"] == "HF_TOKEN"
+ )
+
+ strands = decision_objects(render("--set", "decision.enabled=true", "--set", token))
+ assert hf_token(containers(strands["Deployment"])["model-server"]) == secret_ref
+
+ llama = decision_objects(
+ render(
+ "--set",
+ "decision.enabled=true",
+ "--set",
+ "decision.modelServer.kind=llamacpp",
+ "--set",
+ token,
+ )
+ )
+ init = llama["Deployment"]["spec"]["template"]["spec"]["initContainers"][0]
+ assert hf_token(init) == secret_ref
+
+
+def test_backend_and_model_can_be_overridden() -> None:
+ docs = render(
+ "--set",
+ "decision.enabled=true",
+ "--set",
+ "decision.model=my-decider",
+ "--set",
+ "decision.modelServer.strands.checkpoint=acme/my-decider",
+ )
+ by_name = containers(decision_objects(docs)["Deployment"])
+ assert env_of(by_name["decision"])["DECISION_MODEL"] == "my-decider"
+ assert env_of(by_name["decision"])["DECISION_BACKEND"] == "systemone"
+ assert env_of(by_name["model-server"])["STRANDS_CHECKPOINT"] == "acme/my-decider"
+
+
def test_bedrock_and_the_pod_role() -> None:
docs = render(
"--set",
@@ -186,6 +281,10 @@ def test_without_a_model_server_there_is_no_gpu_or_volume() -> None:
pod = objects["Deployment"]["spec"]["template"]["spec"]
assert [c["name"] for c in pod["containers"]] == ["decision"]
assert "initContainers" not in pod
+ env = env_of(pod["containers"][0])
+ assert env["DECISION_BACKEND"] == "anthropic"
+ assert "DECISION_MODEL" not in env
+ assert "SYSTEMONE_URL" not in env and "LLAMACPP_URL" not in env
def test_network_policy_can_be_left_out() -> None:
@@ -231,13 +330,25 @@ def test_refuses_contradictions() -> None:
"--set",
"decision.enabled=true",
"--set",
- "decision.modelServer.model.file=../x.gguf",
+ "decision.modelServer.kind=llamacpp",
+ "--set",
+ "decision.modelServer.llamacpp.model.file=../x.gguf",
+ )
+ assert "must be strands or llamacpp" in render_error(
+ "--set", "decision.enabled=true", "--set", "decision.modelServer.kind=vllm"
+ )
+ assert "decision.backend is required" in render_error(
+ "--set", "decision.enabled=true", "--set", "decision.modelServer.enabled=false"
)
TESTS: list[Callable[[], None]] = [
test_off_by_default_renders_nothing_and_sets_no_endpoint,
test_on_runs_the_service_and_points_switch_core_at_it,
+ test_strands_decider_is_the_default_model_server,
+ test_qwen_on_llama_cpp_is_the_alternative,
+ test_the_hugging_face_token_reaches_whichever_server_downloads,
+ test_backend_and_model_can_be_overridden,
test_bedrock_and_the_pod_role,
test_without_a_model_server_there_is_no_gpu_or_volume,
test_network_policy_can_be_left_out,
diff --git a/scripts/pin_chart_images.py b/scripts/pin_chart_images.py
index 613139207..cbdeb5fed 100644
--- a/scripts/pin_chart_images.py
+++ b/scripts/pin_chart_images.py
@@ -11,7 +11,8 @@ it, and what runs is reproducible from that one pin.
Two charts are published:
* `switch` (deploy/remote/helm/switch): switch-core, gateway, setup and the
- optional decision service (switch-decision).
+ optional decision service (switch-decision), with its Strands Decider model
+ server (switch-decision-strands).
* `switch-hosted-controller` (deploy/hosted/chart): the controller that runs
Switch cloud machines, and its one image.
@@ -28,8 +29,9 @@ Subcommands:
* `images` prints the image build matrix as JSON; `charts` prints the charts.
* `pin --chart <name>` rewrites that chart's `values.yaml` in place, in the
chart's `pin_style`. The switch chart gets `global.imageRegistry` and
- `<name>:<version>@sha256:…` per image (it pulls a digest-pinned image
- `IfNotPresent` on its own); the hosted controller chart gets
+ `<name>:<version>@sha256:…` per image, at `<values_key>.image`, where
+ `values_key` may be a dotted path to a nested mapping (it pulls a
+ digest-pinned image `IfNotPresent` on its own); the hosted controller chart gets
`image.repository` and `image.digest`, so its image renders as
`<registry>/<name>@sha256:…`, with no tag. The edit is
line-based so the file's comments, which are the chart's documentation under
@@ -77,12 +79,15 @@ from typing import Any, Literal
import yaml
+MULTI_ARCH = "linux/amd64,linux/arm64"
+
@dataclass(frozen=True)
class Image:
chart: str
- # Top-level values key holding the image; what goes under it is the
- # chart's `pin_style`.
+ # Values key holding the image: a top-level key, or a dotted path to a
+ # nested mapping ("decision.modelServer.strands"). What goes under it is
+ # the chart's `pin_style`.
values_key: str
dockerfile: str
context: str
@@ -90,6 +95,12 @@ class Image:
# say), so a render may leave it out; `covered` still requires it in at
# least one of the chart's renders.
optional: bool
+ # What the release builds it for.
+ platforms: str = MULTI_ARCH
+ # A multi-GB image (CUDA and PyTorch): the release frees the runner's disk
+ # before building it and keeps it out of the GitHub Actions layer cache,
+ # whose 10 GB per repository it would fill on its own.
+ large: bool = False
@dataclass(frozen=True)
@@ -152,6 +163,18 @@ IMAGES: dict[str, Image] = {
"switch-decision": Image(
"switch", "decision", "decision/Dockerfile", "decision", True
),
+ # Strands Decider's model server, beside the decision service when
+ # decision.modelServer.kind is strands (the default). NVIDIA GPUs on x86
+ # only, so amd64 alone.
+ "switch-decision-strands": Image(
+ "switch",
+ "decision.modelServer.strands",
+ "decision/model-servers/strands/Dockerfile",
+ "decision/model-servers/strands",
+ True,
+ platforms="linux/amd64",
+ large=True,
+ ),
"switch-hosted-controller": Image(
"switch-hosted-controller",
"image",
@@ -170,43 +193,58 @@ def images_of(chart: str) -> dict[str, Image]:
DIGEST = re.compile(r"^sha256:[0-9a-f]{64}$")
PLACEHOLDER_DIGEST = "sha256:" + "0" * 64
-TOP_LEVEL_KEY = re.compile(r"^([A-Za-z0-9_]+):\s*(#.*)?$")
class PinError(Exception):
pass
+def _block_end(lines: list[str], start: int, indent: int) -> int:
+ """The line after the block opened by `lines[start]`, a key at `indent`."""
+ for i in range(start + 1, len(lines)):
+ stripped = lines[i].strip()
+ if not stripped or stripped.startswith("#"):
+ continue
+ if len(lines[i]) - len(lines[i].lstrip(" ")) <= indent:
+ return i
+ return len(lines)
+
+
def _set_child(lines: list[str], parent: str, child: str, value: str) -> None:
- """Set `parent.child` to `value`, where `parent` is a top-level mapping key.
+ """Set `parent.child` to `value`; `parent` is a top-level mapping key or a
+ dotted path to a nested mapping (two-space indent per level).
- Exactly one `child` line at two-space indent must sit inside `parent`'s
- block; anything else means the values file changed shape under the pinner,
- which must fail rather than pin the wrong line or nothing at all.
+ Each key on the path, and the `child` line, must appear exactly once at its
+ indent inside its parent's block; anything else means the values file
+ changed shape under the pinner, which must fail rather than pin the wrong
+ line or nothing at all.
"""
- start = None
- for i, line in enumerate(lines):
- m = TOP_LEVEL_KEY.match(line)
- if m and m.group(1) == parent:
- if start is not None:
- raise PinError(f"top-level key {parent!r} appears more than once")
- start = i
- if start is None:
- raise PinError(f"no top-level key {parent!r}")
-
- end = len(lines)
- for i in range(start + 1, len(lines)):
- line = lines[i]
- if line and not line[0].isspace() and not line.startswith("#"):
- end = i
- break
-
- pattern = re.compile(rf"^ {re.escape(child)}:(\s.*)?$")
+ start, end = -1, len(lines)
+ for depth, key in enumerate(parent.split(".")):
+ pattern = re.compile(rf"^{' ' * (2 * depth)}{re.escape(key)}:\s*(#.*)?$")
+ hits = [
+ i for i in range(start + 1, end) if pattern.match(lines[i].rstrip("\n"))
+ ]
+ where = ".".join(parent.split(".")[:depth]) or "the top level"
+ if not hits:
+ raise PinError(f"no key {key!r} in {where}")
+ if len(hits) > 1:
+ raise PinError(f"key {key!r} appears more than once in {where}")
+ start, end = hits[0], _block_end(lines, hits[0], 2 * depth)
+
+ indent = " " * (2 * len(parent.split(".")))
+ pattern = re.compile(rf"^{indent}{re.escape(child)}:(\s.*)?$")
hits = [i for i in range(start + 1, end) if pattern.match(lines[i].rstrip("\n"))]
if len(hits) != 1:
raise PinError(f"expected one {parent}.{child} line, found {len(hits)}")
newline = "\n" if lines[hits[0]].endswith("\n") else ""
- lines[hits[0]] = f" {child}: {value}{newline}"
+ lines[hits[0]] = f"{indent}{child}: {value}{newline}"
+
+
+def _lookup(values: Any, path: str) -> Any:
+ for key in path.split("."):
+ values = values[key]
+ return values
def _check_digests(digests: dict[str, str]) -> None:
@@ -265,7 +303,7 @@ def pin(
loaded = yaml.safe_load(pinned)
for (parent, child), value in expected.items():
- if loaded[parent][child] != value:
+ if _lookup(loaded, parent)[child] != value:
raise PinError(f"pinned values do not read back {parent}.{child}")
return pinned
@@ -467,6 +505,8 @@ def main(argv: list[str]) -> int:
"image": name,
"dockerfile": image.dockerfile,
"context": image.context,
+ "platforms": image.platforms,
+ "large": image.large,
}
for name, image in IMAGES.items()
]