Chatbot / README.md
yashAI007's picture
update README.md with claud
6b470db

A newer version of the Gradio SDK is available: 6.10.0

Upgrade
metadata
title: Chatbot
emoji: πŸ’»
colorFrom: yellow
colorTo: green
sdk: gradio
sdk_version: 6.6.0
app_file: app.py
pinned: false
short_description: Chatbot

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference

πŸ€– Memory Chatbot

A multi-user, multi-thread AI chatbot with short-term and long-term memory, powered by LangGraph, LangChain, Groq (Qwen3-32B), and a Gradio UI. The chatbot can call a variety of tools and displays which tools were used directly in the chat interface.


✨ Features

Feature Description
🧠 Short-term memory Remembers conversation context within a thread using InMemorySaver
πŸ’Ύ Long-term memory Stores user preferences, profile, interests, and project info using InMemoryStore
πŸ‘₯ Multi-user support Each user has isolated memory and conversation threads
🧡 Multi-thread support Each user can have multiple independent chat sessions
πŸ”§ Tool use 12 built-in tools (web search, weather, calculator, Python exec, and more)
🏷️ Tool call badges The UI shows which tools were called for each AI response
⚑ Fast inference Powered by Groq's ultra-fast LLM API

πŸ—‚οΈ Project Structure

.
β”œβ”€β”€ memory_chatbot.py   # LangGraph graph: memory nodes + agent chat node
β”œβ”€β”€ app.py              # Gradio UI with multi-user / multi-thread support
β”œβ”€β”€ tool.py             # All tool definitions (12 tools)
β”œβ”€β”€ .env                # API keys (not committed)
└── README.md

🧩 Architecture

User Message
     β”‚
     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ memory_analyzer β”‚  ← Detects if message contains info worth storing long-term
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ memory_retrieval β”‚  ← Searches long-term store and injects relevant memories
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   chat_node   β”‚  ← LangChain agent with 12 tools; returns answer + tool log
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
    AI Response
  + Tool Call Badges

Memory Types

  • Short-term (checkpointer): Full conversation history per thread_id, managed automatically by LangGraph's InMemorySaver.
  • Long-term (store): Key-value memories namespaced by (user_id, category). Categories: preferences, profile, interests, project.

πŸ”§ Tools

Tool Description
tool_tavily Web search via Tavily API
time_date Returns today's date
calculator Evaluates math expressions
python_exec Executes arbitrary Python code
get_weather Current weather for any city
wikipedia_search Wikipedia summary search
scrape_website Extracts text from a URL
read_file Reads a local file
format_json Pretty-prints JSON
generate_sql Converts natural language to SQL
system_info Returns OS/platform info
save_user_preference Saves a user preference to memory

πŸš€ Setup

1. Clone & install dependencies

git clone <your-repo-url>
cd memory-chatbot
pip install -r requirements.txt

Key dependencies:

langgraph
langchain
langchain-groq
langchain-tavily
gradio
wikipedia
beautifulsoup4
requests
python-dotenv

2. Configure API keys

Create a .env file in the project root:

GROQ_API_KEY=your_groq_api_key
TAVILY_API_KEY=your_tavily_api_key

Get your keys:

3. Run

python app.py

Then open http://localhost:7860 in your browser.


πŸ–₯️ UI Guide

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  πŸ‘€ Users       β”‚                                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚   [Chat history appears here]        β”‚
β”‚  β”‚ user_abc β”‚   β”‚                                      β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚   User: What's the weather in Paris? β”‚
β”‚  [βž• New User]  β”‚                                      β”‚
β”‚                 β”‚   AI: It's 18Β°C and sunny in Paris.  β”‚
β”‚  🧡 Threads     β”‚   πŸ”§ get_weather                     β”‚
β”‚  β—‹ thread_123   β”‚                                      β”‚
β”‚  ● thread_456   β”‚                                      β”‚
β”‚  [βž• New Chat]  β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚                 β”‚   β”‚ Type message and press Enter β”‚    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”˜
  • New User β€” creates an isolated user with fresh memory and a new thread
  • New Chat β€” starts a new thread for the current user (long-term memory is preserved)
  • Tool badges β€” appear below each AI reply showing which tools were called

πŸ” How Tool Display Works

When the agent calls tools, chat_node inspects the returned messages for tool_calls and ToolMessage entries and builds a tool_log list. The Gradio UI renders these as colored HTML badges inline in the chat (Gradio's Chatbot renders HTML by default).

Example badge output:

πŸ”§ get_weather   πŸ”§ wikipedia_search

πŸ“ Configuration

Parameter Location Default Description
model memory_chatbot.py qwen/qwen3-32b Groq model to use
temperature memory_chatbot.py 0 LLM temperature
max_results tool.py (Tavily) 5 Web search result count
memory categories memory_chatbot.py preferences, profile, interests, project Long-term memory namespaces

⚠️ Limitations

  • Memory is in-process only β€” all memory resets when the server restarts. For persistence, replace InMemorySaver and InMemoryStore with database-backed alternatives (e.g., PostgresSaver, RedisStore).
  • python_exec tool executes arbitrary code with no sandboxing β€” use with caution in production.
  • scrape_website does not handle JavaScript-rendered pages.

πŸ› οΈ Extending

Add a new tool: Define it with @tool in tool.py, then add it to the tools list in memory_chatbot.py.

Persist memory to a database: Replace InMemorySaver() with a LangGraph-compatible checkpointer and InMemoryStore() with a persistent store.

Change the LLM: Swap ChatGroq for any LangChain-compatible chat model (OpenAI, Anthropic, etc.).