mirror of
https://github.com/NCBM/plyngent.git
synced 2026-07-25 08:04:57 +08:00
core/agent: shift persist_from when prepending system prompt
This commit is contained in:
@@ -210,9 +210,9 @@ class ChatAgent:
|
||||
if self.messages and isinstance(self.messages[0], SystemChatMessage):
|
||||
return
|
||||
self.messages.insert(0, SystemChatMessage(content=self.system_prompt))
|
||||
# System inject is not a DB message unless already stored.
|
||||
if self._persist_from == 0:
|
||||
self._persist_from = 1
|
||||
# Prepended system is local-only; shift the checkpoint so indices that
|
||||
# already pointed past stored messages stay correct after insert.
|
||||
self._persist_from = min(len(self.messages), self._persist_from + 1)
|
||||
|
||||
def replace_messages(
|
||||
self,
|
||||
|
||||
@@ -152,10 +152,15 @@ async def test_rebuild_client_preserves_persist_cursor(tmp_path: Path) -> None:
|
||||
[UserChatMessage(content="hi"), AssistantChatMessage(content="yo")],
|
||||
persisted=True,
|
||||
)
|
||||
assert state.agent.persist_from == 2
|
||||
# Default system prompt is prepended locally (not a DB row); checkpoint
|
||||
# shifts so the two stored turns stay in the persisted prefix.
|
||||
n_msgs = len(state.agent.messages)
|
||||
assert n_msgs >= 2
|
||||
assert state.agent.persist_from == n_msgs
|
||||
cursor = state.agent.persist_from
|
||||
state.rebuild_client()
|
||||
assert len(state.agent.messages) == 2
|
||||
assert state.agent.persist_from == 2
|
||||
assert len(state.agent.messages) == n_msgs
|
||||
assert state.agent.persist_from == cursor
|
||||
finally:
|
||||
await memory.close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user