Skip to content

pathakvikash/support_agent

Repository files navigation

AI Support Agent — Appointment Booking App

A command-line AI agent that can book doctor appointments, manage users, check weather, search the web, and look up stock information — all powered by a local LLM (Ollama) and a SQLite database.

How It Works

You chat with an AI assistant in your terminal. The assistant has access to tools it can call automatically:

Tool Description
insert_user Register a new patient
get_user Look up a patient by ID
insert_appointment Book a doctor appointment
get_appointments List appointments for a patient
get_weather Get current weather for a city
search_web Search the internet
get_ticker_info Fetch stock ticker details
get_company_profile Get a company summary
… and more Financial tools for dividends, analyst recommendations, etc.

When you say something like "I want to see a doctor tomorrow at 5 PM", the agent figures out which tool to call and executes it against the SQLite database.

Folder Structure

support_agent/
├── agent.py              # Core Agent class (chat loop, tool execution)
├── cli.py                # Click-based CLI (ask / chat commands)
├── db.py                 # SQLite database connection & table creation
├── llm_client.py         # HTTP client for the Ollama LLM API
├── schemas.py            # Pydantic models (ToolCall, ChatResponse, etc.)
├── tools.py              # @tool decorator + built-in tools (weather, web, stocks)
├── util.py               # Converts Python functions → LLM tool payloads
├── seed_data.py          # Populate the database with sample data
├── .env                  # Environment variables (API keys) — not committed
├── .gitignore
├── models/
│   ├── __init__.py
│   ├── user.py           # insert_user, get_user tools
│   └── appointment.py    # insert_appointment, get_appointments tools
└── venv/                 # Python virtual environment (not committed)

Prerequisites

  • Python 3.10+
  • Ollama running locally (default: http://localhost:11434)
    • Pull a model: ollama pull qwen3.5:latest
  • (Optional) A Tavily API key for web search — set in .env

Setup Instructions (CLI + Web UI)

1. Clone the repo & enter the directory

cd support_agent

2. Create and activate a virtual environment

python -m venv venv

# Windows
venv\Scripts\activate

# macOS / Linux
source venv/bin/activate

3. Install dependencies (single file)

pip install -r requirements.txt

This single requirements.txt includes both CLI and API server dependencies (FastAPI, Uvicorn, SSE).

4. Configure environment variables

Create a .env file in the project root:

TAVILY_API_KEY=your_tavily_api_key_here

5. Initialize the database

python db.py

This creates clinic.db with users and appointments tables.

6. Seed sample data

python seed_data.py
Seed complete: 10 new users, 17 new appointments.

Running it again is safe — duplicates are skipped:

Seed complete: 0 new users, 0 new appointments.

7. Start the agent

Interactive chat:

python cli.py chat

Single question:

python cli.py ask "What is the weather in Mumbai?"

Run the Web UI + API (Developer Mode)

You can launch both the FastAPI backend and Next.js UI with one command.

Windows (PowerShell)

# Optional: first-time install
./run.ps1 -Install

# Subsequent runs
./run.ps1

macOS / Linux (Bash)

chmod +x run.sh
./run.sh --install   # first time only
./run.sh             # subsequent runs

Services:

The UI streams the agent’s execution trace (reasoning → tool → SQL → result → response) in real time.

Example Chat Session

$ python cli.py chat
Agent chat started. Type 'exit' or 'quit' to end the session.

You> Book an appointment with Dr. Ramesh Kumar on April 25 at 3pm for a headache
Calling tool: insert_appointment with {'user_id': 1, 'doctor_name': 'Dr. Ramesh Kumar', 'appointment_date': '2026-04-25 15:00', 'reason': 'headache'}
Your appointment with Dr. Ramesh Kumar has been booked for April 25, 2026 at 3:00 PM.

You> Show my appointments
Calling tool: get_appointments with {'user_id': 1}
Here are your upcoming appointments:
1. Dr. Ramesh Kumar — April 18, 2026 at 10:00 AM (General checkup)
2. Dr. Sunita Verma — April 20, 2026 at 2:30 PM (Blood test follow-up)
3. Dr. Ramesh Kumar — April 25, 2026 at 3:00 PM (Headache)

You> What's the weather in Delhi?
Calling tool: get_weather with {'city': 'Delhi'}
Delhi: ☀️ +38°C

You> exit
Goodbye!

Docker Usage

You can run the app inside a Docker container — no need to install Python or dependencies on your machine.

1. Build the Docker image

docker build -t support-agent .

2. Run the interactive chat

docker run -it support-agent

3. Run a single question

docker run -it support-agent python cli.py ask "What is the weather in Mumbai?"

4. Seed the database with sample data

docker run -it support-agent python seed_data.py

5. Persist the SQLite database (optional)

By default the database lives inside the container and is lost when the container is removed. To keep it across runs, mount a volume:

docker run -it -v support-agent-data:/app support-agent

Or bind-mount a local folder:

docker run -it -v ./data:/app support-agent

Note: The container connects to Ollama on your host machine. If Ollama runs on localhost:11434, you may need to use --network host (Linux) or host.docker.internal (Windows/macOS) so the container can reach it.


Customization

  • Change the LLM model: pass --model <name> to chat or ask.
  • Change the system prompt: pass --instruction "...".
  • Add new tools: create a function in tools.py or a new file under models/, decorate it with @tool, and import the module in cli.py.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors