fix(reply): known user location reaches getWeather; retries are not blocked by the previous reply

- Drop the engine's deterministic Korean weather shortcut. It bypassed the
  chat model and the tool runner, so a location the user had stated could
  never be used. The tool already returns one clean Korean sentence.
- getWeather and the tool-argument prompts pass the place the user has
  said they are (conversation or memory) and leave the argument empty
  otherwise, so the detected location is not copied into it.
- getWeather retries a "district, city, country" name with its leading
  parts dropped when the geocoder finds nothing.
- The planner gets the live time/location line and plans
  searchMemory topic='where the user lives' only when the location is
  unknown or disabled.
- The per-reply repeat guard counts only this reply's tool messages, so
  calls carried over from the previous reply no longer block a retry the
  user asks for.
- Memory extractor: the context block sits after the examples and the
  no-location example uses a different query, so a location already in
  context is not asked for again. New counterpart eval checks that it is
  still asked for when the context has none.
- Tool retry eval fails every call in turn 1, so a model that retries by
  itself inside turn 1 still exercises the user's "try again".
- Specs (planner, reply), docs/llm_contexts.md and the roadmap updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-11 21:55:45 +09:00
parent 4bb3895ca0
commit 3ec430fd25
15 changed files with 255 additions and 79 deletions

View File

@@ -180,10 +180,17 @@ _PROMPT_TEMPLATE = (
"preferences and dietary restrictions'; 'suggest something I'd "
"enjoy watching' → searchMemory topic='user viewing tastes'. "
"NO-examples (DO NOT emit searchMemory): 'who is Britney Spears', "
"'what is the capital of France', 'what's the weather today', "
"'what is the capital of France', 'what's the weather today' "
"(when LIVE CONTEXT gives the location), "
"'search the web for Possessor 2020'. If no prior-conversation "
"memory is needed, OMIT this step entirely — every extra "
"searchMemory directive costs a real LLM call.\n"
"2b. A tool step that depends on a fact about the user themself "
"(where they are, for weather or local results) also needs memory "
"FIRST when neither LIVE CONTEXT nor DIALOGUE CONTEXT gives that "
"fact, e.g. LIVE CONTEXT says 'Location: Unknown' or 'Location: "
"Disabled': emit `searchMemory topic='where the user lives'` before "
"the tool step. When LIVE CONTEXT gives a location, do not.\n"
"3. Use external tools ONLY from the AVAILABLE TOOLS list below, "
"by exact name. If no tool is needed (greeting, small-talk, "
"opinion, a question about yourself, a fact already in the "
@@ -257,6 +264,7 @@ def _build_user_message(
query: str,
dialogue_context: str,
tools: Sequence[Tuple[str, str]],
live_context: str = "",
) -> str:
parts = []
if tools:
@@ -264,6 +272,8 @@ def _build_user_message(
parts.append(f"AVAILABLE TOOLS:\n{tool_lines}")
else:
parts.append("AVAILABLE TOOLS: (none — plan a direct reply)")
if live_context.strip():
parts.append(f"LIVE CONTEXT: {live_context.strip()}")
if dialogue_context.strip():
parts.append(f"DIALOGUE CONTEXT (most recent last):\n{dialogue_context.strip()}")
else:
@@ -445,6 +455,7 @@ def plan_query(
*,
timeout_sec: Optional[float] = None,
memory_context: str = "", # deprecated; planner now runs before memory
live_context: str = "",
) -> List[str]:
"""Run a short planning LLM pass over the query + dialogue context.
@@ -454,6 +465,10 @@ def plan_query(
A single ``["Reply to the user."]`` is a valid plan and means
"answer directly; skip both memory and tools".
``live_context`` is the engine's live time/location line. It lets the
planner tell a known location from an unknown one, and plan a memory
lookup for where the user is only in the second case.
``memory_context`` is accepted for backward compatibility with old
callers but no longer used: the planner runs before memory search
so it decides *whether* memory is needed, via the searchMemory
@@ -478,7 +493,7 @@ def plan_query(
)
system_prompt = _PROMPT_TEMPLATE.format(max_steps=MAX_STEPS)
user_content = _build_user_message(query, dialogue_context, tools)
user_content = _build_user_message(query, dialogue_context, tools, live_context)
try:
raw = call_llm_direct(