[fix] solution/backend: 카톡 가게 정보 조회를 요약으로 — 발행 주소와 업종 핵심 항목만

"가게 정보 알려줘" 에 저장값을 20개까지 그대로 늘어놓아, 순환 문구 한 항목이 20줄을
넘겨 답을 덮었고 가능·불가 값은 'true' 로 나왔다(2026-10-21 카톡 캡처). 발행 주소는
다른 도구에만 있었다.

- tools.py: 키워드 없으면 상호·업종 · 발행 여부·시각·주소 · 스키마 critical 항목만 한 줄씩
  (첫 줄 30자에서 자름), 나머지는 개수로. 키워드가 있으면 그 항목을 자르지 않고.
  값은 _display 로 사장님 말(가능/불가·단위)로. 요약은 코드가 만든다 — LLM 호출 없음
- docs/AGENT_GUIDE.md: 가게 정보 조회 동작 갱신

테스트 3건 추가, test_agent_runtime·test_kakao_webhook 164 passed.
전체 1116 passed · 48 failed(gemini·search_console·weather_notes — 기존 실패와 동일)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
HyeongBaeYangandClaude Opus 5.5 committed 2026-10-23 15:54:42 +09:00
1 parent 9c107fa895
commit b948b09ba1
3 files changed
+115 -17

No files matched your search

+59 -15
View File
@@ -208,35 +208,79 @@ def _display(spec, value: str) -> str:
# ── 읽기 ────────────────────────────────────────────────────────────────
async def _get_site_status(ctx: ToolContext, args: dict) -> str:
async def _published(ctx: ToolContext) -> tuple[str, str] | None:
"""(주소, 마지막 발행 시각). 발행 전이면 None."""
_fact, site_service = _services()
res = await site_service.get_site(ctx.user, ctx.place_id)
site = res.site
site = (await site_service.get_site(ctx.user, ctx.place_id)).site
if site is None or site.published_at is None:
return "아직 발행 전입니다. 준비가 되면 발행해 드릴게요."
return None
# ★ 주소는 site_payload 의 함수로 만든다. 문자열로 조립하면 canonical 과 갈린다
# (CLAUDE.md '슬러그 규칙은 두 곳에 있고 같아야 한다').
url = f"{site_payload.publish_origin()}/s/{site_payload.publish_slug(ctx.place, site)}"
when = site.published_at.strftime("%Y-%m-%d %H:%M")
return url, site.published_at.strftime("%Y-%m-%d %H:%M")
async def _get_site_status(ctx: ToolContext, args: dict) -> str:
published = await _published(ctx)
if published is None:
return "아직 발행 전입니다. 준비가 되면 발행해 드릴게요."
url, when = published
return f"발행되어 있습니다.\n주소: {url}\n마지막 발행: {when}"
# 요약 한 줄에 싣는 값의 길이. 카톡 말풍선에서 한 줄로 읽히는 정도다.
SUMMARY_VALUE_MAX = 30
def _short(value: str) -> str:
"""첫 줄만, 길면 자른다 — 순환 문구처럼 수십 줄인 값이 요약을 통째로 덮었다(2026-10-21 캡처)."""
lines = value.strip().splitlines()
first = lines[0].strip() if lines else ""
if len(first) > SUMMARY_VALUE_MAX:
return first[:SUMMARY_VALUE_MAX].rstrip() + "…"
return first + ("…" if len(lines) > 1 else "")
async def _list_facts(ctx: ToolContext, args: dict) -> str:
"""키워드가 없으면 요약(발행 주소 + 업종 핵심 항목), 있으면 그 항목을 자르지 않고.
★ 요약 항목은 업종 스키마의 `critical` 이다 — 틀리면 예약 클레임이 나는 값이라 사장님이
제일 먼저 확인해야 하고, 목록을 여기 따로 두면 스키마와 갈린다."""
fact_service, _site = _services()
res = await fact_service.list_facts(ctx.user, ctx.place_id, publishable_only=True)
rows = [f for f in (res.facts or []) if (f.value or "").strip()]
schema = get_schema(PlaceCategory(ctx.place.category))
def label(f) -> str:
spec = schema.get(f.key)
return spec.label if spec else f.key
def shown(f) -> str:
spec = schema.get(f.key)
return _display(spec, f.value) if spec else f.value
keyword = _arg(args, "keyword")
if keyword:
rows = [f for f in rows if keyword in f.key or keyword in ((schema.get(f.key).label if schema.get(f.key) else ""))]
if not rows:
return "저장된 가게 정보가 아직 없습니다." if not keyword else f"'{keyword}' 로 찾은 정보가 없습니다."
lines = []
for f in rows[:20]:
spec = schema.get(f.key)
lines.append(f"· {spec.label if spec else f.key}: {f.value}")
more = f"\n(그 밖에 {len(rows) - 20}개 더 있습니다)" if len(rows) > 20 else ""
return "지금 저장된 정보입니다.\n" + "\n".join(lines) + more
rows = [f for f in rows if keyword in f.key or keyword in label(f)]
if not rows:
return f"'{keyword}' 로 찾은 정보가 없습니다."
lines = [f"· {label(f)}: {shown(f)}" for f in rows[:20]]
more = f"\n(그 밖에 {len(rows) - 20}개 더 있습니다)" if len(rows) > 20 else ""
return "\n".join(lines) + more
published = await _published(ctx)
head = [f"{ctx.place.name} · {schema.label}"]
head += [f"발행됨 · {published[1]}", published[0]] if published else ["아직 발행 전이에요."]
critical = set(schema.critical_keys())
key_rows = [f for f in rows if f.key in critical]
body = ["핵심 정보"] + [f"· {label(f)}: {_short(shown(f))}" for f in key_rows] if key_rows \
else ["저장된 핵심 정보가 아직 없어요."]
rest = len(rows) - len(key_rows)
tail = [f"그 밖에 {rest}개 항목이 저장돼 있어요."] if rest else []
tail.append("\"주차 정보 보여줘\"처럼 물어보시면 자세히 알려 드려요.")
return "\n\n".join(["\n".join(head), "\n".join(body), "\n".join(tail)])
# ── 되돌릴 수 있는 쓰기 ──────────────────────────────────────────────────
@@ -688,7 +732,7 @@ REGISTRY: dict[str, Tool] = {
name="list_facts",
grade=ToolGrade.READ,
title="가게 정보 보기",
summary="지금 저장된 가게 정보를 보여준다.",
summary="가게 정보를 요약해 보여준다(발행 주소 포함). 특정 항목을 물으면 그 값을 자세히 보여준다.",
args={"keyword": "찾고 싶은 항목이 있으면 그 말(선택)"},
run=_list_facts,
),