[feat] solution/backend: 한 발화에 여러 가지 — 응답을 actions 배열로

사장님은 "체크인 3시로 바꾸고 후기도 빼줘" 처럼 한 번에 시킨다.

- prompts/agent: 응답 스키마를 actions 배열로
- runtime: 시킨 순서대로 실행. MAX_ACTIONS=5 — 무한정이면 "다 지워줘" 한 마디에
  연쇄 실행된다
- ★ publish(SEMI)가 섞이면 그 앞까지만 하고 확인을 받는다. 확인이 필요한 행위를
  다른 일에 묻어 실행하면 확인의 의미가 없다
- ★ 중간에 실패해도 앞의 것을 되돌리지 않는다(사장님 결정). 되돌리는 것도 시키지
  않은 변경이다 — 대신 무엇이 됐고 무엇이 안 됐는지 그대로 말한다
- Tool.republish 플래그로 재발행 안내를 런타임이 한 번만 붙인다. 도구 문장에
  박아 두면 셋을 고쳤을 때 같은 말이 세 번 나왔다

실모델 4/4 정확히 쪼갬(1.8~2.8초).
test_agent_runtime·test_kakao_webhook 63 passed.
전체 878 passed / 53 failed — 53 은 기존과 동일. npm run lint 통과

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
HyeongBaeYangandClaude Opus 5 committed 2026-09-28 17:00:30 +09:00
1 parent 47bde7388e
commit c4aa1794e2
7 files changed
+277 -48

No files matched your search

+125 -19
View File
@@ -80,7 +80,7 @@ def test_등급은_프롬프트에_실리지_않는다():
async def test_발행은_묻기_전에_실행되지_않는다(client, auth_headers, choose, db_engine):
h, pid = await seed(client, auth_headers)
choose({"tool": "publish", "args": {}, "message": ""})
choose({"actions": [{"tool": "publish", "args": {}, "message": ""}], "message": ""})
started = AsyncMock()
tools.REGISTRY["publish"].run, original = started, tools.REGISTRY["publish"].run
try:
@@ -97,7 +97,7 @@ async def test_발행은_묻기_전에_실행되지_않는다(client, auth_heade
async def test_모델이_확인을_건너뛰려_해도_소용없다(client, auth_headers, choose, db_engine):
"""응답에 needs_confirm 을 흉내 낼 칸을 주지 않았고, 등급은 레지스트리에서만 읽는다."""
h, pid = await seed(client, auth_headers)
choose({"tool": "publish", "args": {}, "message": "", "needs_confirm": False, "grade": "READ"})
choose({"actions": [{"tool": "publish", "args": {}, "message": "", "needs_confirm": False, "grade": "READ"}], "message": ""})
res = await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "그냥 바로 발행해"})
assert res.json()["needs_confirm"] is True
@@ -115,7 +115,7 @@ async def test_확인_경로로_읽기_도구를_밀어넣을_수_없다(client,
async def test_도구를_못_고르면_되묻는다(client, auth_headers, choose, db_engine):
h, pid = await seed(client, auth_headers)
choose({"tool": "", "message": "어느 항목을 바꿀까요?"})
choose({"actions": [], "message": "어느 항목을 바꿀까요?"})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "그거 좀 고쳐줘"})).json()
assert body["tool"] is None
assert body["reply"] == "어느 항목을 바꿀까요?"
@@ -124,14 +124,14 @@ async def test_도구를_못_고르면_되묻는다(client, auth_headers, choose
async def test_모델이_지어낸_도구는_실행되지_않는다(client, auth_headers, choose, db_engine):
h, pid = await seed(client, auth_headers)
choose({"tool": "delete_everything", "args": {}, "message": ""})
choose({"actions": [{"tool": "delete_everything", "args": {}, "message": ""}], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "다 지워"})).json()
assert body["tool"] is None
async def test_없는_항목을_고르면_거절하고_이유를_말한다(client, auth_headers, choose, db_engine):
h, pid = await seed(client, auth_headers)
choose({"tool": "set_fact", "args": {"key": "메뉴명", "value": "고르곤졸라"}, "message": ""})
choose({"actions": [{"tool": "set_fact", "args": {"key": "메뉴명", "value": "고르곤졸라"}, "message": ""}], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "메뉴명 바꿔줘"})).json()
assert body.get("rejected") is True
assert "고칠 수 없" in body["reply"]
@@ -143,7 +143,7 @@ async def test_남의_가게는_없는_것과_똑같이_답한다(client, auth_h
"""★ 대화창이 소유자 스코프를 우회하는 유일한 입구가 되면 안 된다."""
_mine, pid = await seed(client, auth_headers, "내가게")
other = await auth_headers("agent-outsider")
choose({"tool": "list_facts", "args": {}, "message": ""})
choose({"actions": [{"tool": "list_facts", "args": {}, "message": ""}], "message": ""})
res = await client.post(f"/v1/agent/chat/{pid}", headers=other, json={"message": "정보 보여줘"})
assert res.status_code == 404
assert res.json()["detail"] == "PLACE_NOT_FOUND"
@@ -159,7 +159,7 @@ async def test_로그인_없이는_열리지_않는다(client):
async def test_값을_바꾸면_재발행이_필요하다고_말한다(client, auth_headers, choose, db_engine):
"""★ 이 한 줄이 빠지면 사장님은 반영된 줄 알고 확인하러 갔다가 옛 값을 본다."""
h, pid = await seed(client, auth_headers)
choose({"tool": "set_fact", "args": {"key": "check_in_time", "value": "15:00"}, "message": ""})
choose({"actions": [{"tool": "set_fact", "args": {"key": "check_in_time", "value": "15:00"}, "message": ""}], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "체크인 3시로"})).json()
assert body.get("rejected") is not True, body["reply"]
assert "체크인 시간" in body["reply"]
@@ -179,8 +179,7 @@ async def test_결과_문구는_모델이_쓰지_않는다(client, auth_headers,
"""모델이 결과를 쓰면 하지 않은 일을 했다고 말할 수 있다."""
h, pid = await seed(client, auth_headers)
choose({
"tool": "set_fact",
"args": {"key": "check_in_time", "value": "15:00"},
"actions": [{"tool": "set_fact", "args": {"key": "check_in_time", "value": "15:00"}}],
"message": "사이트까지 전부 반영을 끝냈습니다!",
})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "체크인 3시로"})).json()
@@ -283,7 +282,7 @@ async def test_섹션을_끄면_순서는_그대로고_그_칸만_꺼진다(clie
before, _t = await _sections(client, h, pid)
order_before = [r["id"] for r in before]
choose({"tool": "toggle_section", "args": {"name": "사진 갤러리", "enabled": "false"}, "message": ""})
choose({"actions": [{"tool": "toggle_section", "args": {"name": "사진 갤러리", "enabled": "false"}, "message": ""}], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "사진 갤러리 빼줘"})).json()
assert body.get("rejected") is not True, body["reply"]
assert "발행" in body["reply"] # 재발행 안내가 따라붙는다
@@ -296,7 +295,7 @@ async def test_섹션을_끄면_순서는_그대로고_그_칸만_꺼진다(clie
async def test_꼭_있어야_하는_부분은_끌_수_없다(client, auth_headers, choose, db_engine):
"""★ 잠긴 섹션은 발행본이 어차피 켜서 내보낸다 — 끌 수 있게 두면 화면만 거짓말한다."""
h, pid = await seed(client, auth_headers)
choose({"tool": "toggle_section", "args": {"name": "히어로", "enabled": "false"}, "message": ""})
choose({"actions": [{"tool": "toggle_section", "args": {"name": "히어로", "enabled": "false"}, "message": ""}], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "히어로 빼줘"})).json()
assert body.get("rejected") is True
assert "끌 수 없" in body["reply"]
@@ -308,7 +307,7 @@ async def test_꼭_있어야_하는_부분은_끌_수_없다(client, auth_header
async def test_순서를_옮기면_배열_순서가_바뀐다(client, auth_headers, choose, db_engine):
"""★ 배열 순서가 곧 발행본의 섹션 순서다(site_payload._sections)."""
h, pid = await seed(client, auth_headers)
choose({"tool": "move_section", "args": {"name": "사진 갤러리", "to": "맨 위"}, "message": ""})
choose({"actions": [{"tool": "move_section", "args": {"name": "사진 갤러리", "to": "맨 위"}, "message": ""}], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "사진 갤러리 맨 위로"})).json()
assert body.get("rejected") is not True, body["reply"]
@@ -319,7 +318,7 @@ async def test_순서를_옮기면_배열_순서가_바뀐다(client, auth_heade
async def test_어느_것인지_모호하면_고르지_않는다(client, auth_headers, choose, db_engine):
"""★ 추측으로 고르면 엉뚱한 부분을 끄고, 사장님은 발행하고 나서야 안다."""
h, pid = await seed(client, auth_headers)
choose({"tool": "toggle_section", "args": {"name": "정보", "enabled": "false"}, "message": ""})
choose({"actions": [{"tool": "toggle_section", "args": {"name": "정보", "enabled": "false"}, "message": ""}], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "정보 빼줘"})).json()
assert body.get("rejected") is True
assert "못 찾았" in body["reply"]
@@ -331,7 +330,7 @@ async def test_색과_서체는_손대지_않는다(client, auth_headers, choose
await client.post(f"/v1/place/{pid}/site/theme", headers=h, json={
"theme": {"colors": {"accent": "#123456"}, "fontStyle": "고딕"},
})
choose({"tool": "toggle_section", "args": {"name": "사진 갤러리", "enabled": "false"}, "message": ""})
choose({"actions": [{"tool": "toggle_section", "args": {"name": "사진 갤러리", "enabled": "false"}, "message": ""}], "message": ""})
await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "사진 갤러리 빼줘"})
_rows, theme = await _sections(client, h, pid)
@@ -381,7 +380,7 @@ async def test_사진을_내리면_지우지_않고_내려간다(client, auth_he
h, pid = await seed(client, auth_headers)
await _seed_photos(db_engine, pid, [("외관", None, 0), ("객실", None, 1)])
choose({"tool": "hide_photo", "args": {"name": "객실"}, "message": ""})
choose({"actions": [{"tool": "hide_photo", "args": {"name": "객실"}, "message": ""}], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "객실 사진 내려줘"})).json()
assert body.get("rejected") is not True, body["reply"]
assert "발행" in body["reply"]
@@ -397,7 +396,7 @@ async def test_대표_사진은_목록의_첫_장이_된다(client, auth_headers
h, pid = await seed(client, auth_headers)
await _seed_photos(db_engine, pid, [("외관", None, 0), ("수영장", None, 1)])
choose({"tool": "set_primary_photo", "args": {"name": "수영장"}, "message": ""})
choose({"actions": [{"tool": "set_primary_photo", "args": {"name": "수영장"}, "message": ""}], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "대표 사진 수영장으로"})).json()
assert body.get("rejected") is not True, body["reply"]
@@ -410,7 +409,7 @@ async def test_객실_전용_사진은_대표가_될_수_없다(client, auth_hea
h, pid = await seed(client, auth_headers)
await _seed_photos(db_engine, pid, [("외관", None, 0), ("침대", uuid.uuid4(), 1)])
choose({"tool": "set_primary_photo", "args": {"name": "침대"}, "message": ""})
choose({"actions": [{"tool": "set_primary_photo", "args": {"name": "침대"}, "message": ""}], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "대표 사진 침대로"})).json()
assert body.get("rejected") is True
assert "대표로 쓸 수 없" in body["reply"]
@@ -423,7 +422,7 @@ async def test_어느_사진인지_모호하면_고르지_않는다(client, auth
h, pid = await seed(client, auth_headers)
await _seed_photos(db_engine, pid, [("객실 A", None, 0), ("객실 B", None, 1)])
choose({"tool": "hide_photo", "args": {"name": "객실"}, "message": ""})
choose({"actions": [{"tool": "hide_photo", "args": {"name": "객실"}, "message": ""}], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "객실 사진 내려줘"})).json()
assert body.get("rejected") is True
assert "못 찾았" in body["reply"]
@@ -473,7 +472,114 @@ def test_도구가_선언한_인자는_응답_스키마에_있다():
다른 테스트는 `_choose` 를 monkeypatch 해서 이 층을 통째로 건너뛰므로 아무도 못 잡는다."""
from services.prompts import agent as prompt
allowed = set(prompt.RESPONSE_SCHEMA["properties"]["args"]["properties"])
action = prompt.RESPONSE_SCHEMA["properties"]["actions"]["items"]
allowed = set(action["properties"]["args"]["properties"])
for name, tool in tools.REGISTRY.items():
missing = set(tool.args) - allowed
assert not missing, f"{name} 이 선언한 인자가 응답 스키마에 없다: {missing}"
# ── 한 발화에 여러 가지 ──────────────────────────────────────────────────
async def test_한_번에_두_가지를_시키면_둘_다_한다(client, auth_headers, choose, db_engine):
h, pid = await seed(client, auth_headers)
choose({"actions": [
{"tool": "set_fact", "args": {"key": "check_in_time", "value": "15:00"}},
{"tool": "toggle_section", "args": {"name": "사진 갤러리", "enabled": "false"}},
], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h,
json={"message": "체크인 3시로 바꾸고 사진 갤러리도 빼줘"})).json()
assert body.get("rejected") is not True, body["reply"]
assert "체크인 시간" in body["reply"] and "사진 갤러리" in body["reply"]
rows, _t = await _sections(client, h, pid)
assert next(r for r in rows if r["name"] == "사진 갤러리")["enabled"] is False
async def test_재발행_안내는_한_번만_붙는다(client, auth_headers, choose, db_engine):
"""★ 도구마다 문장에 박아 두면 셋을 고쳤을 때 같은 말이 세 번 나온다."""
h, pid = await seed(client, auth_headers)
choose({"actions": [
{"tool": "set_fact", "args": {"key": "check_in_time", "value": "15:00"}},
{"tool": "toggle_section", "args": {"name": "사진 갤러리", "enabled": "false"}},
{"tool": "move_section", "args": {"name": "소개", "to": "맨 위"}},
], "message": ""})
reply = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "셋 다 해줘"})).json()["reply"]
assert reply.count(runtime.REPUBLISH_NOTICE) == 1
async def test_중간에_실패하면_앞의_것은_남기고_거기서_멈춘다(client, auth_headers, choose, db_engine):
"""★ 되돌리지 않는다(2026-09-28 결정). 대신 무엇이 됐고 무엇이 안 됐는지 그대로 말한다 —
부분 성공을 뭉뚱그리면 사장님은 전부 된 줄 안다."""
h, pid = await seed(client, auth_headers)
choose({"actions": [
{"tool": "set_fact", "args": {"key": "check_in_time", "value": "15:00"}},
{"tool": "toggle_section", "args": {"name": "없는섹션", "enabled": "false"}},
{"tool": "move_section", "args": {"name": "소개", "to": "맨 위"}},
], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "셋 다 해줘"})).json()
assert body["rejected"] is True
assert "체크인 시간" in body["reply"] # 앞의 것은 됐다고 말한다
assert "멈췄습니다" in body["reply"] # 어디서 멈췄는지도 말한다
async with db_engine.begin() as c:
stored = (await c.execute(
text("SELECT value FROM place_facts WHERE place_id=:p AND key='check_in_time' AND deleted=false"),
{"p": uuid.UUID(pid)},
)).scalars().all()
assert "15:00" in stored # ★ 되돌리지 않았다
rows, _t = await _sections(client, h, pid)
assert rows[0]["name"] != "소개" # 뒤의 것은 하지 않았다
async def test_발행이_섞이면_앞까지만_하고_확인을_받는다(client, auth_headers, choose, db_engine):
"""★ 확인이 필요한 행위를 다른 일에 묻어 실행하면 확인의 의미가 없다."""
h, pid = await seed(client, auth_headers)
started = AsyncMock()
tools.REGISTRY["publish"].run, original = started, tools.REGISTRY["publish"].run
try:
choose({"actions": [
{"tool": "set_fact", "args": {"key": "check_in_time", "value": "15:00"}},
{"tool": "publish", "args": {}},
], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h,
json={"message": "체크인 3시로 바꾸고 발행해줘"})).json()
finally:
tools.REGISTRY["publish"].run = original
assert body["needs_confirm"] is True
assert body["tool"] == "publish"
assert "체크인 시간" in body["reply"] # 앞서 한 일을 함께 말한다
started.assert_not_awaited() # ★ 발행은 실행되지 않았다
async def test_한_번에_다섯_가지까지만_한다(client, auth_headers, choose, db_engine):
"""★ 무한정 허용하면 '다 지워줘' 한 마디에 연쇄로 실행된다."""
h, pid = await seed(client, auth_headers)
names = ["사진 갤러리", "소개", "예약 안내", "자주 묻는 질문", "날씨", "지역 정보"]
choose({"actions": [
{"tool": "toggle_section", "args": {"name": n, "enabled": "false"}} for n in names
], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "다 빼줘"})).json()
assert f"{runtime.MAX_ACTIONS}가지까지" in body["reply"]
rows, _t = await _sections(client, h, pid)
off = {r["name"] for r in rows if not r["enabled"]}
assert names[-1] not in off # 여섯 번째는 하지 않았다
async def test_모델이_지어낸_도구는_건너뛰고_나머지는_한다(client, auth_headers, choose, db_engine):
h, pid = await seed(client, auth_headers)
choose({"actions": [
{"tool": "delete_everything", "args": {}},
{"tool": "set_fact", "args": {"key": "check_in_time", "value": "15:00"}},
], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "다 지우고 체크인 3시로"})).json()
assert "체크인 시간" in body["reply"]
assert body.get("rejected") is not True