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
16 changes: 11 additions & 5 deletions charts/openshell-rhdh/files/create-workspace-for-user.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ spec:
inference__url: {title: 'inference: Endpoint base URL (OpenAI-compatible, ending in /v1)',
type: string, pattern: '^https?://'}
inference__model: {title: 'inference: Model', type: string}
inference__thinking: {title: 'inference: Default thinking level', type: string}
inference__reasoning: {title: 'inference: Reasoning model (true or false)', type: string}
inference__max_tokens: {title: 'inference: Maximum output tokens', type: string}
inference__context_window: {title: 'inference: Context window (tokens)', type: string}
required: [inference__api_key, inference__url, inference__model]
allOf:
- if:
Expand Down Expand Up @@ -116,11 +120,13 @@ spec:
stringData: {action: create, token: '${{ secrets.backstageToken }}', profile: '${{ parameters.profile
}}', deploymentMode: '${{ parameters.deploymentMode }}', forUser: '${{ parameters.forUser
}}', inference.api_key: '${{ secrets.inference__api_key }}', inference.url: '${{ parameters.inference__url
}}', inference.model: '${{ parameters.inference__model }}', web-search.api_key: '${{ secrets.web_search__api_key
}}', inference.cuda_model: '${{ parameters.inference__cuda_model }}', gmail.client_id: '${{
secrets.gmail__client_id }}', gmail.client_secret: '${{ secrets.gmail__client_secret }}',
gmail.refresh_token: '${{ secrets.gmail__refresh_token }}', slack.bot_token: '${{ secrets.slack__bot_token
}}'}
}}', inference.model: '${{ parameters.inference__model }}', inference.thinking: '${{ parameters.inference__thinking
}}', inference.reasoning: '${{ parameters.inference__reasoning }}', inference.max_tokens: '${{
parameters.inference__max_tokens }}', inference.context_window: '${{ parameters.inference__context_window
}}', web-search.api_key: '${{ secrets.web_search__api_key }}', inference.cuda_model: '${{
parameters.inference__cuda_model }}', gmail.client_id: '${{ secrets.gmail__client_id }}',
gmail.client_secret: '${{ secrets.gmail__client_secret }}', gmail.refresh_token: '${{ secrets.gmail__refresh_token
}}', slack.bot_token: '${{ secrets.slack__bot_token }}'}
- id: run
name: Start the pipeline
action: http:backstage:request
Expand Down
15 changes: 11 additions & 4 deletions charts/openshell-rhdh/files/create-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ spec:
inference__url: {title: 'inference: Endpoint base URL (OpenAI-compatible, ending in /v1)',
type: string, pattern: '^https?://'}
inference__model: {title: 'inference: Model', type: string}
inference__thinking: {title: 'inference: Default thinking level', type: string}
inference__reasoning: {title: 'inference: Reasoning model (true or false)', type: string}
inference__max_tokens: {title: 'inference: Maximum output tokens', type: string}
inference__context_window: {title: 'inference: Context window (tokens)', type: string}
required: [inference__api_key, inference__url, inference__model]
allOf:
- if:
Expand Down Expand Up @@ -108,10 +112,13 @@ spec:
stringData: {action: create, token: '${{ secrets.backstageToken }}', profile: '${{ parameters.profile
}}', deploymentMode: '${{ parameters.deploymentMode }}', inference.api_key: '${{ secrets.inference__api_key
}}', inference.url: '${{ parameters.inference__url }}', inference.model: '${{ parameters.inference__model
}}', web-search.api_key: '${{ secrets.web_search__api_key }}', inference.cuda_model: '${{
parameters.inference__cuda_model }}', gmail.client_id: '${{ secrets.gmail__client_id }}',
gmail.client_secret: '${{ secrets.gmail__client_secret }}', gmail.refresh_token: '${{ secrets.gmail__refresh_token
}}', slack.bot_token: '${{ secrets.slack__bot_token }}'}
}}', inference.thinking: '${{ parameters.inference__thinking }}', inference.reasoning: '${{
parameters.inference__reasoning }}', inference.max_tokens: '${{ parameters.inference__max_tokens
}}', inference.context_window: '${{ parameters.inference__context_window }}', web-search.api_key: '${{
secrets.web_search__api_key }}', inference.cuda_model: '${{ parameters.inference__cuda_model
}}', gmail.client_id: '${{ secrets.gmail__client_id }}', gmail.client_secret: '${{ secrets.gmail__client_secret
}}', gmail.refresh_token: '${{ secrets.gmail__refresh_token }}', slack.bot_token: '${{ secrets.slack__bot_token
}}'}
- id: run
name: Start the pipeline
action: http:backstage:request
Expand Down
30 changes: 30 additions & 0 deletions charts/openshell-rhdh/files/profile-catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,30 @@
"kind": "text",
"required": true,
"title": "Model"
},
{
"key": "thinking",
"kind": "text",
"required": false,
"title": "Default thinking level"
},
{
"key": "reasoning",
"kind": "text",
"required": false,
"title": "Reasoning model (true or false)"
},
{
"key": "max_tokens",
"kind": "text",
"required": false,
"title": "Maximum output tokens"
},
{
"key": "context_window",
"kind": "text",
"required": false,
"title": "Context window (tokens)"
}
],
"provider": "custom-inference",
Expand Down Expand Up @@ -113,6 +137,12 @@
"harnessRequired": false,
"image": "ghcr.io/validatedpatterns-sandbox/saw-openclaw@sha256:06eb0e7985ecbd655befa8ce35c8b8e7746c9e609c4e28068403cadd7c956686",
"modelInput": "inference.model",
"modelSettingInputs": {
"contextWindow": "inference.context_window",
"maxTokens": "inference.max_tokens",
"reasoning": "inference.reasoning",
"thinking": "inference.thinking"
},
"name": "notebook",
"type": "openclaw",
"uiRoute": true
Expand Down
29 changes: 29 additions & 0 deletions charts/openshell-rhdh/files/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def sandbox_targets(user, registration, profile, *, model_lifecycle=False):
subjectMap="saw-portal-relay-subject" if single else "saw-portal-relay-"+suffix)
if model_lifecycle and sb.get("modelInput"):
targets[key]["modelInput"] = sb["modelInput"]
# The gate Job publishes these settings with the model, so a
# later change reaches OpenClaw on restart.
if sb.get("modelSettingInputs"):
targets[key]["modelSettingInputs"] = sb["modelSettingInputs"]
return targets


Expand Down Expand Up @@ -87,9 +91,34 @@ def public_model_inputs(profile, secrets):
if not re.fullmatch(spelling, value):
raise WorkspaceError("invalid public model selector")
values[key] = value
# Optional model settings (thinking, reasoning, maxTokens, contextWindow):
# public, noncredential text fields of the same Secret. The runtime
# validates them again when it compiles the workspace.
for _, sb in enabled_catalog_sandboxes(profile):
for setting, key in (sb.get("modelSettingInputs") or {}).items():
secret, field = key.split(".", 1)
definition = next((f for f in profile["secrets"].get(secret, {}).get("fields", [])
if f["key"] == field and f["kind"] == "text"), None)
pattern = MODEL_SETTING_PATTERNS.get(setting)
if definition is None or pattern is None:
raise WorkspaceError("invalid model setting input")
value = secrets.get(secret, {}).get(field)
if value is None or value == "":
continue
if not isinstance(value, str) or value in confidential or not re.fullmatch(pattern, value.strip()):
raise WorkspaceError(f"invalid {setting} for {key}")
values[key] = value.strip()
return values


MODEL_SETTING_PATTERNS = {
"thinking": r"(?i)off|minimal|low|medium|high",
"reasoning": r"(?i)true|false",
"maxTokens": r"[1-9][0-9]{0,8}",
"contextWindow": r"[1-9][0-9]{0,8}",
}


CUSTOM_INFERENCE_URL = re.compile(r"https://[a-z0-9-]+(?:\.[a-z0-9-]+)+(?::443)?(?:/[A-Za-z0-9_-]+)*/v1")


Expand Down
105 changes: 83 additions & 22 deletions charts/openshell-saw/files/installer/apply_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,9 @@ def check_trusted_proxy(tp):
# mount; how podman reports the mount (see sandbox_harness_mount). The 0.1.x
# admission rules above are from the v0.1.2 source.

# The model-entry values SAW replaced, per model, so a setting removed from
# the profile can be restored (ProfileApplier.mark_reasoning_model).
MODEL_SETTINGS_STATE = "/sandbox/.openclaw/saw-model-settings.json"
HARNESS_MARKER = ".saw-harness-revision" # written into the volume with the bundle
HARNESS_VOLUME_PREFIX = "saw-harness-"
HARNESS_VOLUME_LABEL = "saw.redhat.com/harness-volume"
Expand Down Expand Up @@ -4041,9 +4044,18 @@ def start_openclaw(self, ws, sb, provider):
except ValueError as exc:
raise InstallerError(f"cannot read OpenClaw managed models: {exc}") from None
thinking = (sb.inference_values or {}).get("thinking", "")
if thinking:
self.mark_reasoning_model(exec_cmd, oc_env, provider.type, model_id,
reasoning=thinking != "off")
# An explicit reasoning flag wins (MODEL_REASONING=false keeps a
# thinking default but sends no reasoning_effort); otherwise any
# thinking level but off marks the model as reasoning.
reasoning = (sb.inference_values or {}).get("reasoning")
if reasoning is None and thinking:
reasoning = thinking != "off"
limits = {k: (sb.inference_values or {})[k] for k in MODEL_LIMIT_KEYS
if k in (sb.inference_values or {})}
# Also with nothing to set: a setting removed since the last apply
# restores the model entry's original value (mark_reasoning_model).
self.mark_reasoning_model(exec_cmd, oc_env, provider.type, model_id,
reasoning=reasoning, limits=limits)
if (sb.inference_values or {}).get("models") or previous or thinking:
current_models = self.cli(*exec_cmd, "sh", "-c",
f"{oc_env} openclaw config get agents.defaults --json",
Expand Down Expand Up @@ -4132,41 +4144,90 @@ def launch_openclaw(self, ws, sb, exec_cmd, oc_env):
self.clear_confinement_stop(ws, sb)
self.install_keepalive(ws, sb)

def mark_reasoning_model(self, exec_cmd, oc_env, provider_type, model_id, reasoning=True):
"""Set whether OpenClaw treats a custom provider's model as reasoning.
def mark_reasoning_model(self, exec_cmd, oc_env, provider_type, model_id, reasoning=True,
limits=None):
"""Set whether OpenClaw treats a custom provider's model as reasoning,
and its maxTokens / contextWindow when the profile gives them.

OpenClaw knows which of its own models reason; a custom model offers
only default and off unless its entry says reasoning: true and lists
the efforts the endpoint accepts (sent as reasoning_effort). Thinking
off marks it reasoning: false, so no effort is sent."""
off (or reasoning: false) marks it reasoning: false, so no effort is
sent.

Each field SAW sets keeps the value it replaced (MODEL_SETTINGS_STATE),
and a setting the profile no longer gives gets that value back, or is
removed when there was none. OpenClaw's onboarding keeps an existing
model entry's metadata, so without this a cleared setting would stay."""
desired = dict(limits or {})
if reasoning is not None:
desired["reasoning"] = reasoning
desired["compat.supportedReasoningEfforts"] = REASONING_EFFORTS if reasoning else None
bare = model_id.removeprefix(f"{provider_type}/")
state_read = self.cli(*exec_cmd, "sh", "-c",
f"if [ -f {MODEL_SETTINGS_STATE} ]; then cat {MODEL_SETTINGS_STATE}; "
"else printf '{}'; fi", check=False, quiet=True)
if self.sh.dry_run:
return
try:
state = json.loads(state_read.out) if state_read.ok else {}
if not isinstance(state, dict):
raise ValueError
except ValueError:
state = {}
originals = state.get(model_id) if isinstance(state.get(model_id), dict) else {}
if not desired and not originals:
return
key = f"models.providers.{shlex.quote(provider_type)}.models"
found = self.cli(*exec_cmd, "sh", "-c", f"{oc_env} openclaw config get {key} --json",
check=False, quiet=True)
if self.sh.dry_run:
return
try:
models = json.loads(found.out) if found.ok else None
except ValueError:
models = None
bare = model_id.removeprefix(f"{provider_type}/")
entry = next((m for m in models or [] if isinstance(m, dict) and m.get("id") in (bare, model_id)), None)
if entry is None:
log(f"WARN: {provider_type} has no model entry for '{bare}'; its thinking level "
"applies only if OpenClaw already treats it as a reasoning model")
return
compat = entry.setdefault("compat", {})
efforts = REASONING_EFFORTS if reasoning else None
if entry.get("reasoning") is reasoning and compat.get("supportedReasoningEfforts") == efforts:
if desired:
log(f"WARN: {provider_type} has no model entry for '{bare}'; its thinking level "
"and token limits apply only if OpenClaw already has them")
return
entry["reasoning"] = reasoning
if reasoning:
compat["supportedReasoningEfforts"] = REASONING_EFFORTS
before = json.dumps(entry, sort_keys=True)

def get(field):
holder = entry.get("compat", {}) if field.startswith("compat.") else entry
name = field.removeprefix("compat.")
return {"value": holder[name]} if isinstance(holder, dict) and name in holder else {}

def put(field, saved):
if field.startswith("compat."):
compat = entry.setdefault("compat", {})
name = field.removeprefix("compat.")
if "value" in saved:
compat[name] = saved["value"]
else:
compat.pop(name, None)
if not compat:
entry.pop("compat")
elif "value" in saved:
entry[field] = saved["value"]
else:
entry.pop(field, None)

for field in sorted(set(desired) | set(originals)):
if field in desired:
originals.setdefault(field, get(field))
put(field, {} if desired[field] is None else {"value": desired[field]})
else:
put(field, originals.pop(field))
if json.dumps(entry, sort_keys=True) != before:
self.cli(*exec_cmd, "sh", "-c",
f"{oc_env} openclaw config set {key} {shlex.quote(json.dumps(models))}")
if originals:
state[model_id] = originals
else:
compat.pop("supportedReasoningEfforts", None)
if not compat:
entry.pop("compat")
state.pop(model_id, None)
self.cli(*exec_cmd, "sh", "-c",
f"{oc_env} openclaw config set {key} {shlex.quote(json.dumps(models))}")
f"printf '%s\\n' {shlex.quote(json.dumps(state, sort_keys=True))} > {MODEL_SETTINGS_STATE}")

def disable_provider_channels(self, ws, sb, exec_cmd, oc_env):
"""Keep OpenClaw's own chat channel off for a provider that shares
Expand Down
Loading
Loading