Skip to content

feat: 숲봇 답변에 warm 인스턴스 메모리 기반 문맥 추가 - #5

Merged
chegom merged 2 commits into
mainfrom
feat/in-memory-reply-context
Aug 28, 2026
Merged

chegom merged 2 commits into
mainfrom
feat/in-memory-reply-context

Conversation

@chegom

@chegom chegom commented Aug 28, 2026

Copy link
Copy Markdown
Owner

문제

숲봇은 질문 하나하나를 독립적으로 답해서, 숲봇아 왜 그렇지? 같은 후속 질문이 자기 직전 답변에 닿지 못했습니다.

이 템플릿은 의도적으로 데이터베이스 없이 배포되므로(원클릭 Deploy에 필요한 env는 OPENAI_API_KEY, SOOPBOT_TOKEN 둘뿐), 내구성 있는 대화 기록은 범위 밖입니다.

접근

MemoryRequestGuard가 이미 쓰고 있는 패턴을 그대로 따릅니다 — warm 서버리스 인스턴스 메모리에 최근 턴을 두고 프롬프트에 넣습니다. 인프라 추가가 없어 원클릭 배포가 그대로 유지됩니다.

  • 디스크에 쓰지 않음
  • 마지막 사용에서 30분 뒤 만료
  • MAX_TURNS = 20으로 상한 — 오래 사는 인스턴스에서도 무한 증가 없음
  • 인스턴스 간 공유 없음
  • 실패한 답변과 호출어만 부른 인사말은 기억하지 않음

SOOPBOT_MAX_HISTORY_TURNS(기본 4, 범위 0~10)로 조절하고, 0이면 기존 동작으로 완전히 돌아갑니다.

프롬프트 변화

이전 대화:
사용자: 어떤 언어를 배울까?
숲봇: 파이썬을 추천해요. 문법이 쉬워요.

현재 질문:
왜 그렇지?

문서 (공개 템플릿이라 중요)

README가 이전 대화 문맥 없이, 무상태 방식이라고 명시하고 있었고, 데이터 처리 항목이 "저장하지 않습니다"로만 되어 있었습니다. 이제 메모리 보관 사실을 명시합니다 — 어디에 얼마나 남고 언제 사라지는지. docs/customize.md에 환경변수와 비용 영향(턴 수를 늘리면 요청당 토큰 증가)을 추가했고, .env.example에도 반영했습니다.

기존 문서 계약 테스트는 그대로 통과하며, 메모리 보관 고지를 강제하는 계약 테스트를 새로 추가했습니다.

테스트

TDD로 작성했고 77개 전부 통과합니다 (check_test_discovery, check_public_tree 포함).

실패를 먼저 확인한 것:

  • 직전 턴이 다음 질문의 문맥이 된다 / 최신 N턴만 유지된다 / 0턴이면 무상태
  • 실패한 답변·인사말은 기억되지 않는다
  • TTL 지난 턴은 잊힌다 / 용량 상한을 넘지 않는다
  • 프로바이더가 이전 대화를 렌더링한다 / 빈 문맥은 명시적으로 표기한다
  • 설정 기본값 4, 상한 초과 거부
  • 문서가 메모리 보관을 고지한다

두 번째 커밋에 대해

리베이스로 상류의 _LazyOpenAIProvider(#1에서 추가)가 들어오면서 실제 프로덕션 경로가 깨졌습니다 — 래퍼가 context 키워드를 안 받아 모든 생성 답변이 프로바이더 실패 메시지로 떨어졌습니다. test_generated_replies_reuse_one_lazily_constructed_provider가 이걸 잡아냈고, 두 번째 커밋에서 래퍼가 context를 전달하도록 고쳤습니다.

chegom and others added 2 commits August 28, 2026 15:43
Soopbot answered each question in isolation, so a follow-up like "왜 그렇지?"
could not reach the answer it referred to. The template deliberately ships
without a database, so durable history is out of scope.

Reuse the pattern MemoryRequestGuard already established: keep the newest turns
in the warm serverless instance and render them into the prompt. Turns never
touch disk, expire 30 minutes after their last use, are capped so a long-lived
instance cannot grow without bound, and are never shared between instances.
Failed answers and the bare-trigger introduction are not remembered.

SOOPBOT_MAX_HISTORY_TURNS (default 4) tunes it, and 0 restores the previous
one-question-at-a-time behaviour. The deploy link still needs only the two
secrets. README and docs/customize.md now disclose the in-memory retention
instead of claiming the bot keeps no context.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The lazy provider wrapper accepted only persona and question, so once the reply
service started passing context every generated answer failed the keyword check
and fell back to the provider-failure message.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@chegom
chegom merged commit e1e3da5 into main Aug 28, 2026
4 checks passed
@chegom
chegom deleted the feat/in-memory-reply-context branch August 28, 2026 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant