diff options
Diffstat (limited to 'assistant.py')
| -rw-r--r-- | assistant.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/assistant.py b/assistant.py index 991dfa0..2a84cd6 100644 --- a/assistant.py +++ b/assistant.py @@ -548,15 +548,17 @@ def reply(history, q, mine): log(f"you ({lang}, {time.perf_counter() - t:.2f}s): {text}") emit({"type": "state", "state": "thinking"}) question = {"role": "user", "content": text} - # ponytail: last 20 messages, summarise if long sessions need memory # The model has no clock: without the date it makes one up for tools. # Also stamped on the question itself, which history does not keep: with # the time only in the system prompt, "what time is it?" asked again an # hour later copied the old answer from history. Stamping every message # in history fixed that but lost tool arguments (account filter 0/6). now = time.strftime("%A %d %B %Y, %H:%M") - msgs = ([{"role": "system", "content": f"{CFG['system']} It is {now}."}] + history[-20:] + # ponytail: last 10 turns, summarise if long sessions need memory + msgs = ([{"role": "system", "content": f"{CFG['system']} It is {now}."}] + + [m for past in history[-10:] for m in past] + [{"role": "user", "content": f"[{now}] {text}"}]) + first = len(msgs) # this turn's tool messages start here t, said, voice, announced = time.perf_counter(), [], lang, False def say(s): @@ -607,9 +609,15 @@ def reply(history, q, mine): log("interrupted") return q.put((mine, None)) - # Tool calls stay inside the turn: history keeps only what was said. A cut - # off exchange is dropped whole, so user and assistant still alternate. - history += [question, {"role": "assistant", "content": " ".join(said)}] + # History keeps the tool calls: with only what was said, the model saw + # facts answered without tools and invented the next ones (no tool call + # 9/10 on a replayed session, 0/10 with the calls kept). Results are + # replaced by a placeholder, for context: same 10/10, and a follow-up on + # an old result calls the tool again (10/10). A cut off exchange is + # dropped whole, so user and assistant still alternate. + past = [{**m, "content": "(shown to the user at the time)"} if m["role"] == "tool" else m + for m in msgs[first:]] + history.append([question] + past + [{"role": "assistant", "content": " ".join(said)}]) log("assistant:", " ".join(said)) |
