547. BedrockSessionSaver LangGraph 라이브러리로 세션 관리 (Manage sessions with BedrockSessionSaver LangGraph library)
- 원문: English
- 위치: Additional capabilities › Session management › Manage sessions with BedrockSessionSaver LangGraph library
한 줄 요약
세션 관리 API를 직접 부르는 대신, LangGraph CheckpointSaver 구현체인 BedrockSessionSaver 를 그래프의 체크포인터로 넣으면 LangGraph 상태가 Bedrock 세션에 자동 저장됩니다.
쉽게 말하면
LangGraph의 compile(checkpointer) 자리에 BedrockSessionSaver를 끼우고, thread_id에 Bedrock 세션 ID를 넣으면 끝입니다. 코드: langgraph-checkpoint-aws
핵심 내용
준비
| 항목 | 내용 |
|---|---|
| 패키지 | boto3, langgraph, langgraph-checkpoint-aws, langchain-core |
| 모델 | 예제는 Claude 3.5 Sonnet v2 (anthropic.claude-3-5-sonnet-20241022-v2:0). 다른 모델로 변경 가능 |
| 리전 | ⚠️ bedrock-agent-runtime 클라이언트와 BedrockSessionSaver의 리전이 같아야 하고, 사용 모델을 지원해야 함 |
사용 패턴 (원문 예제 요약)
from langgraph_checkpoint_aws.saver import BedrockSessionSaver
client = boto3.client("bedrock-agent-runtime", region_name="<리전>")
session_saver = BedrockSessionSaver(region_name="<리전>") # 같은 리전
graph = workflow.compile(session_saver) # 체크포인터로 지정
session_id = client.create_session()["sessionId"]
config = {"configurable": {"thread_id": session_id}} # 세션 ID = thread_id
graph.invoke(state, config)
graph.get_state_history(config, limit=3) # 저장된 상태 이력 조회
- 예제는
StateGraph에 노드 하나(process_question)를 두고 사용자가quit을 입력할 때까지 반복하며, 모델 호출은bedrock-runtime의invoke_model을 씁니다.
📝 원문 확인 필요: 예제의 모델 호출 클라이언트는 region_name="us-west-2"로 고정되어 있어, 본문의 “REGION을 바꾸라"는 안내와 별개로 이 값도 함께 바꿔야 합니다.
SA 관점
- LangGraph 고객이 체크포인터를 직접 구현(DynamoDB 등)하지 않고 IAM·KMS 통제가 되는 관리형 저장소를 쓸 수 있는 가장 쉬운 경로입니다.
- 단, 기반 API가 프리뷰이고 30일 보존·세션당 1,000 스텝 한도(540)가 그대로 적용됩니다. 그래프 노드가 많은 워크플로는 스텝 소모량을 먼저 측정하세요.