From 613648096e01c283f03365b7e0a8cbf72e9bf766 Mon Sep 17 00:00:00 2001 From: kim Date: Fri, 23 Oct 2026 18:14:20 +0900 Subject: [PATCH] =?UTF-8?q?=EB=89=B4=EC=8A=A4=20=ED=91=9C=EC=97=90=20?= =?UTF-8?q?=EB=82=98=EC=98=A8=20=EC=9D=B8=EB=AC=BC=EC=9D=84=20=EB=AC=BB?= =?UTF-8?q?=EB=8A=94=20=ED=9B=84=EC=86=8D=20=EC=A7=88=EB=AC=B8=EC=9D=80=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20=EA=B0=95=EC=A0=9C(isNewsEntityFollowUp)?= =?UTF-8?q?=20=E2=80=94=20=EC=A7=81=EC=A0=84=20=EB=8B=B5=EC=9D=B4=20?= =?UTF-8?q?=EB=89=B4=EC=8A=A4=20=ED=91=9C=EC=9D=B4=EA=B3=A0=20=EB=AC=BC?= =?UTF-8?q?=EC=9D=80=20=EC=9D=B4=EB=A6=84=EC=9D=B4=20=EA=B7=B8=20=ED=91=9C?= =?UTF-8?q?=EC=97=90=20=EC=9E=88=EC=9D=84=20=EB=95=8C=EB=A7=8C.=20'?= =?UTF-8?q?=EB=AC=B4=EB=9D=BC=EC=B9=B4=EB=AF=B8=20=EB=A5=98=20=EB=88=84?= =?UTF-8?q?=EA=B5=AC=EC=A7=80=3F'=EC=97=90=20Haiku=EA=B0=80=20=EA=B8=B0?= =?UTF-8?q?=EC=96=B5=EC=9C=BC=EB=A1=9C=20=EB=8B=B5=ED=95=B4=20=EB=8D=B0?= =?UTF-8?q?=EB=B7=94=EC=9E=91=20=EC=A0=9C=EB=AA=A9=EC=9D=84=20=EC=A7=80?= =?UTF-8?q?=EC=96=B4=EB=82=B4=EA=B3=A0=20=EB=AC=B4=EA=B4=80=ED=95=9C=20JSA?= =?UTF-8?q?=EB=A5=BC=20=EB=81=8C=EC=96=B4=EC=98=B4.=20=EC=9D=B8=EB=AC=BC?= =?UTF-8?q?=20=EC=A7=88=EB=AC=B8=20=EC=A0=84=EC=B2=B4=EB=8A=94=20=EC=95=88?= =?UTF-8?q?=20=EA=B1=B4=EB=93=9C=EB=A6=BC(=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EA=B2=B0=EC=A0=95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- src/gateway/chat/claude-nudge-adapt.ts | 1 + src/gateway/chat/handle-chat.ts | 11 ++++++++++- src/gateway/guards/prompt-gates.ts | 21 +++++++++++++++++++++ tests/prompt-gates.test.ts | 14 ++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/gateway/chat/claude-nudge-adapt.ts b/src/gateway/chat/claude-nudge-adapt.ts index 330cd38..e3ec1b5 100644 --- a/src/gateway/chat/claude-nudge-adapt.ts +++ b/src/gateway/chat/claude-nudge-adapt.ts @@ -14,6 +14,7 @@ export const SYNTHETIC_ACKS: ReadonlySet = new Set([ 'Got it — checking now.', 'Got it — let me verify that first.', + 'Got it — let me look that up.', 'Understood.', 'Understood. Acting immediately.', 'Let me check that now.', diff --git a/src/gateway/chat/handle-chat.ts b/src/gateway/chat/handle-chat.ts index 57958b5..35eda80 100644 --- a/src/gateway/chat/handle-chat.ts +++ b/src/gateway/chat/handle-chat.ts @@ -13,6 +13,7 @@ import { isLiveDataRequest, isFactualInfoRequest, isFactualThreadFollowUp, + isNewsEntityFollowUp, confirmsUserGuessWithoutGrounding, looksLikeUnverifiedSpecClaim, isExemptFromVerification, @@ -920,6 +921,7 @@ async function handleChat( // wasted first generation — see the AUTO-RECOVER fallback below) so the model calls the // tool on round 0 instead of burning a full generation on a fabricated answer that then // gets discarded and retried. + const newsEntityFollowUp = isNewsEntityFollowUp(message, String([...history].reverse().find(h => h.role !== 'user')?.content || '')); if (isLiveDataRequest(message)) { // "뉴스" alone means general current-events news — it must not get resolved into // whatever topic happens to be freshest in the conversation history (observed: a bare @@ -967,6 +969,13 @@ async function handleChat( // 주제어가 앞 턴에 있고 이번 턴엔 명사구만 남은 후속 질문("올라마 클라우드 모델은?")도 같은 // 리마인더를 받아야 한다 — 대화가 깊어질수록 모델이 기억으로 답하기 쉬워지는데, 정작 그때 // 게이트는 메시지가 짧아 아무것도 못 본다(2026-09-04 소설-모델 스레드가 그렇게 3턴 갔다). + } else if (newsEntityFollowUp) { + console.log('[v2] NEWS ENTITY FOLLOW-UP: 뉴스 표에 나온 인물 질문 → 검색 강제'); + messages.push({ role: 'assistant', content: 'Got it — let me look that up.' }); + messages.push({ + role: 'user', + content: 'Reminder: this asks about someone from the news you just listed. Call web_search on the name first (add 약력/프로필) and answer from the results — works, career, dates and other details must come from what the search returned, not from memory.', + }); } else if (isFactualInfoRequest(message) || isFactualThreadFollowUp(message, String([...history].reverse().find(h => h.role === 'user')?.content || ''))) { messages.push({ role: 'assistant', content: 'Got it — let me verify that first.' }); @@ -1529,7 +1538,7 @@ async function handleChat( // after tool results come back. const forceToolChoice = round === 0 && !toolsDisabledForRestOfTurn - && (isLiveDataRequest(message) || isFactualInfoRequest(message)) + && (isLiveDataRequest(message) || isFactualInfoRequest(message) || newsEntityFollowUp) && getModelProfileForceToolChoice(effectiveModel || getModelForRole('executor')); // Always use streaming so text tokens appear in real-time. The streaming // handler collects tool_calls from chunks and returns them in the final diff --git a/src/gateway/guards/prompt-gates.ts b/src/gateway/guards/prompt-gates.ts index f2f7021..9a988eb 100644 --- a/src/gateway/guards/prompt-gates.ts +++ b/src/gateway/guards/prompt-gates.ts @@ -213,6 +213,27 @@ export function isFactualThreadFollowUp(message: string, previousUserMessage: st return /[??]$/.test(m) || /(까|나요|니|냐|지|는가|은가|어때|얼마|몇|뭐|무엇|어디|언제|누구|왜|어떻게)\s*[??]?$/.test(m); } +/** + * 방금 뉴스 표에 나온 인물을 묻는 후속 질문("무라카미 류 누구지?"). + * + * 2026-10-23 실측: 일본 뉴스 표의 "무라카미 류 별세" 다음 턴에 Haiku가 검색 없이 기억으로 답하면서 + * 데뷔작 제목을 지어내고(『한 조각의 푸른 하늘』) 무관한 『공동경비구역 JSA』까지 그의 작품처럼 꺼냈다. + * 인물 질문 전체를 검색으로 돌리면 매 턴 느려지므로, 직전 답이 뉴스 표이고 물은 이름이 그 표에 + * 실제로 있을 때만 잡는다(사용자 결정). + */ +export function isNewsEntityFollowUp(message: string, previousAssistant: string): boolean { + const m = String(message || '').trim(); + const prev = String(previousAssistant || ''); + if (!m || m.length > 40) return false; + if (!/\|\s*제목\s*\|/.test(prev)) return false; + const WHO = /(누구|누군|어떤\s*사람|뭐\s*하는\s*사람|who\s+(is|was|are))/i; + if (!WHO.test(m)) return false; + const names = m.replace(/[??!.,]/g, ' ').split(/\s+/) + .map(t => t.replace(/(이란|란|씨는|씨가|씨|님은|님|은|는|이|가)$/, '')) + .filter(t => t.length >= 2 && !WHO.test(t) && !/^(어떤|사람|뭐하는|그|이|저)$/.test(t)); + return names.some(t => prev.includes(t)); +} + // Output-side counterpart to isFactualInfoRequest()/isLiveDataRequest(): those only catch // predictable INPUT phrasings ("스펙", "비교", "몇 세대"), and casual paraphrases slip through // unmatched ("초당 몇 토큰 나올까?", "이거 어떨까?") — a model answering those confidently from diff --git a/tests/prompt-gates.test.ts b/tests/prompt-gates.test.ts index 5e25dfd..65b5966 100644 --- a/tests/prompt-gates.test.ts +++ b/tests/prompt-gates.test.ts @@ -16,6 +16,7 @@ import { test, describe } from 'node:test'; import assert from 'node:assert/strict'; import { + isNewsEntityFollowUp, looksLikeUnverifiedSpecClaim, isExemptFromVerification, isFactualInfoRequest, @@ -557,3 +558,16 @@ describe('isActionPromiseNoTool — 되묻기는 약속이 아니다', () => { assert.equal(isActionPromiseNoTool('정확한 정보가 필요하므로 검색해 드리겠습니다.'), true); }); }); + +describe('isNewsEntityFollowUp', () => { + const newsTable = '| 제목 | 요약 | 출처 |\n|---|---|---|\n| 소설가 무라카미 류 별세 | 작가 무라카미 류(村上龍)가 사망했으며… | Yahoo!ニュース |\n| 서울고법, 오세훈 서울시장 무죄 선고 | … | Yahoo!ニュース |'; + test('뉴스 표에 나온 이름을 누구냐고 물으면 잡는다', () => { + assert.equal(isNewsEntityFollowUp('무라카미 류 누구지?', newsTable), true); + assert.equal(isNewsEntityFollowUp('오세훈은 어떤 사람이야?', newsTable), true); + }); + test('표에 없는 이름, 뉴스 표가 아닌 직전 답, 인물 질문이 아닌 말은 놓아 둔다', () => { + assert.equal(isNewsEntityFollowUp('하루키는 누구지?', newsTable), false); + assert.equal(isNewsEntityFollowUp('무라카미 류 누구지?', '무라카미 류는 소설가입니다.'), false); + assert.equal(isNewsEntityFollowUp('무라카미 류 작품 뭐 있어?', newsTable), false); + }); +});