st.session_state only stores UI state for the current browser session.
1
Install packages
2
Bootstrap clients once
Wrap
Tex and OpenAI in @st.cache_resource so Streamlit does not recreate clients on every interaction:3
Pin a session id per browser tab
Store a stable
sid in session state. You can also read ?uid= from the query string to test different users:4
Show usage in the sidebar
Call
tex.usage.today() to show current quota usage during demos:5
Render chat + handle input
Render messages from
st.session_state.messages, then handle st.chat_input:6
Run the app
http://localhost:8501/?uid=alice and ?uid=bob in two tabs to test isolation.One file
If you want one block to paste, use this fullapp.py:
app.py
Why Streamlit + Tex
This pattern pairs a disposable browser UI with durable memory in Tex.- Refreshes keep memory: Streamlit session state can reset; Tex memory stays.
- No Redis or Postgres for demos: Tex stores the long-term memory.
- Visible recall: the expander shows exactly what the model saw.

