View a markdown version of this page

Amazon Bedrock AgentCore SDK - Amazon Bedrock AgentCore

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

Amazon Bedrock AgentCore SDK

Amazon Bedrock AgentCore Python SDK를 사용하면 메모리 작업을 간소화하고 일반적인 사용 사례에 편리한 방법을 제공하는 상위 수준의 추상화를 수행할 수 있습니다.

종속성 설치

pip install bedrock-agentcore

단기 메모리 추가

from bedrock_agentcore.memory import MemoryClient client = MemoryClient(region_name="us-east-1") memory = client.create_memory( name="CustomerSupportAgentMemory", description="Memory for customer support conversations", ) client.create_event( memory_id=memory.get("id"), # This is the id from create_memory or list_memories actor_id="User84", # This is the identifier of the actor, could be an agent or end-user. session_id="OrderSupportSession1", #Unique id for a particular request/conversation. messages=[ ("Hi, I'm having trouble with my order #12345", "USER"), ("I'm sorry to hear that. Let me look up your order.", "ASSISTANT"), ("lookup_order(order_id='12345')", "TOOL"), ("I see your order was shipped 3 days ago. What specific issue are you experiencing?", "ASSISTANT"), ("Actually, before that - I also want to change my email address", "USER"), ( "Of course! I can help with both. Let's start with updating your email. What's your new email?", "ASSISTANT", ), ("newemail@example.com", "USER"), ("update_customer_email(old='old@example.com', new='newemail@example.com')", "TOOL"), ("Email updated successfully! Now, about your order issue?", "ASSISTANT"), ("The package arrived damaged", "USER"), ], )

전략을 사용하여 장기 메모리 추가

from bedrock_agentcore.memory import MemoryClient import time client = MemoryClient(region_name="us-east-1") memory = client.create_memory_and_wait( name="MyAgentMemory", strategies=[{ "summaryMemoryStrategy": { # Name of the extraction model/strategy "name": "SessionSummarizer", # Organize facts by session ID for easy retrieval # Example: "summaries/session123" contains summary of session123 "namespaceTemplates": ["/summaries/{actorId}/{sessionId}/"] } }] ) event = client.create_event( memory_id=memory.get("id"), # This is the id from create_memory or list_memories actor_id="User84", # This is the identifier of the actor, could be an agent or end-user. session_id="OrderSupportSession1", messages=[ ("Hi, I'm having trouble with my order #12345", "USER"), ("I'm sorry to hear that. Let me look up your order.", "ASSISTANT"), ("lookup_order(order_id='12345')", "TOOL"), ("I see your order was shipped 3 days ago. What specific issue are you experiencing?", "ASSISTANT"), ("Actually, before that - I also want to change my email address", "USER"), ( "Of course! I can help with both. Let's start with updating your email. What's your new email?", "ASSISTANT", ), ("newemail@example.com", "USER"), ("update_customer_email(old='old@example.com', new='newemail@example.com')", "TOOL"), ("Email updated successfully! Now, about your order issue?", "ASSISTANT"), ("The package arrived damaged", "USER"), ], ) # Wait for meaningful memories to be extracted from the conversation. time.sleep(60) # Query for the summary of the issue using the namespace set in summary strategy above memories = client.retrieve_memories( memory_id=memory.get("id"), namespace=f"/summaries/User84/OrderSupportSession1/", query="can you summarize the support issue" )