Multiple sessions with same agent

In prod, one agent will be used by multiple users. Each user will have their own session id. Since Agent is created with a fixed session. Does it mean that i have to create separate agent instance for each session id?
It seems inefficient to load same tools, files and data for each session id.

Hi @rvm_1
Thanks for reaching out and for using Agno! I’ve looped in the right engineers to help with your question. We usually respond within 24 hours, but if this is urgent, just let us know, and we’ll do our best to prioritize it.
Appreciate your patience—we’ll get back to you soon! :smile:

Hi @rvm_1
Have you seen Persistent Memory with Postgres - Agno?

This does not address your full concern however. You’ll have to keep track of the session IDs made for different user sessions, then every time the user makes a request, you’ll have to create a unique agent instance for them with that session ID to continue the session. Instantiating sessions is very light-weight however, so it should not add much overhead.

I agree this is not the best developer experience, we will improve it.

Hi
I reply to this because I have a similar case where I also do multiple users management with one team of agents and I’d like to know if I do well or not.
I use this in the case of a chatbot, so my code is divided between api routes.

When a new user comes in, i create a new session_id with agent.new_session() and then store it front side too.
To answer a user message, I get session_id from front, set session_id to agent (agent.session_id = session_id) and then run the agent.

Thanks in advance

Hi @skywabi
This is ok. I would suggest rather creating a new agent object every time, but with the same attached storage. It would still hydrate the session from the storage correctly, which is what you need.

We are planning on making agents more stateless in future so that they would automatically be in the right session when you “run” them.

Hi
Thanks for the advice :slight_smile: