단계 3: Memory Runtime 생성

circle-exclamation

AgentCore Runtime 생성 (Memory 포함)

Memory가 통합된 새로운 Runtime을 생성합니다.

circle-exclamation
python3 << 'PATCH'
import re
f = 'scripts/troubleshooting_agent_runtime_with_memory.py'
c = open(f).read()
if '--disable-memory' in c:
    print('Already patched')
else:
    c = re.sub(r",\n\s+'--authorizer-config',[^\n]+", "", c)
    c = c.replace("'--region', get_aws_region()\n        ]",
                   "'--region', get_aws_region(),\n            '--disable-memory'\n        ]")
    oauth = "f'\\n\\nyes\\n{oauth_discovery_url}\\n{oauth_client_id}\\n\\n\\n\\n' + 'no\\n' * 5"
    if 'run_with_pty' in c:
        s = c.index("        # Use pseudo-terminal")
        e = c.index("        result = run_with_pty(configure_cmd, oauth_input)") + len("        result = run_with_pty(configure_cmd, oauth_input)")
        c = c[:s] + f"        result = subprocess.run(configure_cmd, check=False, capture_output=True, text=True, timeout=600, shell=False, input={oauth})" + c[e:]
    elif "input='no\\n' * 10" in c:
        c = c.replace("input='no\\n' * 10", f"input={oauth}")
    open(f, 'w').write(c)
    print('Patched: PTY -> subprocess.run + --disable-memory')
PATCH
chevron-right🔍 이 패치는 무엇을 변경하나요?hashtag
  1. --disable-memory 옵션 추가 — 메모리 관련 대화형 프롬프트를 건너뜀

  2. 불안정한 PTY(가상 터미널) 입력 방식을 안정적인 subprocess.run으로 교체

  3. OAuth 인증 설정을 대화형 입력으로 전달 (yes → Discovery URL → Client ID 순서)

패치가 완료되면 Runtime을 생성합니다:

chevron-right🔍 이 스크립트는 무엇을 하나요?hashtag
  1. Module 1과 동일한 에이전트에 MemoryHook 추가하여 새 Runtime 생성

  2. 에이전트 시작 시 이전 대화 컨텍스트 자동 로드 (최근 10턴)

  3. 메시지마다 전략별 메모리 검색 및 자동 저장

  4. Runtime이 ACTIVE 상태가 될 때까지 대기

검증

Amazon Bedrock AgentCore Agent Runtime 콘솔arrow-up-right로 이동하여 troubleshooting_agent_runtime_with_memory를 확인합니다.

상태가 Active인지 확인합니다.

Runtime with Memory

코드 분석: Memory Hook 통합

MemoryHook 클래스 전체 구조

on_agent_initialized: 세션 복원

on_message_added: 4가지 전략 라우팅

메모리 강화 시스템 프롬프트 (Module 2 추가분)

규칙
설명

MEMORY_INTEGRATION_RULES

메모리 컨텍스트가 있으면 도구 호출 대신 메모리 직접 사용

SUMMARIZATION_MEMORY_OVERRIDE

요약 메모리 모드에서는 dns-resolve, connectivity 도구 호출 금지

VERBATIM QUOTE RULES

메모리에 저장된 정보(권한, PathID 등)를 정확히 인용

ERROR HANDLING

스로틀링 시 메모리 기반 가이드 제공, 지수 백오프 재시도

circle-info

Module 1 vs Module 3 차이: Module 1은 memory_hook=None으로 메모리 없이 동작합니다. Module 2에서 MemoryHook을 추가하면, 시스템 프롬프트에 MEMORY-ENHANCED APPROACH 섹션이 추가되고, on_message_added에서 전략별 메모리 라우팅이 활성화됩니다.

이 시점의 아키텍처

circle-check

마지막 업데이트