def submit(): user_message = st.session_state['user_input'] if user_message: st.session_state.history.append(("user", user_message)) result = run_agent_once(user_message, client, collection, user_id=username) st.session_state.history.append(("agent", result["formatted"])) if 'empty_key' not in st.session_state: st.session_state.empty_key='' st.session_state.empty_key=st.session_state.user_input # if you set user_input to a blank valueto clear the prompt, streamlit throws an error st.session_state.user_input = '' st.set_page_config(page_title="AI Book Finder Agent", layout='wide') st.title('AI Book Finder Agent') st.sidebar.header('Session') username = st.sidebar.text_input('Enter you profile name', value='Default user') if username: CHROMA_DIR = f'.chroma_db_{username}' else: CHROMA_DIR = '.chroma_db' client,collection = init_chromadb(CHROMA_DIR) if 'history' not in st.session_state: st.session_state.history = [] chat_container = st.container() with chat_container: for role, text in st.session_state.history: if role == "user": st.markdown(f"