Rasa Python API

So I have been building an agent for Rasa using the command line i.e. rasa train, rasa run actions, rasa shell etc. and now I want to try and interface with it with my website. However, is there a way for me to run it in conjunction with my personal Flask backend? Basically, is there a way to create agents and run rasa nlu and core in a regular python script, and just cache the agent and history as a variable in python?

Also, is there a way to set a timeout for my agent? Basically, after like a couple minutes of doing nothing, I want the agent to just delete old sessions to save memory so I am not memorizing the state of every single conversation forever