Skip to content

Conversation

@jeromevdl
Copy link

Description

This PR provides a new SessionManager for Valkey/Redis (Elasticache).

Related Issues

Documentation PR

In Progress...

Type of Change

New feature

Testing

I've created unit tests (see provided code) and integration test (not pushed but here it is):

def test_agent_with_valkey_session():
    valkey_client = valkey.Valkey(host="localhost", port="6379", decode_responses=True, ssl=True, ssl_cert_reqs="none")

    test_session_id = str(uuid4())
    session_manager = ValkeySessionManager(session_id=test_session_id, client=valkey_client)
    try:
        agent = Agent(session_manager=session_manager)
        agent("Hello!")
        assert len(session_manager.list_messages(test_session_id, agent.agent_id)) == 2

        valkey_client_2 = valkey.Valkey(
            host="localhost", port="6379", decode_responses=True, ssl=True, ssl_cert_reqs="none"
        )
        session_manager_2 = ValkeySessionManager(session_id=test_session_id, client=valkey_client_2)
        agent_2 = Agent(session_manager=session_manager_2)
        assert len(agent_2.messages) == 2
        agent_2("Hello!")
        assert len(agent_2.messages) == 4
        assert len(session_manager_2.list_messages(test_session_id, agent_2.agent_id)) == 4

        message = session_manager_2.read_message(test_session_id, agent_2.agent_id, 0)
        assert message.message["content"][0]["text"] == "Hello!"

        message.message["content"][0]["text"] = "Hello World!"
        session_manager_2.update_message(test_session_id, agent_2.agent_id, message)
        message = session_manager_2.read_message(test_session_id, agent_2.agent_id, 0)
        assert message.message["content"][0]["text"] == "Hello World!"

    finally:
        session_manager.delete_session(test_session_id)
        assert session_manager.read_session(test_session_id) is None
  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@dbschmigelski
Copy link
Member

Hi, to take a more scalable approach, Strands Agents is generally trying to avoid merging more implementations of SessionManager into the core SDK. Our new goal is to encourage a vibrant ecosystem of building-block implementations. You can see some of these already highlighted in our Community section on strandsagents.com. If you would be willing to create a repository to store this, and ideally publish on pypi, we would be glad to highlight it on the website as well!

@jeromevdl
Copy link
Author

@dbschmigelski
I agree for this one, but I think the DynamoDB one should be part of the core, see #873, it makes much more sense than a FileSessionManager and is faster than S3. WDYT ?

@jeromevdl jeromevdl closed this Oct 16, 2025
@jeromevdl
Copy link
Author

Also the community page only contains tools and models... where should go a session manager ?

@jeromevdl
Copy link
Author

For interested people, see https://github.com/jeromevdl/strands-valkey-session-manager

I've also created a PR in the documentation to have a mention of this in the community page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants