Files
ModelHub XC c1ce9811bb 初始化项目,由ModelHub XC社区提供模型
Model: Xirui1208/selective-readtwice-7b-early-evaluated-20260928
Source: Original Platform
2026-11-17 05:18:17 +08:00

53 lines
2.9 KiB
Python

"""Complete memory updates that permit verbatim retention of useful old facts.
This is a separate ReadTwice protocol, not the original MemAgent protocol.
The original protocol module remains unchanged for existing checkpoints.
"""
from __future__ import annotations
from selective.protocol_readtwice import (
NO_MEMORY, KEEP_MEMORY, TEMPLATE_SKIM, TEMPLATE_FINAL,
TEMPLATE_UPDATE_READTWICE, TEMPLATE_UPDATE_SUMMARY,
)
PROTOCOL_KEEP = 'readtwice_conservative_keep_v1'
def templates(protocol: str):
if protocol != PROTOCOL_KEEP:
raise ValueError(f'Unknown memory update protocol: {protocol}')
old = ('The output is not an evidence delta and must not mechanically copy the old memory\n'
'and append a suffix. You may reorganize, rewrite, merge, deduplicate, and compress\n'
'facts while preserving every useful answer fact, entity identity, alias, number,\n'
'date, relation, and unresolved bridge.')
new = ('The output is the complete next memory, not an evidence delta. You may retain\n'
'the old wording verbatim and add useful new facts. Rephrasing is optional,\n'
'not required. Reorganize, merge, deduplicate, or compress only when useful,\n'
'while preserving every useful answer fact, entity identity, alias, number,\n'
'date, relation, and unresolved bridge.')
assert TEMPLATE_UPDATE_READTWICE.count(old) == 1
qa = TEMPLATE_UPDATE_READTWICE.replace(old, new)
qa = qa.replace('COMPLETE MEMORY REWRITE', 'COMPLETE MEMORY UPDATE')
qa = qa.replace('the rewritten complete memory body', 'the complete updated memory body')
summary = TEMPLATE_UPDATE_SUMMARY.replace('COMPLETE SUMMARY MEMORY REWRITE', 'COMPLETE SUMMARY MEMORY UPDATE')
summary = summary.replace('the rewritten complete memory body', 'the complete updated memory body')
summary = summary.replace('Maintain a complete compact summary of the target document while reading it in',
'You may retain old wording verbatim; rephrasing is optional, not required.\n'
'Maintain a complete compact summary of the target document while reading it in')
return qa, summary
def next_memory(previous: str, response: str, protocol: str) -> str:
"""Full replacement, with an optional explicit no-op branch."""
if protocol != PROTOCOL_KEEP:
raise ValueError(f'Unknown memory update protocol: {protocol}')
text = response.strip()
if protocol == PROTOCOL_KEEP and text.upper() == KEEP_MEMORY:
return previous
return text
def protocol_assets(protocol: str) -> dict:
qa, summary = templates(protocol)
return {'id': protocol, 'qa_update_template': qa, 'summary_update_template': summary,
'keep_marker': KEEP_MEMORY, 'keep_preserves_previous_memory': True,
'other_output_replaces_entire_memory': True, 'memory_token_limit': 1024,
'compulsory_rephrasing': False, 'original_memagent_protocol': False}