Skip to content

An intelligent chatbot built with LangGraph that uses conditional tool routing, reflection-based validation, and multi-tool reasoning for high-quality responses.

License

Notifications You must be signed in to change notification settings

vivek34561/Chatbot_with_Websearch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

title emoji colorFrom colorTo sdk sdk_version app_file pinned
Smart GPT with Tools
๐Ÿค–
blue
green
streamlit
1.32.0
frontend.py
false

๐Ÿค– Smart GPT with Tools โ€“ Intelligent LangGraph Chatbot

Python LangGraph LangChain Groq Streamlit

An intelligent chatbot built with LangGraph that uses conditional tool routing, reflection-based validation, and multi-tool reasoning for high-quality responses.

โœจ Features โ€ข ๐Ÿ—๏ธ Architecture โ€ข ๐Ÿ“ Project Structure โ€ข ๐Ÿš€ Quick Start โ€ข ๐Ÿ”ฌ How It Works


๏ฟฝ๐ŸŽฏ Overview

Smart GPT with Tools is a LangGraph-powered conversational AI system that intelligently decides:

  • when to answer directly,
  • when to use external tools,
  • and when to reflect and improve its own responses.

Unlike linear chat pipelines, this system uses graph-based control flow to route queries through tools, validation, and refinement stages before delivering the final answer.

The result is a chatbot that is faster, more accurate, and more reliable.


๐Ÿ’ก Why This Project

Traditional chatbots:

  • Call tools unnecessarily
  • Return unverified answers
  • Lack self-correction

This project demonstrates how to build:

  • conditional reasoning flows,
  • reflection-based quality assurance,
  • and tool-augmented intelligence

It closely resembles production-grade agent systems used in real-world GenAI applications.


โœจ Features

๐ŸŽฏ Intelligent Routing

  • Conditional tool execution using LangGraph
  • Direct LLM responses for simple questions
  • Automatic decision-making by the model

๐Ÿ”ง Multi-Tool Capabilities

  • DuckDuckGo web search for real-time information
  • Calculator for mathematical expressions
  • Easily extensible tool interface

๐Ÿ” Quality Assurance

  • Reflection node validates every response
  • Improves clarity, correctness, and completeness
  • Prevents low-quality or partial answers

๐Ÿ’ฌ Advanced Chat Experience

  • Conversation history with memory
  • Multi-threaded chat sessions
  • Persistent state using checkpointer
  • Streaming token-by-token responses

๐Ÿ—๏ธ Architecture

High-Level Flow


User Query
โ”‚
โ–ผ
Chat Node
โ”‚
โ–ผ
Conditional Router
โ”‚
โ”œโ”€โ”€โ–บ Tool Execution (Search / Calculator)
โ”‚           โ”‚
โ”‚           โ–ผ
โ”‚       Chat Node
โ”‚
โ””โ”€โ”€โ–บ Reflection Node
โ”‚
โ–ผ
Final Response

Why LangGraph

LangGraph enables:

  • conditional edges
  • tool-aware routing
  • validation loops
  • clean separation of responsibilities

๐Ÿ”ฌ How It Works

1. Chat Node

Receives user input and invokes the LLM with tool bindings.

2. Conditional Router

Inspects the LLM output:

  • tool call detected โ†’ route to tool execution
  • no tool needed โ†’ route directly to reflection

3. Tool Execution

Executes requested tools such as:

  • web search
  • calculator

4. Reflection Node

Evaluates the response for:

  • correctness
  • clarity
  • completeness

Improves the answer if needed before returning it.

5. Memory Management

  • Thread-based conversation separation
  • Full chat history retained per session
  • Supports multi-user and multi-chat workflows

๐Ÿ› ๏ธ Tech Stack

Component Technology
Orchestration LangGraph
LLM Framework LangChain
LLM Provider Groq
Web Search DuckDuckGo
UI Streamlit
Language Python

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.8+
  • Groq API key

Environment Setup

Create a .env file:


GROQ_API_KEY=your_groq_api_key

Install Dependencies

pip install -r requirements.txt

Run the App

streamlit run frontend.py

The app will open at http://localhost:8501.


๐Ÿ“ Project Structure

Smart_Gpt_with_tools/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ states/
โ”‚   โ”‚   โ””โ”€โ”€ state.py              # ChatState definition
โ”‚   โ”œโ”€โ”€ llms/
โ”‚   โ”‚   โ””โ”€โ”€ llm.py                # LLM + tool setup
โ”‚   โ”œโ”€โ”€ nodes/
โ”‚   โ”‚   โ””โ”€โ”€ node.py               # Chat, router, reflection nodes
โ”‚   โ””โ”€โ”€ graphs/
โ”‚       โ””โ”€โ”€ graph_builder.py      # LangGraph construction
โ”œโ”€โ”€ backend.py                    # Chatbot initialization
โ”œโ”€โ”€ frontend.py                   # Streamlit UI
โ”œโ”€โ”€ requirements.txt              # Dependencies
โ”œโ”€โ”€ pyproject.toml                # Project config
โ””โ”€โ”€ README.md

๐Ÿงช Example Queries

Direct response:

  • What is Python?
  • Explain machine learning

Tool-based:

  • What is 456 * 789?
  • Latest news about AI
  • Current weather in New York

๐Ÿ”ง Customization

Change LLM Model

Edit src/llms/llm.py:

llm = ChatGroq(model="your-model-name")

Add New Tools

@tool
def custom_tool(input: str) -> str:
    return result

Modify Routing Logic

Edit route_tools() in src/nodes/node.py.

Improve Reflection Logic

Customize prompts in reflect_node().


๐Ÿš€ Deploy to Hugging Face Spaces

  1. Create a new Space โ†’ SDK: Streamlit
  2. Upload this repository
  3. Add GROQ_API_KEY in Space Secrets
  4. App runs automatically using frontend.py

๐Ÿ“Š Why This Project Stands Out

  • Not a basic chatbot
  • Demonstrates agentic reasoning
  • Uses reflection and validation
  • Clean, scalable architecture
  • Directly aligned with real-world GenAI systems

๐Ÿ”ฎ Future Improvements

  • Tool result caching
  • More specialized tools
  • Confidence-based refusal
  • Evaluation metrics dashboard
  • Multi-agent extensions

๐Ÿ‘จโ€๐Ÿ’ป Author

Vivek Kumar Gupta AI Engineering Student | GenAI & Agentic Systems Builder

GitHub: https://github.com/vivek34561 LinkedIn: https://linkedin.com/in/vivek-gupta-0400452b6 Portfolio: https://resume-sepia-seven.vercel.app/


๐Ÿ“„ License

MIT License ยฉ 2025 Vivek Kumar Gupta

Releases

No releases published

Packages

No packages published

Languages