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:

Hi @Dirk,
Now there is option for session id in run method. Is agent stateless now?
Can i use the same agent object to reply to different sessions?

Hi @rvm_1 By passing the session_id in a run method , you can continue runs in the same session.

@monalisha
If calls with multiple sessions to same agent object are made at the same time, Will it cause any conflict or issues?

Hi @rvm_1
This is our first attempt at making the agent stateless. It is not fully stateless, for example the run_response is still available on the agent right after a run, session_state as well, BUT I would say it can be used with multiple sessions on the same agent object. That is definitely the intent from our side. Please let us know where this breaks and we will address it, the goal is for a single agent/team instance to be sufficient.

thanks @Dirk . Just wanted to confirm.