Skip to content

[BUG] AgentCoreMemorySessionManager agent tool use labeled as "role": "USER" #1325

@seandkendall

Description

@seandkendall

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

1.19.0

Python Version

3.13

Operating System

MacOS 26.1 (25B78)

Installation Method

pip

Steps to Reproduce

Use the AgentCoreMemorySessionManager in your strands agent:

agentcore_memory_config = AgentCoreMemoryConfig(
            memory_id=MEMORY_ID,
            memory_name=MEMORY_NAME,
            session_id=session_id,
            actor_id=actor_id,
        )
        session_manager = AgentCoreMemorySessionManager(
            agentcore_memory_config=agentcore_memory_config, region_name=AWS_REGION
        )

Expected Behavior

When AgentCoreMemorySessionManager is persisting an agent response with tool use, it SHOULD label all events with "role": "USER", expected example below:

{
    "events": [
        {
            "memoryId": "<memoryid>",
            "actorId": "<actorid>",
            "sessionId": "<sessionid>",
            "eventId": "<eventid>",
            "eventTimestamp": "<timestamp>",
            "payload": [
                {
                    "conversational": {
                        "content": {
                            "text": "{\"message\": {<end of message>}}"
                        },
                        "role": "ASSISTANT"
                    }
                }
            ],
            "branch": {
                "name": "main"
            }
        },
        {
            "memoryId": "<memoryid>",
            "actorId": "<actorid>",
            "sessionId": "<sessionid>",
            "eventId": "<eventid>",
            "eventTimestamp": "<timestamp>",
            "payload": [
                {
                    "conversational": {
                        "content": {
                            "text": "{\"message\": {\"role\": \"user\", \"content\": [{\"toolResult\": {\"status\": \"success\", \"toolUseId\": \"tool_use_id\", \"content\": [{\"text\": \"Found 10 search results:\"}}}]}, \"message_id\": 0\"}"
                        },
                        "role": "ASSISTANT"
                    }
                }
            ],
            "branch": {
                "name": "main"
            }
        },
        {
            "memoryId": "<memoryid>",
            "actorId": "<actorid>",
            "sessionId": "<sessionid>",
            "eventId": "<eventid>",
            "eventTimestamp": "<timestamp>",
            "payload": [
                {
                    "conversational": {
                        "content": {
                            "text": "{\"message\": {\"role\": \"assistant\", \"content\": [{\"text\": \"I'll help you search for \\\"AWS\\\" on the web!\"}, {\"toolUse\": {\"toolUseId\": \"some_id\", \"name\": \"search\", \"input\": {\"query\": \"aws\"}}}]}, \"message_id\": 0, \"redact_message\": null, \"created_at\": \"2025-12-12T23:34:34.509555+00:00\", \"updated_at\": \"2025-12-12T23:34:34.509557+00:00\"}"
                        },
                        "role": "ASSISTANT"
                    }
                }
            ],
            "branch": {
                "name": "main"
            }
        },
        {
            "memoryId": "<memoryid>",
            "actorId": "<actorid>",
            "sessionId": "<sessionid>",
            "eventId": "<eventid>",
            "eventTimestamp": "<timestamp>",
            "payload": [
                {
                    "conversational": {
                        "content": {
                            "text": "{\"message\": {\"role\": \"user\", \"content\": [{\"text\": \"wSearch the Web for AWS\"}]}, \"message_id\": 0}"
                        },
                        "role": "USER"
                    }
                }
            ],
            "branch": {
                "name": "main"
            }
        }
    ]
}

Actual Behavior

You will notice this is the way the events are stored today with the tool-use being saved as a "USER" action:

{
    "events": [
        {
            "memoryId": "<memoryid>",
            "actorId": "<actorid>",
            "sessionId": "<sessionid>",
            "eventId": "<eventid>",
            "eventTimestamp": "<timestamp>",
            "payload": [
                {
                    "conversational": {
                        "content": {
                            "text": "{\"message\": {<end of message>}}"
                        },
                        "role": "ASSISTANT"
                    }
                }
            ],
            "branch": {
                "name": "main"
            }
        },
        {
            "memoryId": "<memoryid>",
            "actorId": "<actorid>",
            "sessionId": "<sessionid>",
            "eventId": "<eventid>",
            "eventTimestamp": "<timestamp>",
            "payload": [
                {
                    "conversational": {
                        "content": {
                            "text": "{\"message\": {\"role\": \"user\", \"content\": [{\"toolResult\": {\"status\": \"success\", \"toolUseId\": \"tool_use_id\", \"content\": [{\"text\": \"Found 10 search results:\"}}}]}, \"message_id\": 0\"}"
                        },
                        "role": "USER"
                    }
                }
            ],
            "branch": {
                "name": "main"
            }
        },
        {
            "memoryId": "<memoryid>",
            "actorId": "<actorid>",
            "sessionId": "<sessionid>",
            "eventId": "<eventid>",
            "eventTimestamp": "<timestamp>",
            "payload": [
                {
                    "conversational": {
                        "content": {
                            "text": "{\"message\": {\"role\": \"assistant\", \"content\": [{\"text\": \"I'll help you search for \\\"AWS\\\" on the web!\"}, {\"toolUse\": {\"toolUseId\": \"some_id\", \"name\": \"search\", \"input\": {\"query\": \"aws\"}}}]}, \"message_id\": 0, \"redact_message\": null, \"created_at\": \"2025-12-12T23:34:34.509555+00:00\", \"updated_at\": \"2025-12-12T23:34:34.509557+00:00\"}"
                        },
                        "role": "ASSISTANT"
                    }
                }
            ],
            "branch": {
                "name": "main"
            }
        },
        {
            "memoryId": "<memoryid>",
            "actorId": "<actorid>",
            "sessionId": "<sessionid>",
            "eventId": "<eventid>",
            "eventTimestamp": "<timestamp>",
            "payload": [
                {
                    "conversational": {
                        "content": {
                            "text": "{\"message\": {\"role\": \"user\", \"content\": [{\"text\": \"wSearch the Web for AWS\"}]}, \"message_id\": 0}"
                        },
                        "role": "USER"
                    }
                }
            ],
            "branch": {
                "name": "main"
            }
        }
    ]
}

Additional Context

No response

Possible Solution

No response

Related Issues

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions