Skip to content

feat: Evidence Research Agent를 AgentCore Gateway(MCP)로 연결 + Lambda 웜업 버그 수정 - #83

Merged
jeongmin1999 merged 1 commit into
mainfrom
feature/evidence-research-mcp-gateway
Jul 4, 2026
Merged

jeongmin1999 merged 1 commit into
mainfrom
feature/evidence-research-mcp-gateway

Conversation

@gpffh20

@gpffh20 gpffh20 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

개요

Evidence Research Agent의 7개 검색 tool을 AgentCore Gateway(MCP, AWS_IAM 인증) 경유로 원격 호출할 수 있게 합니다 (Infra PR #390에서 만든 Gateway/Lambda 대상).

  • evidence_research_gateway_url 설정값이 비어있으면(기본값) 기존처럼 in-process tool 그대로 사용 — 기존 동작 변경 없음
  • 값이 채워지면 mcp-proxy-for-aws의 aws_iam_streamablehttp_client(SigV4 자동 서명)로 Gateway에 연결해 같은 7개 tool을 원격 호출
  • KURE-v1 임베딩 계산은 Lambda 안에서 일어남 (in-process 경로와 동일한 파이프라인 재사용, 결과는 동일해야 함)
  • AgentCore Runtime(5-Agent Graph 전체 호스팅)은 이 PR 범위 밖입니다. 리포트 생성 워커는 여전히 run_report_generation()을 in-process로 호출합니다 - 이건 별도 작업입니다.

실제 prod Gateway로 검증하며 발견한 버그 수정

fetch/resolve_ontology_synonyms 같은 DB/모델 안 쓰는 tool은 바로 됐는데, search_korean_evidence(KURE 모델 로딩 + DB 필요)가 계속 실패했습니다:

  • Lambda의 웜업 ping이 실제로는 아무것도 안 하고 바로 return해서, "웜" 상태여도 모델이 로드된 적이 없었습니다. 매 실제 검색 요청마다 콜드 모델 로딩 비용을 그대로 물었고, 이게 Gateway의 tool 호출 타임아웃(30초)을 넘겨버렸습니다 (prod 로그로 확인: 콜드 60180초+, 로컬 RIE 재현으로는 ~20초 - 차이는 VPC ENI 콜드스타트로 추정)
  • 수정: 웜업 ping이 _get_embedding_model().predict(["ping"])를 실제로 호출해 모델을 로드/캐싱하도록 변경

검증

  • prod에 배포된 실제 Gateway로 tool 목록 조회 + resolve_ontology_synonyms 실제 호출 성공 확인
  • 로컬에서 Lambda 이미지를 Runtime Interface Emulator로 직접 띄워 수정된 웜업 로직 실측: 콜드 ping 19.5초(모델 로딩 포함, Gateway 예산 안), 웜 ping 0.64초, 웜 상태 search_korean_evidence(DB 포함) 10.4초 - 전부 프로덕션 배포 없이 검증
  • pytest tests/ 179 passed, ruff check 통과

Test plan

  • 로컬 RIE로 웜업 fix 실측
  • prod Gateway 실제 tool 목록/호출 확인 (모델 불필요한 tool)
  • 머지 후 CI가 이미지 재배포하면, 실제 prod에서 search_korean_evidence 등 DB+모델 필요한 tool도 Gateway 경유로 성공하는지 재확인 필요

… Lambda warmup

Evidence Research Agent's tools now have two code paths, chosen by whether
evidence_research_gateway_url is set (empty by default, so nothing changes
for existing callers):
  - unset: in-process @tool functions (existing behavior)
  - set: connects to the deployed AgentCore Gateway over MCP
    (mcp-proxy-for-aws's aws_iam_streamablehttp_client handles SigV4
    signing), calling the same 7 tools remotely via kure_retriever Lambda

Verified for real against the deployed prod Gateway: listed all 7 tools
with their qualified names, and called resolve_ontology_synonyms end to
end (Gateway -> Lambda -> ontology.yaml, real response).

Also found and fixed a real bug while testing search_korean_evidence live:
the Lambda's warmup ping short-circuited before ever loading the KURE-v1
embedding model, so it kept every container "warm" without the model
actually loaded. Every real search call then paid full cold-load time
(measured 60s+, exceeding the Gateway's own ~30s tool-call timeout) even
on a supposedly warm container. The warmup handler now actually calls
_get_embedding_model().predict(["ping"]) so the model is cached in the
process for subsequent real invocations.
@gpffh20 gpffh20 self-assigned this Jul 4, 2026
@jeongmin1999
jeongmin1999 self-requested a review July 4, 2026 05:36
@jeongmin1999
jeongmin1999 merged commit 688e702 into main Jul 4, 2026
6 checks passed
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.

2 participants