AI Chat Assistant is a conversational AI application that combines a local large language model with intelligent web search to provide accurate and context-aware responses. Built with LangChain, Ollama, Tavily Search, and Streamlit, the assistant can answer questions using its own knowledge or automatically perform a web search when recent or external information is needed.
- Conversational AI interface built with Streamlit
- Local LLM inference using Ollama
- Intelligent web search with Tavily
- Automatic tool selection using a LangChain Agent
- Persistent chat history stored as JSON
- Start new conversations
- Load previous chats
- Delete chat history
- Displays whether the response came from the local model or web search
The AI Chat Assistant follows a modular architecture where each component has a specific responsibility. The Streamlit interface handles user interactions, the LangChain Agent manages the conversation and decides whether a web search is required, Ollama provides the local language model for reasoning and response generation, Tavily supplies real-time information when needed, and JSON files store chat history for persistent conversations.
User
│
▼
Streamlit Interface
│
▼
LangChain Agent
┌───────────┼───────────┐
│ │ │
▼ ▼ ▼
Ollama LLM Tavily Search JSON Storage
The following workflow illustrates how the assistant processes each user request. The LangChain Agent first analyzes the conversation history and the current question. If the model already has sufficient knowledge, it generates the response directly using the local Ollama model. If additional or up-to-date information is required, the agent automatically rewrites the search query using the conversation context, sends it to Tavily Search, and passes the retrieved results back to the language model. The model then synthesizes a final response, which is displayed to the user and stored locally for future conversations.
User Question
│
▼
Chat History + Current Question
│
▼
LangChain Agent
│
┌───────────────┴────────────────┐
│ │
│ Answer from Model? │ Need Web Search?
│ │
Yes Yes
│ │
▼ ▼
Ollama Generates Answer Rewrite Search Query
│
▼
Tavily Search
│
Search Results
│
▼
Ollama Generates Final Answer
│
▼
Display Response
│
▼
Save Chat History (JSON)
AI-Chat-Assistant/
│
├── app.py # Streamlit user interface
├── main.py # LangChain agent and response generation
├── memory.py # Chat history management
├── history/ # Stores conversation history as JSON files
├── screenshots/ # Project screenshots for the README
├── .env.example # Environment variable template
├── .gitignore # Git ignore rules
├── requirements.txt # Project dependencies
└── README.md # Project documentation
| Technology | Purpose |
|---|---|
| Python | Core programming language |
| Streamlit | Interactive web application interface |
| LangChain | AI agent framework and tool orchestration |
| Ollama | Local LLM inference |
| Qwen3:8B | Large language model for reasoning and response generation |
| Tavily Search | Web search tool for retrieving up-to-date information |
| python-dotenv | Loading environment variables |
| JSON | Persistent storage of chat history |
Follow the steps below to set up the project on your local machine.
git clone https://github.com/<your-username>/ai-chat-assistant.git
cd ai-chat-assistantWindows
python -m venv .venv
.venv\Scripts\activateLinux / macOS
python3 -m venv .venv
source .venv/bin/activatepip install -r requirements.txtDownload and install Ollama for your operating system:
Verify the installation:
ollama --versionPull the Qwen3 8B model:
ollama pull qwen3:8bYou can verify the downloaded models using:
ollama listCreate a free account and generate an API key:
Create a .env file in the project root directory and add your Tavily API key:
TAVILY_API_KEY=your_tavily_api_key
Start the Streamlit application:
streamlit run app.pyAfter the application starts, open the URL displayed in the terminal (typically http://localhost:8501) in your web browser.
The application starts with a clean chat interface and a sidebar containing actions to create a new conversation, delete the current chat, and switch between previously saved conversations.
For general questions, the LangChain Agent determines that web search is unnecessary and generates the response directly using the local Ollama model. The assistant also understands follow-up questions by using the conversation history to maintain context.
When a question requires recent or real-time information, the LangChain Agent automatically invokes the Tavily Search tool. The search results are then provided to the local language model, which generates a concise and natural response.
-
Launch the application using Streamlit.
-
Enter a question in the chat input box.
-
The LangChain Agent analyzes the request and decides whether to:
- Answer directly using the local Ollama model.
- Perform a web search using Tavily when up-to-date information is required.
-
View the response along with its source:
- Model Knowledge – Response generated using the local language model.
- Web Search – Response generated using Tavily Search and synthesized by the local language model.
-
Continue the conversation with follow-up questions. The assistant uses the conversation history to understand context.
-
Use the sidebar to:
- Start a new chat.
- Load previous conversations.
- Delete the current chat.
-
Conversations are automatically saved as JSON files and can be reopened in future sessions.