새 브라우저 탭에서 ApplicationURL을 열고 Support Tickets > View Tickets를 클릭하여 새로운 지원 티켓이 생성되었는지 확인합니다.
에이전트 테스트
테스트 스크립트 수정 필요: 테스트 스크립트의 Cognito 로그인이 example.com 콜백으로 리다이렉트될 때 SSL 인증서 오류가 발생합니다. 아래 패치를 먼저 실행하세요.
🔍 이 패치는 무엇을 변경하나요?
Cognito 인증 성공 후 https://example.com/auth/callback?code=...로 리다이렉트될 때, requests 라이브러리가 실제로 example.com에 HTTPS 연결을 시도하여 SSL 인증서 오류가 발생합니다. 이 패치는 SSL 오류를 catch하여 실패한 요청 URL에서 인증 코드를 추출합니다. 인증 자체는 이미 성공한 상태이므로 코드 추출만으로 충분합니다.
다음 자격 증명을 사용하여 인증합니다:
사용자 이름: test@example.com
비밀번호: TestPassword123!
로그인 프로세스를 완료하는 데 10-15초가 소요될 수 있습니다.
의미 메모리 (Semantic Memory) 검증
에이전트에게 권한과 아키텍처 정보를 질문합니다:
영어: Do I have permissions to troubleshoot the Image Platform connectivity issues? What's the architecture?
의미 메모리 응답
에이전트가 의미 메모리에서 권한 및 아키텍처 정보를 검색하여 응답합니다. 이 정보는 실시간으로 조회하는 것이 아니라, 사전에 메모리에 저장된 사실 정보에서 검색됩니다.
사용자 선호도 메모리 (User Preference) 검증
SOP를 요청합니다:
영어: Give me the SOP for connectivity issue between Reporting Server and Database?
사용자 선호도 메모리 응답
사용자 선호도에 맞춘 상세 런북이 제공됩니다.
요약 메모리 (Summary Memory) 검증
이 테스트는 두 개의 세션을 통해 수행합니다.
세션 1: 문제 해결 시작 후 의도적 종료
영어: Check connectivity between reporting.examplecorp.com and database.examplecorp.com
에이전트가 진단을 시작하면, 의도적으로 exit로 세션을 종료합니다.
세션 1 요약
세션 2: 메모리 컨텍스트로 재개
새 세션을 시작합니다:
다시 인증한 후 이전 세션의 컨텍스트를 참조하여 질문합니다:
영어: System crashed, where were we with respect to troubleshooting connectivity between reporting.examplecorp.com and database.examplecorp.com?
MemoryHook 클래스 핵심 구조 (memory_hook_provider.py, 559줄)
4-Question 라우팅 로직
on_message_added 메서드는 사용자 질문을 분석하여 적절한 메모리 전략으로 라우팅합니다:
retrieve_memories 메커니즘
메모리 전략별 네임스페이스 매핑
전략
네임스페이스 패턴
저장 데이터
검증 질문
Semantic
examplecorp/user/{actor}/facts
권한, 아키텍처, 팀 정보
"Do I have permissions...?"
User Preference
examplecorp/user/{actor}/preferences
SOP, 선호 형식, 통신 스타일
"Give me the SOP for...?"
Summary
examplecorp/user/{actor}/{session}
세션 대화 요약
"System crashed, where were we?"
Custom
examplecorp/procedures/{actor}/workflows
기관 절차, 이력
(절차 기반 질문)
세션 간 컨텍스트 복원 (on_agent_initialized)
핵심 포인트: MemoryHook은 Strands Framework의 Hook 패턴을 활용합니다. on_agent_initialized는 에이전트 시작 시 이전 세션을 로드하고, on_message_added는 매 메시지마다 관련 메모리를 검색하여 시스템 프롬프트에 동적으로 주입합니다. 에이전트 코드(agent.py)는 수정 없이hooks=[memory_hook] 한 줄만 추가하면 됩니다.
모듈 2 완료! 에이전트가 세션 간 컨텍스트를 유지하고, 개인화된 응답을 제공합니다. 다음 모듈에서는 A2A 프로토콜로 멀티 에이전트 협업을 구현합니다.
시스템이 다운됐었는데, reporting.examplecorp.com과 database.examplecorp.com 연결 문제 해결이 어디까지 진행됐었지?
응, 수정하고 검증해줘
exit
class MemoryHook(HookProvider):
"""Strands Agent의 Hook 시스템을 통해 메모리를 자동 관리"""
def __init__(self, memory_client: MemoryClient, memory_id: str,
actor_id: str, session_id: str):
self.memory_client = memory_client # AgentCore Memory SDK
self.memory_id = memory_id # 메모리 리소스 ID
self.actor_id = actor_id # 사용자 식별자
self.session_id = session_id # 세션 식별자
def register_hooks(self, registry: HookRegistry):
"""Strands Agent에 두 가지 훅 등록"""
registry.add_callback(AgentInitializedEvent, self.on_agent_initialized)
registry.add_callback(MessageAddedEvent, self.on_message_added)
def on_message_added(self, event: MessageAddedEvent):
user_query = messages[-1]["content"][0]["text"].lower()
# Q1: 권한/아키텍처 → Semantic Memory
if "permission" in user_query and "architecture" in user_query:
self._add_context_user_query(
namespace=f"examplecorp/user/{self.actor_id}/facts",
strategy_name="Semantic Memory"
)
# Q2: SOP → User Preference Memory
elif "sop" in user_query:
self._add_context_user_query(
namespace=f"examplecorp/user/{self.actor_id}/preferences",
strategy_name="User Preference Memory"
)
# Q3: 연결성 점검 → Semantic + Tool Calling
elif "check connectivity" in user_query:
self._add_context_user_query(
namespace=f"examplecorp/user/{self.actor_id}/facts",
strategy_name="Semantic Memory"
)
# Q4: 시스템 크래시 → Summary Memory
elif "system crashed" in user_query or "where were we" in user_query:
self._add_context_user_query(
namespace=f"examplecorp/user/{self.actor_id}/{self.session_id}",
strategy_name="Summarization Memory"
)
def _add_context_user_query(self, namespace, query, init_content, event, strategy_name):
"""네임스페이스에서 관련 메모리를 검색하여 시스템 프롬프트에 주입"""
memories = self.memory_client.retrieve_memories(
memory_id=self.memory_id,
namespace=namespace, # 전략별 네임스페이스
query=query, # 사용자 질문 (유사도 검색)
top_k=3 # 상위 3개 결과
)
if memories:
# 메모리 컨텍스트를 시스템 프롬프트에 동적 추가
memory_context = f"=== MEMORY CONTEXT FOR RESPONSE ===\n"
memory_context += f"STRATEGY: {strategy_name.upper()}\n"
for i, memory in enumerate(memories):
memory_context += f"MEMORY {i+1}: {memory['content']['text']}\n"
event.agent.system_prompt += memory_context # 런타임 프롬프트 확장
def on_agent_initialized(self, event: AgentInitializedEvent):
"""에이전트 시작 시 이전 세션 컨텍스트를 자동 로드"""
# 현재 세션에서 최근 대화 검색
recent_turns = self.memory_client.get_last_k_turns(
memory_id=self.memory_id,
actor_id=self.actor_id,
session_id=self.session_id,
k=10, # 최근 10턴
)
# 이전 세션 컨텍스트가 없으면 다른 세션 패턴 탐색
if not recent_turns:
for session_pattern in ["troubleshooting_session", "main_session"]:
recent_turns = self.memory_client.get_last_k_turns(
memory_id=self.memory_id,
session_id=session_pattern, k=10
)
if recent_turns:
break
# 시스템 프롬프트에 이전 컨텍스트 주입
event.agent.system_prompt += f"""
=== PREVIOUS SESSION CONTEXT ===
{formatted_context}
=== END PREVIOUS SESSION CONTEXT ===
"""