Every injected prompt becomes editable, and several get written
The instructions LLeMbas puts in front of a model were hard-coded: six
strings in a GUIDANCE dict, two headings, and the title request inline in
chat.py. An operator could not see what was being sent, let alone change
it, and there was nowhere for a custom tool to contribute its own guidance
when custom tools land.
services/prompts.py now holds each piece as a Fragment, and /admin/prompts
edits them with a preview of the whole assembled system message including
unsaved edits. harness.py keeps only the decisions -- which fragments apply
to this request, and what their variables resolve to.
The design turns on one choice: a fragment carries its gate as data
(families, requires, when_tools) rather than as a callable, because a
database row can carry the same three fields. Custom tools will therefore
register a fragment source and change nothing else -- there is a test that
says exactly that, and it is the reason the rest of the shape is what it is.
Consequences worth knowing:
- Defaults live in code, overrides in the database, and text equal to its
default is never stored. Otherwise pressing Save once would freeze
today's wording forever and no later release could improve it.
- An empty override means off. A fragment that was not submitted at all
keeps what it had, because it may be missing from the page only because
whatever contributes it is currently switched off.
- requires= replaced the hand-written pair of memory guidance variants.
The sentence that refers to a section now lives inside that section, so
it cannot outlive it. That was the general problem the pair was a
special case of.
- {{name}}, with anything unrecognised passing through verbatim. The name
grammar is the guard: {"total": 1} and ${PATH} are not candidates.
Substitution is one pass and never recursive, because {{memories}}
carries text a model wrote.
The wording is also overhauled, and a model now gets the core fragments
even with no tools -- the date above all. "An empty harness is worse than
none" was about tokens that say nothing; a model with no clock being asked
about the present is not that. Clearing those boxes restores the old
silence exactly. New: today's date, who it is talking to, the three-round
tool budget, that tool results are not replayed, that anything a tool
returns is data rather than instruction, and what the <document> wrapper
around an attachment is. Extended: memory_forget, notes_edit/delete,
skill_create/edit, and reading a knowledge document in full rather than
answering from an extract.
Tool descriptions stay in code and are listed read-only. They are schema
and they state facts about what a runner does; an edit would make the text
a lie with nothing to catch it.
No schema change -- one JSON row in the settings table.
488 tests. Version 0.2.0, which also invalidates the service worker cache
so the green artwork appears without a hard reload.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,7 @@ from lembas.db.models import Setting
|
||||
GENERAL = "general"
|
||||
AUDIO = "audio"
|
||||
SEARCH = "search"
|
||||
PROMPTS = "prompts"
|
||||
|
||||
|
||||
def _general_defaults() -> dict[str, Any]:
|
||||
@@ -84,10 +85,26 @@ def _search_defaults() -> dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
def _prompts_defaults() -> dict[str, Any]:
|
||||
"""Deliberately carries no prompt text.
|
||||
|
||||
The default wording of every fragment lives in ``services/prompts.py``, and
|
||||
only an administrator's *override* is stored here. That is what lets a later
|
||||
release improve a default and have the improvement reach every instance that
|
||||
never touched that fragment -- copying the defaults in here at first save
|
||||
would freeze them forever.
|
||||
"""
|
||||
return {
|
||||
# 0 means "use services.harness.MAX_HARNESS_CHARS".
|
||||
"max_harness_chars": 0,
|
||||
}
|
||||
|
||||
|
||||
_DEFAULTS: dict[str, Any] = {
|
||||
GENERAL: _general_defaults,
|
||||
AUDIO: _audio_defaults,
|
||||
SEARCH: _search_defaults,
|
||||
PROMPTS: _prompts_defaults,
|
||||
}
|
||||
|
||||
|
||||
@@ -124,6 +141,24 @@ def update(db: DBSession, changes: dict[str, Any], *, key: str = GENERAL) -> dic
|
||||
return get_group(db, key)
|
||||
|
||||
|
||||
def replace(db: DBSession, values: dict[str, Any], *, key: str = GENERAL) -> dict[str, Any]:
|
||||
"""Set a settings group to exactly these values, dropping anything absent.
|
||||
|
||||
`update` merges, which is right for a form that posts a fixed set of fields
|
||||
and wrong for one whose fields come and go -- the prompt editor stores only
|
||||
the fragments an administrator has actually changed, so "no longer present"
|
||||
has to mean "no longer stored". There is no other way to delete a key.
|
||||
"""
|
||||
row = db.get(Setting, key)
|
||||
if row is None:
|
||||
row = Setting(key=key, value={})
|
||||
db.add(row)
|
||||
|
||||
row.value = dict(values)
|
||||
db.commit()
|
||||
return get_group(db, key)
|
||||
|
||||
|
||||
def signup_allowed(db: DBSession) -> bool:
|
||||
return bool(get(db, "allow_signup"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user