Session state contamination happening in concurrent agno agent instants

In a concurrent system setup (example: celery worker with --pool=thread configuration) and SQLite storage, multiple concurrent agno agents are initialized, and each one has its own session_state and tools. Now, the issue is that even if you pass session_id during agent initialization and during .run, there seems to be a session_state mix-up happening.

But there seems to be no contamination on the message thread—only with session_state.

And there is no contamination happening if I run the agents concurrently in a multiprocess system. This suggests some memory contamination is happening when multiple agents are initialized in the multi thread with shared memory.

Hey @arun477
thanks for reaching out and supporting Agno. I’ve shared this with the team, we’re working through all requests one by one and will get back to you soon.
If it’s urgent, please let us know. We appreciate your patience!

Hi @arun477
Are you using the same session ID for all the agents?

No @Dirk each has its own unique session id. And i can see in db(sqlite storage) i can clearly see different sessions proper chat history but duplicate session state between both sessions.

Issue is specifically with session_state when two concurrent agents with different session id. not always but most of the time. Main message thread not contaminated only session_state.

To replicate:
Try celery worker with concurrent setup with sqlite storage, use any tool which interact with session state and try to run workers concurrently with (thread, prefork), you can replicate the issue.

Hi @Dirk, on a different note, is there any unified API interface to count the token usage stats from the agent? for example, i’m using OpenAI API through ango in different places for different use cases. is there any way to get the total token usage? this would be helpful for me to monitor my usage. if not available, no worries, would be a nice feature.

Thanks!