Make provider sampler params opt-in; drop escalation preset

Sampler parameters (temperature/top_p/presence_penalty/frequency_penalty)
now default to None and are omitted from the request payload when unset, so
the server's model/Modelfile default applies. The provider no longer guesses
values on the user's behalf; callers opt in via config or a per-chat override.

- provider.OpenAICompatClient / llm.LLMClient: default the four params to None
  and only include them in the payload when set (max_tokens/reasoning_effort
  already behaved this way).
- cli.build_scheduler: pass None when the config key is absent via _opt_float,
  instead of hardcoded numeric fallbacks.
- codegen: remove ESCALATED_SAMPLER and its use on retries (body, elicitation,
  testgen, regen). The retry ladder keeps the fresh short prompt but reuses the
  configured/omitted sampler; appropriate values can't be known in advance for
  arbitrary user models.
- console: no functional change; the hosted Console API now receives no sampler
  params by default.
- Tests cover omit-by-default, send-when-configured, per-call override, and the
  no-escalation retry.
- Docs: config.example.json comments, provider/llm/codegen/console docstrings,
  AGENTS.md.
This commit is contained in:
gabby committed 2026-10-02 13:00:50 +00:00
1 parent 8afb488dc4
commit 5747ad2fa6
11 files changed
+223 -105

No files matched your search

+18 -8
View File
@@ -66,6 +66,16 @@ def _resolve_api_key(cfg: dict) -> str:
return ""
def _opt_float(value) -> float | None:
"""Config number for an opt-in provider parameter.
A missing/`null` key yields `None`, which the provider omits from the
request so the server's model default applies. A present value is coerced
to `float`.
"""
return None if value is None else float(value)
def _provider_endpoint(cfg: dict, default_base: str) -> dict:
"""Endpoint kwargs shared by the llm/codegen clients.
@@ -123,10 +133,10 @@ def build_scheduler(config: dict) -> tuple[Scheduler, dict]:
idle_warn=float(llm_cfg.get("idle_warn", 30.0)),
idle_timeout=float(llm_cfg.get("idle_timeout", 120.0)),
context_window=float(llm_cfg.get("context_window", 0.0)),
temperature=float(llm_cfg.get("temperature", 0.2)),
top_p=float(llm_cfg.get("top_p", 0.9)),
presence_penalty=float(llm_cfg.get("presence_penalty", 0.0)),
frequency_penalty=float(llm_cfg.get("frequency_penalty", 0.0)),
temperature=_opt_float(llm_cfg.get("temperature")),
top_p=_opt_float(llm_cfg.get("top_p")),
presence_penalty=_opt_float(llm_cfg.get("presence_penalty")),
frequency_penalty=_opt_float(llm_cfg.get("frequency_penalty")),
disable_thinking=bool(llm_cfg.get("disable_thinking", True)),
api_key=llm_endpoint["api_key"],
extra_headers=llm_endpoint["extra_headers"],
@@ -161,10 +171,10 @@ def build_scheduler(config: dict) -> tuple[Scheduler, dict]:
degeneration_interval=int(deg_cfg.get("interval", 8000)),
degeneration_window=int(deg_cfg.get("window", 2000)),
degeneration_min_chars=int(deg_cfg.get("min_chars", 4000)),
temperature=float(codegen_cfg.get("temperature", 0.7)),
top_p=float(codegen_cfg.get("top_p", 0.85)),
presence_penalty=float(codegen_cfg.get("presence_penalty", 1.5)),
frequency_penalty=float(codegen_cfg.get("frequency_penalty", 0.2)),
temperature=_opt_float(codegen_cfg.get("temperature")),
top_p=_opt_float(codegen_cfg.get("top_p")),
presence_penalty=_opt_float(codegen_cfg.get("presence_penalty")),
frequency_penalty=_opt_float(codegen_cfg.get("frequency_penalty")),
max_attempts=int(codegen_cfg.get("max_attempts", 3)),
api_key=codegen_endpoint["api_key"],
extra_headers=codegen_endpoint["extra_headers"],
+14 -33
View File
@@ -479,14 +479,6 @@ def integration_findings(integration: dict, source: str, code: str) -> list[str]
return findings
ESCALATED_SAMPLER = {
"temperature": 0.5,
"top_p": 0.85,
"presence_penalty": 2.0,
"frequency_penalty": 0.3,
}
def _retry_prompt(
request: Request,
category: str,
@@ -495,7 +487,7 @@ def _retry_prompt(
error: Exception,
requirements: dict[str, str] | None = None,
) -> list[dict]:
"""Fresh short prompt for an escalated retry.
"""Fresh short prompt for a corrective retry.
Not a growing conversation: the context resets to SMART (new request, tiny
prompt) and the model is told in one line to stop looping and emit the
@@ -538,16 +530,15 @@ def generate_skill_body(
degeneration_check: Callable[[str], str | None] | None = None,
requirements: dict[str, str] | None = None,
) -> str:
"""Author a skill body with the big model; escalate up to `max_attempts`.
"""Author a skill body with the big model; retry up to `max_attempts`.
Attempt 1 uses the client's sampler defaults. Attempts >= 2 use the
escalated sampler (higher presence_penalty to suppress repeated thinking,
lower temperature for a decisive final answer) plus a fresh short prompt
that resets the context to SMART and tells the model to emit the final
Python now. Only an invalid parse (ValueError) escalates; a
DegenerationError or other CodegenError propagates immediately so the
scheduler can stub out gracefully. `requirements` (elicitation answers) are
fed to the first-attempt prompt only.
Every attempt uses the client's configured sampler parameters (or omits
them when unset). A rejected parse (ValueError) retries with a fresh short
prompt that resets the context to SMART and tells the model to emit the
final Python now. Only an invalid parse retries; a DegenerationError or
other CodegenError propagates immediately so the scheduler can stub out
gracefully. `requirements` (elicitation answers) are fed to the
first-attempt prompt only.
"""
contract_text = contract if contract is not None else read_skill_contract()
if client.stream:
@@ -573,7 +564,6 @@ def generate_skill_body(
messages,
max_tokens=max_tokens,
degeneration_check=degeneration_check,
**(ESCALATED_SAMPLER if attempt > 1 else {}),
)
return parse_skill_body(raw)
except ValueError as exc:
@@ -734,7 +724,7 @@ def generate_elicitation(
"""Propose implementation questions + an integration hint with the big model.
Returns an empty result when the model produced none or the reply failed to
parse after the escalation ladder — elicitation must never block authoring.
parse after the retry ladder — elicitation must never block authoring.
"""
attempts = max(client.max_attempts, 1)
last_error: Exception | None = None
@@ -748,10 +738,7 @@ def generate_elicitation(
request, category, draft, tree, last_error, max_questions=max_questions
)
try:
raw = client.chat(
messages,
**(ESCALATED_SAMPLER if attempt > 1 else {}),
)
raw = client.chat(messages)
result = parse_elicitation_result(raw)
return ElicitationResult(
result.questions[: max(0, max_questions)], result.integration
@@ -977,10 +964,7 @@ def generate_skill_tests(
target=target,
)
try:
raw = client.chat(
messages,
**(ESCALATED_SAMPLER if attempt > 1 else {}),
)
raw = client.chat(messages)
return parse_skill_test(raw)
except ValueError as exc:
last_error = exc
@@ -1058,7 +1042,7 @@ def regenerate_skill_body(
"""Rewrite a skill body whose test, review, or real run failed.
Fresh prompt (context resets) carrying the raw evidence bundle and the
previous body; escalation ladder identical to generate_skill_body.
previous body; retry ladder identical to generate_skill_body.
`reason_kind` labels the corrective context (`test`, `fidelity`, or
`run_failure`). The bundle is handed through as-is — the caller includes
requirements and the raw failure fields, never a paraphrase. A
@@ -1076,10 +1060,7 @@ def regenerate_skill_body(
attempt_evidence, reason_kind=reason_kind,
)
try:
raw = client.chat(
messages,
**(ESCALATED_SAMPLER if attempt > 1 else {}),
)
raw = client.chat(messages)
return parse_skill_body(raw)
except ValueError as exc:
last_error = exc
+5 -4
View File
@@ -47,7 +47,8 @@ class OpenCodeConsoleClient(OpenAICompatClient):
Pins the Console defaults: bearer auth, the Console base URL, a Console
label, and ``query_context = False`` (no ollama ``/api/show`` probe). The
endpoint subclasses below reuse it via cooperative multiple inheritance so
they also keep ``LLMClient``/``CodegenClient`` sampler defaults.
they also keep ``LLMClient``/``CodegenClient`` sampler parameters (opt-in:
none are sent unless configured).
A default ``User-Agent`` is always sent: the Console gateway rejects
urllib's default ``Python-urllib/<ver>`` with HTTP 403. Pass ``user_agent``
@@ -91,9 +92,9 @@ class OpenCodeConsoleClient(OpenAICompatClient):
class ConsoleLLMClient(OpenCodeConsoleClient, LLMClient):
"""Console-backed `llm` author (skill/category title + description).
Same conservative sampler defaults as ``LLMClient``; the Console transport
adds the bearer key and skips the ollama probe. Raises ``LLMError``
(unchanged contract).
Same opt-in sampler behavior as ``LLMClient`` (none sent unless configured);
the Console transport adds the bearer key and skips the ollama probe. Raises
``LLMError`` (unchanged contract).
``disable_thinking`` is forced **off**: `LLMClient` sends
``reasoning_effort: "none"`` (an ollama-compat knob) and the Console
+11 -9
View File
@@ -5,8 +5,8 @@ on the `llm` endpoint, deliberately separate from the larger `codegen` model
that writes runnable bodies. It uses the same provider machinery as
`CodegenClient` (`provider.OpenAICompatClient`): stdlib-only HTTP, a real SSE
stream, a token budget, and an idle watchdog — just with its own endpoint,
model, sampler defaults, and error type. `_parse_json` is also borrowed by the
authoring parsers.
model, sampler parameters, and error type. `_parse_json` is also borrowed by
the authoring parsers.
"""
from __future__ import annotations
@@ -23,9 +23,11 @@ class LLMError(ProviderError):
class LLMClient(OpenAICompatClient):
"""Small-model author of skill/category titles + descriptions.
Short JSON replies, so the defaults are conservative: low temperature, no
presence penalty, a modest timeout, and single-shot generation. Every value
is overridable from the `llm` block in `config.json`.
Short JSON replies, so the timeout is modest and generation is single-shot.
No sampler parameters are sent unless the `llm` block in `config.json` sets
them: an unset `temperature`/`top_p`/`presence_penalty`/`frequency_penalty`
is omitted so the server's model default applies. Every value is overridable
from config.
`disable_thinking` defaults **on**: the small local model is often a
reasoning model (e.g. `qwen3.5:4b`) whose hidden chain-of-thought consumes
@@ -57,10 +59,10 @@ class LLMClient(OpenAICompatClient):
degeneration_interval: int = 8000,
degeneration_window: int = 2000,
degeneration_min_chars: int = 4000,
temperature: float = 0.2,
top_p: float = 0.9,
presence_penalty: float = 0.0,
frequency_penalty: float = 0.0,
temperature: float | None = None,
top_p: float | None = None,
presence_penalty: float | None = None,
frequency_penalty: float | None = None,
disable_thinking: bool = True,
api_key: str = "",
extra_headers: dict[str, str] | None = None,
+23 -18
View File
@@ -4,9 +4,9 @@ Both the small title/description author (`LLMClient` in `llm.py`) and the big
skill-body writer (`CodegenClient` in `codegen.py`) use the same transport
machinery: stdlib-only HTTP, a real SSE stream, a layered token budget, an idle
watchdog, and an optional SemIf degeneration hook. This module holds that
provider logic once; subclasses set `base_url`/`model`, their sampler defaults,
and the error classes they raise so existing callers keep catching their own
types.
provider logic once; subclasses set `base_url`/`model`, their sampler
parameters, and the error classes they raise so existing callers keep catching
their own types.
Stdlib-only and imports nothing from the agent's own modules, so `codegen.py`
(which imports `skills.py`, which imports `llm.py`) can depend on it without a
@@ -49,7 +49,7 @@ class TokenBudget(NamedTuple):
class OpenAICompatClient:
"""OpenAI-compatible chat provider shared by the authoring clients.
Subclasses set `base_url`/`model` (and their sampler defaults) and the
Subclasses set `base_url`/`model` (and their sampler parameters) and the
error classes they raise: `error_class` for transport/parse/budget failures
and `degeneration_error_class` for a watchdog abort, so existing callers
keep catching their own types. `label` prefixes console diagnostics.
@@ -80,14 +80,13 @@ class OpenAICompatClient:
It lets a SemIf continue/stop decision cut off a generation that is
looping instead of converging, before it fills the context window.
Sampler defaults are the Qwen3.8 card's instruct-mode preset
(unsloth/Qwen3.8-27B-GGUF) used as an anti-repetition sampler, not to
toggle reasoning: a high `presence_penalty` is the loop cure, while the
prototype thinking-mode preset (`presence_penalty=0.0`) is what this
codegen model loops under. `temperature`/`top_p`/`presence_penalty`/
`frequency_penalty` are per-`chat` overridable; the `generate_skill_body`
escalation ladder bumps presence toward the card's max (2.0) and lowers
temperature on retries. `max_attempts` bounds that ladder (default 3).
Sampler parameters are **opt-in**: `temperature`/`top_p`/
`presence_penalty`/`frequency_penalty` default to `None` and a `None`
parameter is omitted from the request payload entirely, so the server's
model/Modelfile default applies. A caller that knows the right value for its
model sets it (constructor or per-`chat` override); this provider never
guesses a value on the user's behalf. `max_tokens` and `reasoning_effort`
work the same way: sent only when explicitly set.
`disable_thinking` sends `reasoning_effort: "none"` so a reasoning model
answers directly instead of spending the (short) reply budget on hidden
@@ -129,10 +128,10 @@ class OpenAICompatClient:
degeneration_interval: int = 8000,
degeneration_window: int = 2000,
degeneration_min_chars: int = 4000,
temperature: float = 0.7,
top_p: float = 0.85,
presence_penalty: float = 1.5,
frequency_penalty: float = 0.2,
temperature: float | None = None,
top_p: float | None = None,
presence_penalty: float | None = None,
frequency_penalty: float | None = None,
max_attempts: int = 3,
disable_thinking: bool = False,
api_key: str = "",
@@ -202,6 +201,13 @@ class OpenAICompatClient:
payload: dict = {
"model": self.model,
"messages": messages,
"stream": True,
"stream_options": {"include_usage": True},
}
# Sampler parameters are opt-in: a per-call override wins, otherwise the
# constructor value; a None value is omitted entirely so the server's
# model/Modelfile default applies.
sampler = {
"temperature": self.temperature if temperature is None else temperature,
"top_p": self.top_p if top_p is None else top_p,
"presence_penalty": (
@@ -210,9 +216,8 @@ class OpenAICompatClient:
"frequency_penalty": (
self.frequency_penalty if frequency_penalty is None else frequency_penalty
),
"stream": True,
"stream_options": {"include_usage": True},
}
payload.update({k: v for k, v in sampler.items() if v is not None})
if self.disable_thinking:
payload["reasoning_effort"] = "none"
if max_tokens is not None: