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:
+46
-2
@@ -2,6 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
@@ -131,6 +133,44 @@ def test_fallback_title_of_nothing():
|
||||
assert chat_service.fallback_title(" ") == "New chat"
|
||||
|
||||
|
||||
async def test_the_title_prompt_carries_the_exchange(mock_http):
|
||||
"""The wording is a fragment an administrator can edit, so what reaches the
|
||||
endpoint has to be the substituted text, not the template."""
|
||||
seen: list[str] = []
|
||||
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
seen.append(json.loads(request.content)["messages"][0]["content"])
|
||||
return httpx.Response(200, json={"choices": [{"message": {"content": "A short name"}}]})
|
||||
|
||||
mock_http(handler)
|
||||
endpoint = Endpoint("http://x.test", "", {})
|
||||
title = await chat_service.generate_title(
|
||||
endpoint,
|
||||
"m",
|
||||
"What is lembas?",
|
||||
"Waybread.",
|
||||
template="Name this: {{question}} / {{answer}} / {{nonsense}}",
|
||||
)
|
||||
|
||||
assert title == "A short name"
|
||||
assert seen == ["Name this: What is lembas? / Waybread. / {{nonsense}}"]
|
||||
|
||||
|
||||
async def test_an_empty_title_prompt_asks_no_model_at_all(mock_http):
|
||||
"""Clearing the fragment is how auto-titling is turned off. It must not
|
||||
cost a request that is then thrown away."""
|
||||
|
||||
def handler(request: httpx.Request) -> httpx.Response: # pragma: no cover - must not run
|
||||
raise AssertionError("the endpoint was contacted")
|
||||
|
||||
mock_http(handler)
|
||||
endpoint = Endpoint("http://x.test", "", {})
|
||||
title = await chat_service.generate_title(
|
||||
endpoint, "m", "What is lembas?", "Waybread.", template=" "
|
||||
)
|
||||
assert title == "What is lembas?"
|
||||
|
||||
|
||||
# --- Chats and folders (through the API) -------------------------------------
|
||||
def _add_connection(db) -> Connection:
|
||||
# Port 1 refuses connections, which is what the error-path test relies on.
|
||||
@@ -316,7 +356,8 @@ def test_history_skips_failed_and_empty_turns(db, user_id):
|
||||
)
|
||||
db.commit()
|
||||
|
||||
contents = [m["content"] for m in chat_service.build_request(db, chat)["messages"]]
|
||||
messages = chat_service.build_request(db, chat)["messages"]
|
||||
contents = [m["content"] for m in messages if m["role"] != "system"]
|
||||
assert contents == ["one", "two"]
|
||||
|
||||
|
||||
@@ -332,7 +373,10 @@ def test_system_prompt_leads_the_message_list(db, user_id):
|
||||
db.commit()
|
||||
|
||||
messages = chat_service.build_request(db, chat)["messages"]
|
||||
assert messages[0] == {"role": "system", "content": "You are terse."}
|
||||
assert messages[0]["role"] == "system"
|
||||
# The harness precedes it inside the same message; the authored prompt is
|
||||
# last, where it is closest to the conversation.
|
||||
assert messages[0]["content"].endswith("You are terse.")
|
||||
|
||||
|
||||
def test_streaming_reports_an_unreachable_endpoint_in_the_thread(
|
||||
|
||||
Reference in New Issue
Block a user