Ops bot: remember the last exchanges so follow-ups have context
Each message started a fresh claude -p with only the database snapshot, so «да, поправь» had nothing to refer to. Keep the last 6 exchanges (2 h, in memory, shared by Telegram and BroV) and put them into the prompt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -174,5 +174,26 @@ class Company(unittest.TestCase):
|
||||
os.remove(path)
|
||||
|
||||
|
||||
|
||||
class HistoryTest(unittest.TestCase):
|
||||
def test_follow_up_sees_previous_exchange(self):
|
||||
brain._history.clear()
|
||||
o = Ops(connect(":memory:"))
|
||||
seen = []
|
||||
def fake(prompt, *a, **k):
|
||||
seen.append(prompt)
|
||||
return '{"actions":[],"reply":"Ок"}'
|
||||
brain.ask_claude = fake
|
||||
brain.handle_text(o, "задача посмотреть бегущий по лезвию 2033", threading.Lock())
|
||||
brain.handle_text(o, "да, поправь", threading.Lock())
|
||||
self.assertNotIn("Недавний разговор", seen[0])
|
||||
self.assertIn("бегущий по лезвию 2033", seen[1])
|
||||
self.assertLess(seen[1].index("Недавний разговор"), seen[1].index("да, поправь"))
|
||||
|
||||
def test_old_history_expires(self):
|
||||
brain._history.clear()
|
||||
brain.remember("старое", "ответ", now=0)
|
||||
self.assertEqual(brain.history_text(now=brain.HISTORY_TTL + 1), "")
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user