
LANGCHAIN — What is Langchain Streamlit?
Digital design is like painting, except the paint never dries. — Neville Brody.
Langchain Streamlit is an integration that combines the LangChain and Streamlit libraries to leverage the power of LLMs (Large Language Models) and quickly deliver functional web applications. In this tutorial, we’ll examine how to use the Streamlit Callback Handler to render and examine the thoughts and actions of an LLM agent.
First, you need to initialize the callback handler with a container to write to and then pass it to the agent in the call to run. Here’s the code snippet to achieve this:
# initialize the callback handler with a container to write to
st_callback = StreamlitCallbackHandler(st.container())
# pass it to the agent in the call to run()
answer = agent.run(user_input, callbacks=[st_callback])You can also customize the behavior of the callback handler with advanced options such as choosing whether to expand or collapse each step when it first loads and completes, determining how many steps will render before they start collapsing into a “History” step, and defining custom labels for expanders based on the tool name and input.
To get started, refer to our docs for a complete walkthrough.
Moving forward, LangChain and Streamlit are working on several improvements including extending StreamlitCallbackHandler to support additional chain types like VectorStore, SQLChain, and simple streaming, making it easier to use LangChain primitives like Memory and Messages with Streamlit chat and session_state, and adding more app examples and templates to the langchain-ai/streamlit-agent repository.
If you have ideas, example apps, or want to contribute, please join the LangChain or Streamlit Discord servers. Happy coding! 🎈🦜🔗




