This repo re‑implements Assignment 1 using LangGraph and extends it with:
- Query classifier – routes user requests to either a structured or unstructured agent.
- Persistent sessions – chat continues across browser tabs/reloads via a
session_id. - Summarised user memory – stores concise, long‑term facts.
- (Bonus) next‑query recommender – TODO (easy to add a new node).
.
├── agents.py # builders for structured/unstructured agents + summary node
├── classifier.py # LLM‑powered router (structured / unstructured / oos)
├── config.py # existing – API keys, logging helper
├── graph.py # LangGraph definition (nodes + routing)
├── memory.py # JSONL checkpoint store (one file per session)
├── tools.py # **provided** helper functions + TOOL_SCHEMAS
├── ui_streamlit.py # Streamlit chat front‑end (with session IDs)
├── requirements.txt # exact version pins
└── README.md # you’re here
# 1. Create env
python -m venv .venv && source .venv/bin/activate
# 2. Install deps
pip install -r requirements.txt
# 3. Export your OpenAI key
export OPENAI_API_KEY=sk‑…
# 4. Prepare the dataset (one‑time)
python data_setup.py # downloads → bitext_df.pkl (~25 MB)
# 5. Launch the chat UI
streamlit run ui_streamlit.pyOpen http://localhost:8501 – the first text box lets you fix your session_id so the agent remembers you across refreshes.
Organises the flow:
┌──────────┐
│classifier│
└─────┬────┘
│structured unstructured│
▼ ▼
┌───────────────┐ ┌────────────────┐
│structured_node│ │unstructured_node│
└──────┬────────┘ └────────┬───────┘
└───────────────────┬───────┘
▼
┌───────────┐
│ summary │
└────┬──────┘
▼
(end)
Each turn, LangGraph calls persist_checkpoint(session_id, state); reloading a page loads
previous exchanges so the agent remembers.
A tiny LLM call decides whether to store remember::<fact> lines. These are kept in state["memories"] and will be available to any node.
| Symptom | Fix |
|---|---|
| KeyError: OPENAI_API_KEY | Export the key in your shell or a .env file |
OSError: bitext_df.pkl not found |
Run python data_setup.py first |
| Chat forgets history | Re‑use the same session_id; check checkpoints/<id>.jsonl exists |
MIT © 2025 Asaf Cohen