Improve seeing and memory answers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-26 06:58:10 +09:00
co-authored by Claude Opus 5.5
parent 9085235edf
commit 284638a22d
6 changed files with 323 additions and 88 deletions
+40 -5
View File
@@ -41,6 +41,37 @@ def _vec(text):
return _vecs[text]
KO_CACHE = ROOT / "logs" / "memory_check_ko.json" # title -> Korean title / summary (local: made from the sets)
_ko = {}
def _korean(title, summary):
"""The Korean title and summary a live talk carries (memory.summarise asks the LLM for both): made once per talk by
the LLM and kept in KO_CACHE, so the rules-only runs need no LLM after the first."""
key = f"{title}|{summary}"
if not _ko and KO_CACHE.exists():
_ko.update(json.loads(KO_CACHE.read_text()))
if key not in _ko:
from assistant import brain
out = json.loads(brain._chat([{"role": "system", "content": "Translate this robot's memory of a talk into Korean "
"as JSON: {\"title_ko\": \"<the title, 1-4 Korean words>\", \"summary_ko\": \"<the "
"summary in polite Korean (-요)>\"}. Names of people, robots and companies as they are "
"said in Korean (JAKA = 자카)."},
{"role": "user", "content": f"title: {title}\nsummary: {summary}"}],
{"type": "object", "properties": {"title_ko": {"type": "string"}, "summary_ko": {"type": "string"}},
"required": ["title_ko", "summary_ko"]}))
_ko[key] = {"title_ko": out["title_ko"].strip(), "summary_ko": out["summary_ko"].strip()}
KO_CACHE.write_text(json.dumps(_ko, ensure_ascii=False, indent=0))
return _ko[key]
def _talk(t):
ko = _korean(t["title"], t["summary"])
return {"t": epoch(t["when"]), "title": t["title"], "summary": t["summary"], "facts": t.get("facts", []),
"commands": t.get("commands", []), "person": t.get("person"), **ko,
"vec": _vec(f"{t['title']}. {t['summary']}"), "vec_ko": _vec(f"{ko['title_ko']}. {ko['summary_ko']}")}
def load(d):
"""The dialogue's memory into assistant/memory.py: a new temp folder, its clock, its self state."""
mem, now = d["memory"], epoch(d["now"])
@@ -48,9 +79,7 @@ def load(d):
memory.clock = lambda: now
memory._recall.update(offered=[], left=[], talk=None, listed=[], at=0.0)
memory._talk.update(name=None, track=mem.get("forget_person"), skip=False) # who talks now (the forget's person)
memory._save("talks", [{"t": epoch(t["when"]), "title": t["title"], "summary": t["summary"],
"facts": t.get("facts", []), "commands": t.get("commands", []), "person": t.get("person"),
"vec": _vec(f"{t['title']}. {t['summary']}")} for t in mem.get("talks", [])])
memory._save("talks", [_talk(t) for t in mem.get("talks", [])])
memory._save("seen", [{"t": epoch(s["when"]), "name": memory._object(s["object"]) or s["object"],
"colour": s.get("colour"), "where": s.get("where")} for s in mem.get("seen", [])])
st = mem.get("self") or {}
@@ -90,7 +119,12 @@ def score_memory(d, old, use_llm):
"""One memory dialogue -> blind_check rows (the dialogue scorer with the memory loaded and asked first)."""
load(d)
with mock.patch.object(blind_check, "turn_route", _route(blind_check.turn_route, d)):
return blind_check.score_dialogue(d, old, use_llm)
rows = blind_check.score_dialogue(d, old, use_llm)
for r in rows: # "what's my name?" wanting the name from a talk with another person: the check can't say who
if r["verdict"] == "wrong" and "(told in the talk about" in r["show"] and \
any(n[:20] in r["show"] for n in memory.NO_NAME.values()):
r["verdict"] = "who?" # the visitor is not known (re-id): not scored
return rows
def main(args):
@@ -117,7 +151,8 @@ def main(args):
by_tag[tag][r["verdict"]] += 1
lines = [f"# memory_dialogues {rnd} {split} ({'LLM' if use_llm else 'rules only'}, {time.time() - t0:.0f} s)", "",
f"right {kinds['right']} / {len(scored)}; wrong {kinds['wrong']}, motion {kinds['motion']}, "
f"llm? {kinds['llm?']}, error {kinds['error']}", "", "| case kind | right | wrong | llm? |", "|---|---|---|---|"]
f"llm? {kinds['llm?']}, error {kinds['error']}, who? {kinds['who?']} (the visitor's name from a talk the "
f"check can't tie to them)", "", "| case kind | right | wrong | llm? |", "|---|---|---|---|"]
lines += [f"| {t} | {c['right']} | {c['wrong'] + c['motion'] + c['error']} | {c['llm?']} |" for t, c in sorted(by_tag.items())]
lines += ["", "## Wrong", ""] + [f"- d{r['dialogue']} {r['show'][:400]}" for r in scored
if r["verdict"] in ("wrong", "motion", "error")]
+3 -3
View File
@@ -119,7 +119,7 @@ assert ask("no") == "Or was it our talk about weather in Busan today at about 2
assert ask("no") == "I can't remember that."
assert ask("remember what we said about battery?") == "I can't remember that." # only past 48 h
assert ask("do you remember our talk last week?") == "I only remember the last two days."
assert ask("what did we talk about yesterday?") == "Do you mean our talk about birds yesterday at about 4 pm?"
assert ask("what did we talk about yesterday?") == "Yesterday we talked about birds at about 4 pm. Would you like to hear more?"
assert ask("yeah, that one") .startswith("Yes, I remember.")
assert ask("기억나? 어제 새 얘기 했던 거", "ko") == "어제 오후 4시쯤에 새에 대해 이야기한 거 말씀이세요?"
assert ask("네", "ko") == "네, 기억나요. 한국의 새에 대해 이야기했어요."
@@ -151,7 +151,7 @@ assert ask("오늘 하기로 한 거 해.", "ko").startswith("어제 오후 3시
assert ask("time to do what we planned") .startswith("Yesterday at about 3 pm we agreed")
assert "agreed" not in (ask("don't do what we said") or "")
memory._recall.update(offered=[], talk=None, listed=[])
assert ask("그저께 얘기한 거 기억나?", "ko") == "저는 최근 이틀 동안의 일만 기억해요."
assert ask("그저께 얘기한 거 기억나?", "ko") == "그건 기억이 안 나요." # none that day (within 48 h)
for q in ["remember to bring the cup", "I don't remember", "please remember my name", "기억해 줘", "how are you?",
"what is the weather?", "I remember when I was a kid", "last time I was here it was cold", "do you remember me?",
"지난번에 왔을 때 추웠어요"]:
@@ -228,7 +228,7 @@ for q in ["open your hand", "손 펴", "손 펴 줘", "give me your hand", "clos
assert memory.reply("hand open or close?", "en", NOW).endswith("I'm holding the red cup.")
memory._state.update(place="p3", lift=0.0)
assert memory.reply("where are you?", "en", NOW) == "I'm at p3 right now."
assert memory.reply("지금 어디야?", "ko", NOW) == "지금 p3에 있어요."
assert memory.reply("지금 어디야?", "ko", NOW) == "지금 p3 근처에 있어요."
assert memory.reply("where are you going?", "en", NOW) is None and memory.reply("where are you from?", "en", NOW) is None
assert memory.reply("지금 몸 얼마나 올라가 있어?", "ko", NOW) == "리프트는 맨 아래에 있어요. 몸을 올리지 않은 상태예요."
memory._state.update(lift=75.0)
+2 -2
View File
@@ -66,7 +66,7 @@ p = scene.person_in_front(f)
assert p and p["where"] == "on my right" and p["facing"] is False, p
assert p["clothes"] == {"upper": "white", "lower": "blue", "feet": None}, p["clothes"] # ankle below the frame
assert say("What is it? Color my jeans.", f) == "Your jeans look blue." # 2026-10-21 live
assert say("내가 뭐 입고 있어?", f, "ko") == "흰색 상의에 파란색 바지를 입고 계세요. 신발은 여기서 안 보여요."
assert say("내가 뭐 입고 있어?", f, "ko") == "흰색 상의에 파란색 바지를 입고 계세요."
assert scene.person_holds(None, f) is not True, "no detected thing in his hands: never claim one"
# ---------- a man with his back to the torso camera, a clear plastic cup in his hand (not detectable) ----------
@@ -74,7 +74,7 @@ f = fx("holding_cup_back")
p = scene.person_in_front(f)
assert p and p["clothes"]["upper"] == "light blue" and p["pointing"] is None and p["facing"] is False, p
assert scene.object_in_hand(f) is None and scene.person_holds("cup", f) is None # depth stale: can't tell
assert say("what am I wearing?", f) == "You're wearing a light blue top and black trousers. I can't see your shoes from here."
assert say("what am I wearing?", f) == "You're wearing a light blue top and black trousers."
# the trousers are near black (V ~48): no hue there (2026-10-22 live: "blue")
assert say("is my shirt really white?", f).startswith("To my camera") # light blue or white: says both may be true
+3 -3
View File
@@ -51,7 +51,7 @@ CASES = [ # (question, regex the answer must match; None: not a seeing questio
("Lumi, am I wearing a hat?", r"^Yes.*black cap"),
("what colour is my cap?", r"black cap"),
("do I have a bag?", r"^Yes.*blue backpack"),
("am I wearing a mask?", r"^No, I don't see a mask"),
("am I wearing a mask?", r"^No, you don't have a mask on"),
("what colour is my hair?", r"hair looks brown"),
("is my hair short?", r"^No, your hair looks long"),
("is my hair long?", r"^Yes, your hair looks long"),
@@ -71,7 +71,7 @@ CASES = [ # (question, regex the answer must match; None: not a seeing questio
("안경 쓰셨나요?", r"^네, 안경을"),
("모자 쓰고 있어요?", r"검은색 모자를 쓰고"),
("가방 메고 있습니까?", r"파란색 백팩을 메고"),
("마스크 썼어?", r"^아니요, 마스크는 안 보여요"),
("마스크 썼어?", r"^아니요, 마스크는 안 쓰고 계세요"),
("내 머리 무슨 색이야?", r"갈색 머리"),
("머리 길어?", r"^네, 머리가 길어"),
("제 머리 짧아요?", r"^아니요, 머리가 길어"),
@@ -128,7 +128,7 @@ assert re.search(r"I looked again\. No, you're not wearing glasses", ask("are yo
setup(me={**ME, "glasses": None, "hat": None, "bag": {"kind": "handbag", "colour": "red"}})
seeing._last.update(kind=None, asked=None)
assert re.search(r"can't see your face", ask("am I wearing glasses?"))
assert re.search(r"^No, I don't see a hat", ask("am I wearing a hat?"))
assert re.search(r"^No, you don't have a hat on", ask("am I wearing a hat?"))
assert re.search(r"red handbag", ask("do I have a bag?"))
assert re.search(r"빨간색 핸드백", ask("가방 메고 있어요?"))