Fix age calculation: inject today's date, add Korean/international age

- Prepend today's date to system prompt on every call so LLM uses correct year
- Calculate both Korean age (현재연도-출생연도+1) and 만 나이 with exact birthday handling
- Support full date (생년월일) and year-only (생년) profile values
- Update remember_user_info to encourage storing full birth date
- Strengthen get_current_date tool description for age-related queries

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sal
2026-05-27 15:10:30 +09:00
parent 06bcdb03ac
commit b4b628ab78
3 changed files with 39 additions and 6 deletions
+28 -3
View File
@@ -74,12 +74,37 @@ class AgentService:
llm_with_tools = chat_model.bind_tools(tools)
async def call_model(state: MessagesState, config: RunnableConfig) -> dict:
system_content = self._system_prompt
from datetime import date
system_content = f"오늘 날짜: {date.today().isoformat()}\n\n" + self._system_prompt
if self._profile_repo:
profile = self._profile_repo.get_all(self._user_id)
if profile:
lines = "\n".join(f"- {k}: {v}" for k, v in profile.items())
system_content += f"\n\n## 사용자 정보 (이전 대화에서 기억된 내용)\n{lines}"
import re
from datetime import date
today = date.today()
current_year = today.year
_DATE_KEYS = ("생년월일", "생년", "생일")
lines = []
for k, v in profile.items():
if any(term in k for term in _DATE_KEYS):
full_date = re.search(r'(\d{4})[년\-/.]\s*(\d{1,2})[월\-/.]\s*(\d{1,2})', v)
year_only = re.search(r'\b(19|20)\d{2}\b', v)
age_key = re.sub(r'생년월일|생년|생일', '나이', k)
if full_date:
by, bm, bd = int(full_date.group(1)), int(full_date.group(2)), int(full_date.group(3))
korean_age = current_year - by + 1
intl_age = current_year - by - (1 if today < date(current_year, bm, bd) else 0)
lines.append(f"- {age_key}: 한국 나이 {korean_age}세, 만 {intl_age}")
elif year_only:
by = int(year_only.group())
korean_age = current_year - by + 1
intl_age = current_year - by
lines.append(f"- {age_key}: 한국 나이 {korean_age}세, 만 {intl_age}~{intl_age - 1}세 (생일에 따라 다름)")
else:
lines.append(f"- {k}: {v}")
else:
lines.append(f"- {k}: {v}")
system_content += f"\n\n## 사용자 정보 (이전 대화에서 기억된 내용)\n" + "\n".join(lines)
msgs = [SystemMessage(content=system_content)] + state["messages"]
thinking_acc, content_acc, tool_calls_acc = "", "", []
async for chunk in llm_with_tools.astream(msgs, config):