sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

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

Open seandkendall opened this issue 11 months ago • 1 comments

Checks

  • [x] I have updated to the lastest minor and patch version of Strands
  • [x] I have checked the documentation and this is not expected behavior
  • [x] 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

seandkendall avatar Dec 13 '25 17:12 seandkendall

This is similar to #1393 - Strands follows the Bedrock model, and Bedrock represents tool results as USER generated since they're generated client-side.

Closing as "by-design".

I don't expect that we'll change that any time soon, but if you think such a feature is worthwhile, please file a feature request

zastrowm avatar Dec 31 '25 18:12 zastrowm