context + repl + config: per-class system_prompt override (closes #86)
Small local models follow precise structured instructions better than
natural language. Per-routing-class system_prompt override gives them
tighter instructions for THAT request while preserving ambient context.
Changes:
- Context:to_messages(opts) — opts.system_prompt_override REPLACES
the base system_prompt for THIS render only (state unchanged).
Dynamic blocks ([background], [project], [earlier summary], NORRIS
suffix) still compose on top. opts is optional; nil-safe for old
callers.
- repl.lua ask_ai — captures req_class from router.classify_model
(already returned by Phase 5; previously discarded after the
status line). Looks up config.routing.system_prompts[req_class];
passes as opts.system_prompt_override to ctx:to_messages each
iteration of the tool-sub-loop.
- Gating: override fires only when routing.auto is on (no class ->
no override). If system_prompts[class] absent for a class, fall
through to the default system_prompt (no surprise).
- Norris unaffected: safety.norris_step builds its own messages
array; doesn't go through this path.
- config.lua gains a commented-out example showing routing.system_
prompts with the code/default examples from the FR body.
Smoke verified:
- 12-case context.lua unit test: opts nil/absent/present, override
replaces base, dynamic blocks still compose, state unchanged
after call, Norris-mode coexistence (suffix still present;
background still suppressed).
- E2E against cloud broker with routing.system_prompts.code set:
triple-backtick prompt -> code class -> override fires; model
emits terse code-only output. Non-code prompt -> default class
-> no override -> normal verbose-ish reply.
Regression: test_safety 87/87, test_router_model 31/31, repl loads.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+20
@@ -240,6 +240,26 @@ return {
|
||||
-- -- Toggle at runtime with :fallback on / :fallback off.
|
||||
-- fallback = false, -- default off (cost-safety)
|
||||
-- fallback_model = "cloud",
|
||||
--
|
||||
-- -- Issue #86: per-class system_prompt override. When the
|
||||
-- -- classified request falls into a class with an entry here,
|
||||
-- -- the BASE system_prompt is REPLACED for that one request
|
||||
-- -- (dynamic blocks — [background], [project], [earlier
|
||||
-- -- summary], NORRIS suffix — still compose on top). Mostly
|
||||
-- -- useful for tightening small local models' instruction
|
||||
-- -- adherence. Default {} (no override).
|
||||
-- system_prompts = {
|
||||
-- code = [[You are a code assistant. Rules:
|
||||
-- 1. Output ONLY the requested code or command.
|
||||
-- 2. No prose explanation unless explicitly asked.
|
||||
-- 3. Wrap shell commands in CMD: prefix.
|
||||
-- 4. Max response: 200 tokens.]],
|
||||
-- default = [[You are a shell assistant.
|
||||
-- Output shell commands as: CMD: <command>
|
||||
-- Output answers as single short sentences.
|
||||
-- Do not ask clarifying questions.]],
|
||||
-- -- reasoning routes to cloud; no override usually needed
|
||||
-- },
|
||||
-- },
|
||||
|
||||
-- ── Phase 5 context summarization on sliding-window eviction.
|
||||
|
||||
Reference in New Issue
Block a user