https://linen.dev logo
Do I need to persist `session` across multiple API...
# 🖥│support-forum
a
I want to ask if i do
composio.create(sessionId)
multiple times, does it create new session each time? If yes, then how to achieve this flow -> user creates session, then chats back and forth. For each sendMessage call, I shouldn't create new session then? In that case I would have to store the session in a in-memory cache?
b
Hello You do not need to store anything about a cache! Sessions are just designed to be ephemeral. Something you can keep recreating if you need to https://docs.composio.dev/docs/users-and-sessions#when-should-i-create-a-new-session
--about a cache-- about a session
a
I read the documentation, my question is -- - if i call the composio.create(sessionID) multiple times, will it create new sessions each time? - Isn't it better to cache the Session and not create it again in next API call in terms of speed?
b
No. It does not impact speed. If you do session.create() with the same user ID and rest of the config. We reuse the session. Only recreated if you change the contract/config.
a
say if i only pass in user id, and calls composio.create() multiple times, in between which a new integration is added, composio would recreate in this case, correct? Even tho the config i pass to create() is same
b
What do you mean by new integration is added? Like the user connected their account? or?
a
Yes, if user connected their gmail now
b
Doesn't recreate the session.
a
So how would I recreate the session then? Since the auth is changed
b
You don't have to recreate a session. Can we get on a quick call. I am trying to understand your use case here.
a
Official docs says this > When should I create a new session? > Create a new session when the config changes: different toolkits, different auth config, or a different connected account. You don't need to store or manage session IDs. Just call create() each time. So won't I have to create a new session when the gmail account is added
b
No. So If you want to choose a different auth config for your user. Or want to specify something specifically then you need to do that. But not in any other case
All the tool auth management for a user, tool discover happens within a session dynamically
a
ahh ok, so if i had multiple gmail accounts for a user and i change from one to another, then a new session is created. otherwise not. But in any case i still have to call the composio.create() in each call correct?
b
*then you need to create a new session Dont call composio.create() in each message. https://docs.composio.dev/cookbooks/chat-app (although you can, that shouldn't matter) But if you want to change something like 1. okay for this user in the chat I want to use their work gmail account now. 2. I want to disable a toolkit. I want to change what tools are available to be executed So basically when you want to change any of the specs of the contract.
a
https://docs.composio.dev/cookbooks/chat-app This example literally calls composio.create() in each message call
But okay, i get the idea now
3 Views