remove reasoning from llm calls for title and description generation
This commit is contained in:
1 parent
50c83c61fd
commit
65c5899393
8 files changed
+84
-3
No files matched your search
+3
-1
@@ -14,4 +14,6 @@ config.json
|
||||
*.log
|
||||
# Machine-specific experiments/recipes (GPU offload probe, benchmark harness).
|
||||
# Deliberately not part of the shipped agent.
|
||||
local/
|
||||
local/
|
||||
*.egg-info/
|
||||
*.bak.*
|
||||
@@ -447,6 +447,21 @@ CLI, unit tests (24) + box integration tests (2).
|
||||
that model is pulled; `config.json` `llm.base_url` points here.
|
||||
- `bootstrap.sh` installs **no ollama**: it expects the target box to already
|
||||
run one for `llm` (and pulls `llm.model` into it), while codegen is remote.
|
||||
- **The local `llm` model is a reasoning model — thinking must be off.** The
|
||||
default `qwen3.5:4b` has ollama's `thinking` capability: it emits hidden
|
||||
chain-of-thought and puts the answer in `content`. Through the `/v1` compat
|
||||
endpoint the CoT consumes the entire reply budget, so
|
||||
`generate_category`/`generate_skill`'s `max_tokens=128` returns
|
||||
`finish_reason: length` with `content: ""` → `JSONDecodeError` and a traced
|
||||
`draft_failed` (no category/skill is ever authored — the whole create branch
|
||||
is silently dead). `LLMClient` now sends `reasoning_effort: "none"`
|
||||
(`llm.disable_thinking`, **default on**) so the model answers the ~30-token
|
||||
JSON directly (~2.5s). Ollama's native `think:false` is **not** plumbed
|
||||
through `/v1` (silently ignored), and `/no_think` in the prompt is ignored
|
||||
too; only `reasoning_effort` works there. Codegen *wants* the reasoning, so
|
||||
the knob is `llm`-only — `CodegenClient` never sets it. Unbounded (no
|
||||
`max_tokens`) does not help: the model loops on this prompt (2048 tokens of
|
||||
reasoning, still empty `content`, 3+ min).
|
||||
|
||||
### jarvis (staging)
|
||||
|
||||
|
||||
+3
-2
@@ -21,7 +21,7 @@
|
||||
"threads": 8
|
||||
},
|
||||
"llm": {
|
||||
"_comment": "Small OpenAI-compatible model that authors a new category/skill title + description (never the runnable body — that is `codegen` below). Deliberately its own endpoint/model, so it can be local and fast even when codegen is remote. Runs on THIS machine's local ollama; bootstrap sets base_url from --llm-url (default http://127.0.0.1:11434) and pulls `model` if it is missing. Uses the same provider machinery as codegen (real SSE stream, token budget, idle watchdog); short JSON replies, so the sampler defaults are conservative (low temperature, no presence penalty). The draft is authored asynchronously by a single-slot worker and the request re-runs when it lands; an unreachable endpoint is graceful (traced, user notified), not fatal.",
|
||||
"_comment": "Small OpenAI-compatible model that authors a new category/skill title + description (never the runnable body — that is `codegen` below). Deliberately its own endpoint/model, so it can be local and fast even when codegen is remote. Runs on THIS machine's local ollama; bootstrap sets base_url from --llm-url (default http://127.0.0.1:11434) and pulls `model` if it is missing. Uses the same provider machinery as codegen (real SSE stream, token budget, idle watchdog); short JSON replies, so the sampler defaults are conservative (low temperature, no presence penalty). The draft is authored asynchronously by a single-slot worker and the request re-runs when it lands; an unreachable endpoint is graceful (traced, user notified), not fatal. disable_thinking sends reasoning_effort:none so a reasoning model answers the short JSON directly instead of spending the reply budget on hidden chain-of-thought (set false only for an endpoint that rejects the parameter).",
|
||||
"base_url": "http://localhost:11434/v1",
|
||||
"model": "qwen3.5:4b",
|
||||
"timeout": 600,
|
||||
@@ -32,7 +32,8 @@
|
||||
"temperature": 0.2,
|
||||
"top_p": 0.9,
|
||||
"presence_penalty": 0.0,
|
||||
"frequency_penalty": 0.0
|
||||
"frequency_penalty": 0.0,
|
||||
"disable_thinking": true
|
||||
},
|
||||
"codegen": {
|
||||
"_comment": "OpenAI-compatible model that writes runnable skill bodies. Runs on a REMOTE ollama host (bootstrap sets base_url from --codegen-url, default guppy http://192.168.8.181:11434); the local small model is `llm` above. Bodies perform real actions against the user's configured services via stdlib transports, read every operational value from ctx.config, and declare their integration (INTEGRATION: service/transport/config_vars). Larger/slower than the decision or title/description model. The transport always streams so the client-side token budget (output cap / peak total fill) can abort a runaway in real time; stream only toggles console echo of tokens. timeout is total seconds; idle_warn/idle_timeout surface a silent (wedged) stream. The context window is auto-detected via ollama /api/show; context_window is the manual fallback (0 = auto/default 100000). smart_limit/warn_limit and max_fill_ratio/warn_fill_ratio bound total fill; max_output caps streamed output (>=1 absolute tokens, 0<x<1 fraction of window); chars_per_token converts chars to the token estimate. temperature/top_p/presence_penalty/frequency_penalty follow the Qwen3.8 model card's instruct-mode anti-repetition guidance (high presence_penalty, not greedy temperature); generate_skill_body escalates to presence 2.0 / temp 0.5 on retries (max_attempts attempts, fresh short prompt each time). elicitation asks the product owner implementation questions before the body is written (posted to the question queue; every front end defers). After the body lands it is reviewed for real-action fidelity, then the data contract (contract.json) is derived in a separate call, then skill.test.py (hermetic mechanics test: loopback http.server for HTTP bodies, fixtures inline, no external network) in a shared-context call, and the test is auto-run as a subprocess (test_timeout seconds); on failure a 3-option SemIf decision (code/contract/test) regenerates the failing piece, bounded by test_max_attempts. contract_search.enabled auto-populates the skill config.json via SemIf against the global + category config.",
|
||||
|
||||
Whitespace-only changes.
@@ -83,6 +83,7 @@ def build_scheduler(config: dict) -> tuple[Scheduler, dict]:
|
||||
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)),
|
||||
disable_thinking=bool(llm_cfg.get("disable_thinking", True)),
|
||||
)
|
||||
log = DecisionLog(config.get("log", "data/decisions.jsonl"))
|
||||
trace = TraceLog(config.get("trace", "data/runs.jsonl"))
|
||||
|
||||
@@ -26,6 +26,13 @@ class LLMClient(OpenAICompatClient):
|
||||
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`.
|
||||
|
||||
`disable_thinking` defaults **on**: the small local model is often a
|
||||
reasoning model (e.g. `qwen3.5:4b`) whose hidden chain-of-thought consumes
|
||||
the short reply budget and leaves `content` empty — the same cap problem
|
||||
codegen documents, but here the reply is a ~30-token JSON object, so the
|
||||
thinking is pure overhead. Set `llm.disable_thinking: false` for a
|
||||
non-reasoning endpoint that rejects the parameter.
|
||||
"""
|
||||
|
||||
error_class = LLMError
|
||||
@@ -54,6 +61,7 @@ class LLMClient(OpenAICompatClient):
|
||||
top_p: float = 0.9,
|
||||
presence_penalty: float = 0.0,
|
||||
frequency_penalty: float = 0.0,
|
||||
disable_thinking: bool = True,
|
||||
):
|
||||
super().__init__(
|
||||
base_url=base_url,
|
||||
@@ -76,6 +84,7 @@ class LLMClient(OpenAICompatClient):
|
||||
top_p=top_p,
|
||||
presence_penalty=presence_penalty,
|
||||
frequency_penalty=frequency_penalty,
|
||||
disable_thinking=disable_thinking,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -88,6 +88,13 @@ class OpenAICompatClient:
|
||||
`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).
|
||||
|
||||
`disable_thinking` sends `reasoning_effort: "none"` so a reasoning model
|
||||
answers directly instead of spending the (short) reply budget on hidden
|
||||
chain-of-thought. It is off by default because codegen *wants* the
|
||||
reasoning; the `llm` title/description author turns it on. Ollama honors it
|
||||
on the `/v1` compat endpoint (its native `think:false` is not plumbed
|
||||
through `/v1`).
|
||||
"""
|
||||
|
||||
error_class = ProviderError
|
||||
@@ -117,6 +124,7 @@ class OpenAICompatClient:
|
||||
presence_penalty: float = 1.5,
|
||||
frequency_penalty: float = 0.2,
|
||||
max_attempts: int = 3,
|
||||
disable_thinking: bool = False,
|
||||
):
|
||||
self.base_url = base_url.rstrip("/")
|
||||
self.model = model
|
||||
@@ -139,6 +147,7 @@ class OpenAICompatClient:
|
||||
self.presence_penalty = presence_penalty
|
||||
self.frequency_penalty = frequency_penalty
|
||||
self.max_attempts = max_attempts
|
||||
self.disable_thinking = disable_thinking
|
||||
self._window: int | None = None
|
||||
|
||||
def chat(
|
||||
@@ -169,6 +178,8 @@ class OpenAICompatClient:
|
||||
"stream": True,
|
||||
"stream_options": {"include_usage": True},
|
||||
}
|
||||
if self.disable_thinking:
|
||||
payload["reasoning_effort"] = "none"
|
||||
if max_tokens is not None:
|
||||
payload["max_tokens"] = max_tokens
|
||||
body = json.dumps(payload).encode("utf-8")
|
||||
|
||||
@@ -123,6 +123,48 @@ def test_generate_skill_via_provider():
|
||||
httpd.server_close()
|
||||
|
||||
|
||||
def test_llm_disables_thinking_by_default():
|
||||
"""The title/description author sends reasoning_effort:none so a reasoning
|
||||
model answers the short JSON directly (its CoT otherwise eats the 128-token
|
||||
reply budget and leaves `content` empty)."""
|
||||
httpd, base = _fake_server('{"title": "x", "description": "y"}')
|
||||
try:
|
||||
LLMClient(base_url=base, model="test", timeout=10).chat(
|
||||
[{"role": "user", "content": "name this"}]
|
||||
)
|
||||
assert httpd.RequestHandlerClass.received[0]["reasoning_effort"] == "none"
|
||||
finally:
|
||||
httpd.shutdown()
|
||||
httpd.server_close()
|
||||
|
||||
|
||||
def test_llm_thinking_can_be_re_enabled():
|
||||
httpd, base = _fake_server('{"title": "x", "description": "y"}')
|
||||
try:
|
||||
LLMClient(base_url=base, model="test", timeout=10, disable_thinking=False).chat(
|
||||
[{"role": "user", "content": "name this"}]
|
||||
)
|
||||
assert "reasoning_effort" not in httpd.RequestHandlerClass.received[0]
|
||||
finally:
|
||||
httpd.shutdown()
|
||||
httpd.server_close()
|
||||
|
||||
|
||||
def test_codegen_keeps_thinking():
|
||||
"""Codegen wants the chain-of-thought: the knob must not leak into it."""
|
||||
from semif_agent.codegen import CodegenClient
|
||||
|
||||
httpd, base = _fake_server("def predict(ctx, request):\n pass\n")
|
||||
try:
|
||||
CodegenClient(base_url=base, model="test", timeout=10).chat(
|
||||
[{"role": "user", "content": "write a body"}]
|
||||
)
|
||||
assert "reasoning_effort" not in httpd.RequestHandlerClass.received[0]
|
||||
finally:
|
||||
httpd.shutdown()
|
||||
httpd.server_close()
|
||||
|
||||
|
||||
def test_unreachable_endpoint_raises_llm_error():
|
||||
client = LLMClient(base_url="http://127.0.0.1:1/v1", model="test", timeout=2)
|
||||
with pytest.raises(LLMError):
|
||||
|
||||
Reference in new issue
Block a user