A chatbot needs to make it clear who said what. `st.chat_message` creates a Streamlit message container styled for a speaker. Pass `"human"` or `"ai"` to show the corresponding avatar and distinguish the messages visually. section 10.2.3
Show a prompt and reply
After `st.chat_input` returns a prompt, display it with `st.chat_message("human").markdown(prompt)`. Generate a reply, then display it with `st.chat_message("ai").markdown(reply)`. You can also write `with st.chat_message("human"):` and put `st.markdown(prompt)` inside the container. section 10.2.3
Displaying a reply is not the same as remembering a conversation. A first-pass chatbot can answer individual prompts yet fail to show earlier exchanges. To show the full conversation, retrieve its message history and render each entry in its own container, using `message.type` for the role and `message.content` for the text. section 10.2.3 section 10.3.2
...
bot = st.session_state.bot
for message in bot.get_history():
st.chat_message(message.type).markdown(message.content)
if human_message_text := st.chat_input("Chat with Nibby!"):
...
This short frontend loop renders saved messages before accepting the next prompt. section 10.3.2
