This is my personal project based on the IBM lab Building AI Agents from Scratch with Python. I started with the course's weather and restaurant agents and extended them into a Streamlit web app.
I wanted to understand how an agent can decide which tool to use, find relevant information, and remember parts of a conversation. The project uses Python rules, TF-IDF, and cosine similarity. It does not use ChatGPT, other large language models, or agent frameworks.
The assistant handles two main types of questions:
- Weather: gets current weather for a city using OpenWeather, including temperature, conditions, humidity, and wind when available.
- Restaurant information: searches a FAQ PDF for answers about The Daily Dish, such as its location, opening hours, and reservation information.
It also keeps some context during a session. For example, after asking about weather in Jakarta, you can ask "How humid is it there?" without repeating the city. You can clear the conversation to reset this memory.
The app has four sections: Home, AI Assistant, FAQ, and About the Project. The chat includes suggested questions, weather metrics, and an optional explanation of how each answer was found.
The original lab provided the starting point: a memory agent, a weather agent, a restaurant agent, query preprocessing, and basic routing.
For this version, I added:
- A Streamlit interface instead of only a terminal chat loop.
- City selection from questions instead of always using one fixed city.
- Follow-up questions using session memory, with separate memory for each user.
- HTTPS requests, timeouts, and clearer handling of API errors.
- More consistent query normalization and checks for weak or ambiguous FAQ matches.
- Separate Python modules so the app and enhanced notebook use the same agent logic.
- Automated tests, a small retrieval evaluation, and deployment instructions.
I kept the original notebook unchanged and created a separate enhanced notebook to explain the changes.
flowchart LR
UI[Streamlit app] --> C[Chatbot]
C --> P[Query processor]
C --> R[Query router]
R --> W[Weather agent]
R --> D[Restaurant agent]
C <--> M[Session memory]
W <--> M
W --> API[OpenWeather API]
D --> PDF[Restaurant FAQ PDF]
The query processor normalizes text and handles a small set of synonyms. The router uses rules to choose an agent, respond to greetings and help questions, or ask for clarification.
The weather agent calls OpenWeather's current weather API. It remembers the last successful city and previously retrieved observations within the session.
The restaurant agent extracts question-and-answer pairs from a PDF. TF-IDF gives more weight to useful words, and cosine similarity compares the user's question with the FAQ questions. If a match passes the retrieval checks, the agent returns the answer from the document. It does not generate new restaurant information. The similarity score is a measure of word overlap, not a probability that the answer is correct.
The memory agent stores a limited amount of temporary context in a Python dictionary. There is no conversation database or permanent user profile.
This project helped me connect several concepts in one application:
- Splitting a task between agents with different responsibilities.
- Routing natural language questions using simple, understandable rules.
- Turning text into TF-IDF vectors and comparing them with cosine similarity.
- Connecting to an external API and handling failures.
- Keeping useful context without needing a database.
- Separating notebook experiments from reusable application code.
- Testing features without relying on live API calls.
Python 3.13, Streamlit, scikit-learn, requests, PyMuPDF, python-dotenv, pytest, and Jupyter.
app.py # Streamlit interface
src/
agents.py # Memory, weather, and restaurant agents
query_processor.py # Text processing, routing, and city extraction
chatbot.py # Connects the components
notebooks/ # Enhanced educational notebook
data/ # Local restaurant FAQ PDF and setup notes
tests/ # Automated tests and synthetic test data
scripts/ # Evaluation, notebook checks, and packaging
docs/ # Deployment guide and test results
.streamlit/config.toml # App theme and settings
requirements.txt
requirements-dev.txt
.env.example
IMPLEMENTATION_PLAN.md
NOTICE.md
The original reference is Building AI Agents from Scratch - Weather Agent Daily Dish.ipynb. The enhanced version is notebooks/Building AI Agents from Scratch - Enhanced Multi-Agent System.ipynb. Both are kept out of the public deployment package while redistribution permissions are unresolved.
Create and activate a virtual environment:
python -m venv .venvOn Windows PowerShell:
.venv\Scripts\Activate.ps1On macOS or Linux:
source .venv/bin/activateInstall the dependencies:
python -m pip install -r requirements.txtCopy .env.example to .env and add your own OpenWeather key:
OPENWEATHER_API_KEY=your_api_key_here
DEFAULT_CITY=Jakarta
RESTAURANT_PDF_PATH=data/The-Daily-Dish-FAQ.pdfPlace an authorized copy of the restaurant FAQ PDF at that path. See data setup for the source and supported format. The restaurant agent expects extractable text with Q: and A: blocks; it cannot read scanned pages without OCR.
Start the app:
python -m streamlit run app.pyOpen the local URL shown in the terminal, usually http://localhost:8501. Restart the app after changing the key or PDF.
You can also use environment variables or Streamlit Secrets. If the key or PDF is missing, the app explains which feature needs configuration. Jakarta is the default weather city; it is not assumed to be the restaurant's location.
If you get a missing dotenv error or your .env is not loading, install the package in the same environment:
python -m pip install python-dotenvThe app can still use environment variables or Streamlit Secrets without this package.
- What is the weather in New York?
- What is the temperature in Yogyakarta?
- How humid is Jakarta?
- How humid is it there?
- Where is The Daily Dish located?
- What are the restaurant's opening hours?
- How can I make a reservation?
- Does the restaurant offer vegetarian options?
Restaurant answers depend on what is actually in the PDF. Asking about weather near the restaurant also requires a city that the app can identify from its documented location.
The original notebook is the course reference and has been left byte-for-byte unchanged. The enhanced notebook explains the improvements through Markdown, code, and demonstrations. It imports the same modules as the app so there are not two different implementations to maintain.
To run the enhanced notebook, install requirements-dev.txt and open it in Jupyter. Its default demonstrations use clearly labeled synthetic FAQ data and mocked weather responses, so they can run without an API key. These examples are not real restaurant facts or live weather readings.
python -m pip install -r requirements-dev.txt
python -m pytest -q
python -m scripts.evaluateThe latest local test run passed 72 tests. These cover weather API responses and failures, PDF parsing, retrieval, routing, memory, and Streamlit interactions. All 13 code cells in the enhanced notebook also executed successfully.
The retrieval evaluation uses a small synthetic dataset. It compares the original retrieval approach with the updated version using exact questions, paraphrases, irrelevant questions, and ambiguous questions. It is useful for checking behavior, but it does not establish accuracy on the real restaurant PDF. The holdout examples were also inspected during debugging, so they are now regression tests rather than an independent benchmark.
More details are in the test report and evaluation results. Real API behavior, retrieval against the actual restaurant document, and desktop/mobile browser checks still need further validation.
The app is prepared for Streamlit Community Cloud, using app.py as the entry point. There is no verified public deployment URL yet.
See the deployment guide for GitHub setup, secrets, dependencies, and checks to run after deploying. The packaging script creates an app-only archive:
python scripts/package_public.pyIt excludes local secrets, PDFs, and both notebooks. Check the document and dependency licenses before publishing, and only include a restaurant PDF if you have permission to redistribute it.
This is a learning project, and the simple approach has limits:
- Rules can miss unfamiliar wording or route some questions incorrectly.
- TF-IDF compares words, so it can miss meaning or return an imperfect match. Retrieval thresholds still need evaluation on the real FAQ.
- Weather depends on the API key, service availability, and request limits. Only current weather is supported; previous session readings are not historical weather data or forecasts.
- Memory only lasts within the active session and keeps a limited amount of context.
- The assistant cannot make reservations, place orders, process payments, or check live table availability.
My next steps would be to evaluate more real FAQ questions, improve the supported query patterns, check the interface on different screen sizes, and verify a public deployment.