https://github.com/langchain-ai/streamlit-agent
Reference implementations of several LangChain agents as Streamlit apps
https://github.com/langchain-ai/streamlit-agent
Last synced: 7 months ago
JSON representation
Reference implementations of several LangChain agents as Streamlit apps
- Host: GitHub
- URL: https://github.com/langchain-ai/streamlit-agent
- Owner: langchain-ai
- License: apache-2.0
- Created: 2023-06-13T04:15:45.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-04T14:55:12.000Z (over 1 year ago)
- Last Synced: 2025-04-11T19:59:39.713Z (8 months ago)
- Language: Python
- Homepage:
- Size: 11.9 MB
- Stars: 1,437
- Watchers: 17
- Forks: 701
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- StarryDivineSky - langchain-ai/streamlit-agent - ai/streamlit-agent 是一个基于 LangChain 框架的开源项目,通过 Streamlit 构建了多个可交互的代理(Agent)演示应用,旨在帮助开发者快速理解和实践 LangChain 的代理功能。项目的核心目标是通过可视化界面展示 LangChain 的代理设计模式,使用户能够直观地体验代理如何与语言模型、工具和外部系统协作完成任务。每个 Streamlit 应用对应一个特定的代理实现,例如支持多步骤任务规划、工具调用、记忆功能等,开发者可通过 Web 界面实时调整参数、查看代理的决策过程和结果输出。 项目特色在于将 LangChain 的代理架构与 Streamlit 的快速开发能力结合,无需复杂配置即可运行演示应用。用户可通过界面直接与代理交互,观察代理如何解析用户指令、调用工具、生成回答,并通过可视化组件(如图表、日志面板)实时追踪代理的运行状态。此外,项目提供了完整的代码示例和文档,便于开发者学习如何自定义代理逻辑、集成外部 API 或扩展工具集。工作原理上,每个代理基于 LangChain 的 AgentExecutor 框架,通过 Streamlit 的组件封装用户输入和代理输出,形成闭环交互流程,同时支持动态调整代理的提示词、工具配置和记忆模块,帮助开发者深入理解代理的工作机制和优化方向。该项目适合 LangChain 入门者快速上手实践,也适合需要可视化调试代理行为的开发者参考使用。 (A01_文本生成_文本对话 / 大语言对话模型及数据)
- awesome_ai_agents - Streamlit Agent by Langchain - This repository showcases various LangChain agents as Streamlit apps, including a basic streaming app, a memory-based conversation app, a demo replicating MRKL functionality, a minimal agent with search capability, chatbots with feedback options, document querying, database communication, and pandas DataFrame interaction, featuring LangChain and Streamlit integrations [github](https://github.com/langchain-ai/streamlit-agent) | [github profile](https://github.com/langchain-ai) (Learning / Repositories)
README
# 🦜️🔗 LangChain 🤝 Streamlit agent examples
[](https://codespaces.new/langchain-ai/streamlit-agent?quickstart=1)
This repository contains reference implementations of various LangChain agents as Streamlit apps including:
- `basic_streaming.py`: Simple streaming app with `langchain.chat_models.ChatOpenAI` ([View the app](https://langchain-streaming-example.streamlit.app/))
- `basic_memory.py`: Simple app using `StreamlitChatMessageHistory` for LLM conversation memory ([View the app](https://langchain-st-memory.streamlit.app/))
- `mrkl_demo.py`: An agent that replicates the [MRKL demo](https://python.langchain.com/docs/modules/agents/how_to/mrkl) ([View the app](https://langchain-mrkl.streamlit.app))
- `minimal_agent.py`: A minimal agent with search (requires setting `OPENAI_API_KEY` env to run)
- `search_and_chat.py`: A search-enabled chatbot that remembers chat history ([View the app](https://langchain-chat-search.streamlit.app/))
- `simple_feedback.py`: A chat app that allows the user to add feedback on responses using [streamlit-feedback](https://github.com/trubrics/streamlit-feedback), and link to the traces in [LangSmith](https://docs.smith.langchain.com/) ([View the app](https://langsmith-simple-feedback.streamlit.app/))
- `chat_with_documents.py`: Chatbot capable of answering queries by referring custom documents ([View the app](https://langchain-document-chat.streamlit.app/))
- `chat_with_sql_db.py`: Chatbot which can communicate with your database ([View the app](https://langchain-chat-sql.streamlit.app/))
- `chat_pandas_df.py`: Chatbot to ask questions about a pandas DF (Note: uses `PythonAstREPLTool` which is vulnerable to arbitrary code execution,
see [langchain #7700](https://github.com/langchain-ai/langchain/issues/7700))
Apps feature LangChain 🤝 Streamlit integrations such as the
[Callback integration](https://python.langchain.com/docs/modules/callbacks/integrations/streamlit) and
[StreamlitChatMessageHistory](https://python.langchain.com/docs/integrations/memory/streamlit_chat_message_history).
## More great app examples
Check out some other full examples of apps that utilize LangChain + Streamlit:
- [Auto-graph](https://auto-graph.streamlit.app/) - Build knowledge graphs from user-input text ([Source code](https://github.com/langchain-ai/langchain-benchmarks/blob/main/extraction/streamlit_app.py))
- [Web Explorer](https://web-explorer.streamlit.app/) - Retrieve and summarize insights from the web ([Source code](https://github.com/langchain-ai/web-explorer))
- [LangChain Teacher](https://lang-teacher.streamlit.app/) - Learn LangChain from an LLM tutor ([Source code](https://github.com/langchain-ai/langchain-teacher))
- [Text Splitter Playground](https://langchain-text-splitter.streamlit.app/) - Play with various types of text splitting for RAG ([Source code](https://github.com/langchain-ai/text-split-explorer))
- [Tweet Generator](https://elon-twitter-clone.streamlit.app/) - Fine tune GPT-3.5 on tweets ([Source code](https://github.com/langchain-ai/twitter-finetune))
## Setup
This project uses [Poetry](https://python-poetry.org/) for dependency management.
```shell
# Create Python environment
$ poetry install
# Install git pre-commit hooks
$ poetry shell
$ pre-commit install
```
## Running
```shell
# Run mrkl_demo.py or another app the same way
$ streamlit run streamlit_agent/mrkl_demo.py
```
# Running with Docker
This project includes `Dockerfile` to run the app in Docker container. In order to optimise the Docker Image is optimised for size and building time with cache techniques.
To generate Image with `DOCKER_BUILDKIT`, follow below command
```DOCKER_BUILDKIT=1 docker build --target=runtime . -t langchain-streamlit-agent:latest```
1. Run the docker container directly
``docker run -d --name langchain-streamlit-agent -p 8051:8051 langchain-streamlit-agent:latest ``
2. Run the docker container using docker-compose (Recommended)
Edit the Command in `docker-compose` with target streamlit app
``docker-compose up``
## Contributing
We plan to add more agent and chain examples over time and improve the existing ones - PRs welcome! 🚀