Add LLMService.append_system_instruction()

Composes durable text onto a user-provided system instruction (alongside the
turn-completion and async-tool-cancellation addons) so it is prepended on every
inference and survives context-message resets. The user's base prompt is now
snapshotted once and the effective instruction is always rebuilt from it,
replacing the prior lazy capture/restore logic with a single invariant.
This commit is contained in:
Mark Backman
2026-05-21 16:51:13 -04:00
parent e8ec7c585f
commit ee3d1128ec
4 changed files with 126 additions and 29 deletions

View File

@@ -224,7 +224,10 @@ class TestSystemInstructionComposition(unittest.IsolatedAsyncioTestCase):
# Disable
await service._update_settings(LLMSettings(filter_incomplete_user_turns=False))
self.assertEqual(service._settings.system_instruction, "You are a helpful assistant.")
self.assertIsNone(service._base_system_instruction)
# The base prompt is retained — it's the single source of truth that
# composition rebuilds from; disabling just recomposes without the
# turn-completion addon.
self.assertEqual(service._base_system_instruction, "You are a helpful assistant.")
async def test_disable_turn_completion_restores_none(self):
"""Disabling turn completion when original was None should restore None."""