TaskWeaver icon indicating copy to clipboard operation
TaskWeaver copied to clipboard

Is state(variables) saved after a session is shutdown?

Open samantha0-ops opened this issue 1 year ago • 3 comments

After shutting down a session, we want to restart the session and reload all the variables in ipython. In fact we find a update_session_var function in class Environment, but did not find where it is used. So we would like to know if we can reload these variables, and how?

samantha0-ops avatar Dec 26 '23 04:12 samantha0-ops

We currently don't support restoring a closed session. update_session_var is not for this purpose, and it is used to pass arguments into plugins (e.g., keys) in a session. In practice, you can find all the generated code in project/workspace/sessions/xx.json files which record all the information of each round. You can extract the python codes and rerun them in ipython if no plugins were called. Otherwise, you may need to also put the plugin code into ipython as functions.

We have internally discussed this feature before, but failed to see a real use case. Could you help to describe your scenario in a more detailed way so we can better understand this requirement?

liqul avatar Dec 26 '23 04:12 liqul

We are building a chatgpt-like interactive web assistant, which supports over 2000 users per day. If the system keeps a kernel in kernel_manager for every chat session, we think this might put too much burden on the server. So we would like to choose a tricky strategy:

  1. keep the kernel alive when the user is watching the web page.
  2. when the user close the current chat session, we could shutdown this kernel.
  3. if user come back to the chat session, reload and recover this kernel so user can continue the following steps.

But in fact we haven't see such kind of implementations so far, could you share your concerning about this feature? We probably have missed some key points and this strategy might not be a realistic one.

samantha0-ops avatar Dec 26 '23 05:12 samantha0-ops

Thanks for sharing more information.

When we discussed this feature, one challenge was how to take a snapshot of the session. It is fairly easy to store the conversation history, but non-trivial for the code part. We currently don't have restrictions on code generation which means the code can do probably anything like opening a file handler or connecting to a remote service. It is thus hard to restore the session to that state once it is closed. One idea was to re-play all the previously generated code, which however may still not able to recover the previous state because of things like generating a random number.

In general, it is hard to restore an arbitrary session. But in your situation, if you have a clear scope of the variables to persist and you know they are serializable, this actually could be done technically.

liqul avatar Dec 26 '23 05:12 liqul

Close as no more activity

ShilinHe avatar Jan 09 '24 07:01 ShilinHe