-
Notifications
You must be signed in to change notification settings - Fork 92
Description
Describe the bug
When using AgentCoreMemorySessionManager with a Strands agent that has tools, the agent crashes on any invocation that triggers a tool call. The MessageAddedEvent fires for tool use/result messages, which contain no plain text content. create_message correctly returns None for these, but append_message doesn't guard against it and immediately calls .get() on the None return value.
Stack trace
File "bedrock_agentcore/memory/integrations/strands/session_manager.py", line 571, in append_message
session_message = SessionMessage.from_message(message, created_message.get("eventId"))
AttributeError: 'NoneType' object has no attribute 'get'
Root cause
In session_manager.py, create_message returns None when message_to_payload produces an empty list (i.e. the message has no text content after filtering). The caller append_message doesn't check for this:
line ~570 - missing None guard
created_message = self.create_message(self.session_id, agent.agent_id, SessionMessage.from_message(message, 0))
session_message = SessionMessage.from_message(message, created_message.get("eventId")) # crashes if None
Suggested fix
created_message = self.create_message(self.session_id, agent.agent_id, SessionMessage.from_message(message, 0))
if created_message is None:
return # no text content to persist, skip silently
session_message = SessionMessage.from_message(message, created_message.get("eventId"))
To reproduce
Create an AgentCoreMemorySessionManager and attach it to a Strands Agent with at least one @tool
Send a prompt that triggers the tool
Observe crash on the tool use/result MessageAddedEvent
Environment
bedrock-agentcore: 1.4.1
strands-agents: 1.26.0
Python: 3.12