AgentCoreMemorySessionManager discards the two boto3 clients MemoryClient builds; boto_session and boto_client_config are not passed through
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 84/100
Hướng nghiên cứu
Bắt đầu tại src/bedrock_agentcore/memory/integrations/strands/session_manager.py ở AgentCoreMemorySessionManager.init, sau đó kiểm tra MemoryClient.init trong memory/client.py:76-80. Chạy reproduction được cung cấp cho no-session và warm-session; được xem là hoàn tất khi MemoryClient sử dụng cùng session với các override client, không thay đổi public signature, và hành vi timing và region được báo cáo đã được sửa.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
AgentCoreMemorySessionManager.__init__ builds its MemoryClient without a boto3 session, then overwrites both clients MemoryClient just created with clients from a different session.
# src/bedrock_agentcore/memory/integrations/strands/session_manager.py, 1.23.1
self.memory_client = MemoryClient(region_name=region_name) # :151
session = boto_session or boto3.Session(region_name=region_name) # :152
...
self.memory_client.gmcp_client = session.client( # :195
"bedrock-agentcore-control", region_name=..., config=client_config
)
self.memory_client.gmdp_client = session.client( # :198
"bedrock-agentcore", region_name=..., config=client_config
)
MemoryClient.__init__ accepts boto3_session (memory/client.py:76-80) and would use it. Since it isn't passed, MemoryClient creates its own boto3.Session() and builds bedrock-agentcore-control and bedrock-agentcore clients from it. Lines 195 and 198 then replace both. Those two clients are built and thrown away on every instantiation.
botocore caches the parsed service model per boto3.Session, so a fresh session pays that load again every time.
boto_session and boto_client_config are both in the signature and documented in the docstring. Neither reaches MemoryClient.
Cost
We build a session manager per invoke, so this runs on every turn. We also pass a long-lived boto_session, which is what the parameter is for, and that's where this hurts most. The injected session only reaches the override clients. MemoryClient still cold-builds its own session, and that cold build is nearly all of the remaining time.
Medians over 10 iterations after a warm-up, from the script below:
| caller | as shipped | with the fix below |
|---|---|---|
passes boto_session (a long-lived session) |
42 ms | 3.3 ms |
passes no boto_session |
97 ms | 41 ms |
Five consecutive runs ranged 40.3 to 43.9 ms against 3.2 to 3.5 ms for the first row, and 95.3 to 98.9 ms against 39.9 to 44.1 ms for the second.
These are from an M-series laptop. On a warm AgentCore runtime the per-turn cost is in the same range, 37 to 51 ms. The first construction on a cold container is higher, because the service-model load and credential resolution happen then.
To Reproduce
import os, statistics, time
os.environ["AWS_CONFIG_FILE"] = "/dev/null"
os.environ["AWS_SHARED_CREDENTIALS_FILE"] = "/dev/null"
os.environ["AWS_ACCESS_KEY_ID"] = "AKIAIOSFODNN7EXAMPLE"
os.environ["AWS_SECRET_ACCESS_KEY"] = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
os.environ["AWS_EC2_METADATA_DISABLED"] = "true"
import boto3
from botocore.config import Config
from bedrock_agentcore.memory.client import MemoryClient
REGION = "us-west-2"
CFG = Config(user_agent_extra="strands-agents") # what :184-192 builds
def pair(s): # the :195/:198 overrides
s.client("bedrock-agentcore-control", region_name=REGION, config=CFG)
s.client("bedrock-agentcore", region_name=REGION, config=CFG)
# A long-lived session the caller passes as boto_session, primed once.
WARM = boto3.Session(region_name=REGION)
pair(WARM)
def no_session_shipped(): # boto_session=None, as shipped
MemoryClient(region_name=REGION)
pair(boto3.Session(region_name=REGION))
def no_session_fixed():
s = boto3.Session(region_name=REGION)
MemoryClient(region_name=REGION, boto3_session=s)
pair(s)
def warm_session_shipped(): # boto_session=WARM, as shipped
MemoryClient(region_name=REGION)
pair(WARM)
def warm_session_fixed():
MemoryClient(region_name=REGION, boto3_session=WARM)
pair(WARM)
for name, fn in (("no session, shipped", no_session_shipped),
("no session, fixed", no_session_fixed),
("warm session, shipped", warm_session_shipped),
("warm session, fixed", warm_session_fixed)):
fn() # warm-up
samples = []
for _ in range(10):
t0 = time.perf_counter(); fn()
samples.append((time.perf_counter() - t0) * 1000)
print(f"{name:22s} {statistics.median(samples):6.1f} ms")
Run it with no AWS profile set. It makes no network calls, so the dummy keys only stop botocore from searching for real ones.
Expected behavior
MemoryClient should be built from the same session the overrides use. Hoisting line 152 above line 151 and passing the session through is enough:
session = boto_session or boto3.Session(region_name=region_name)
self.memory_client = MemoryClient(region_name=region_name, boto3_session=session)
No public signature changes. Callers who pass boto_session get the 42 to 3.3 ms drop, and callers who don't still save the second service-model load.
Two related points:
-
boto_client_configcan't be forwarded the same way.MemoryClient.__init__takes onlyregion_name,integration_sourceandboto3_session, and builds its ownConfig(user_agent_extra=...)internally. Honouring the documentedboto_client_configmeans adding a parameter there. Until then, retry and timeout config can't be set on the memory client at all. -
With
region_name=Noneand aboto_sessionpinned to one region,MemoryClient.region_nameresolves from a fresh default session while the clients actually used come fromboto_session. The attribute can disagree with the region serving the calls. Passing the session fixes that too.
Happy to test a patch against our workload. I didn't open a PR because CONTRIBUTING.md says the repo isn't accepting external ones.
Environment
bedrock-agentcore1.23.1. Also present onmainat cc980d14, the most recent commit to touch this file.- boto3 1.43.101, botocore 1.43.101
- Python 3.13.13, macOS
- Also reproduces on 1.18.1
- Ngôn ngữ chính
- Python
- Star
- 776
- Fork
- 153
- Merge trung bình
- 1 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 15
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của aws/bedrock-agentcore-sdk-python
-
bug high-severity
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
aws/bedrock-agentcore-sdk-python#698 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug high-severity
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
aws/bedrock-agentcore-sdk-python#680 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] update_message fails with parameter validation error when SessionMessage.message_id is a Strands positional integer indexCó thể đã có người làm @citizen204 đã nhận 100 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
aws/bedrock-agentcore-sdk-python#556 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
CodeInterpreter should not require a region argumentCó thể đã có người làm @citizen204 đã nhận 115 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
aws/bedrock-agentcore-sdk-python#511 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
aws/bedrock-agentcore-sdk-python#496 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của aws/bedrock-agentcore-sdk-python
Issue tương tự
-
HTML: <template> content is extracted as document textCó thể đã có người làm @ryanmeowy đã nhận hôm nay. Đang mởbug html
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
docling-project/docling#4714 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] Qdrant RAG client applies score_threshold to raw cosine similarity, not the 0-1 score it returnsCó thể đã có người làm @roydonsequeira đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Host test failure in core/direct_io.zig on Linux kernel 6.17: O_DIRECT open succeeds on procfs, so the test's 'plain' fd is not plainCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ashhart/TensorFold#536 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area/install-update comp/cli duplicate P2 python:uv sweeper:risk-compatibility type/bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
NousResearch/hermes-agent#135440 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Deepak3699/Ai_Mentor#244 ·
Maintainer thường phản hồi trong vòng 1 ngày