An AI Socratic tutor that guides students through the Borneo DDT / "Fixes That Fail" case study by building a Causal Loop Diagram (CLD) through conversation, followed by MCQ and Behaviour-Over-Time quizzes.
Companion to flubot. Built for the RC4 Junior Seminar at NUS.
How it works: open
docs/how-it-works.htmlin a browser — it explains the diagram drawing, the guardrails, and what is (and isn't) simulated.
| Phase | What happens |
|---|---|
| Pre-assessment | Student writes their initial mental model in free text; an LLM extracts variables/loops and they are scored silently against the reference model |
| Socratic chat | Tutor asks guiding questions; each reply is structured output (variables, links, loops) |
| CLD | Graphviz diagram redraws live as the guardrails approve each element |
| MCQ quiz | 5 questions on the archetype |
| Behaviour Over Time | Open-ended chat questions, answers judged by an LLM against a reference answer |
| Feedback survey | Anonymous rating for research |
Everything is logged to PostgreSQL. There is no login — each visit gets a random STU-xxxxxxxx ID.
app.py Streamlit entry point — phase routing, session state, all UI
llm.py OpenAI calls — tutor reply (gpt-4o) + BOT evaluator (gpt-4o-mini)
models.py Pydantic schemas, the tutor SYSTEM_PROMPT, the case study text
guardrails.py Validates LLM-proposed variables/links/loops before they enter the graph
render.py Builds the Graphviz DOT for the CLD
assess.py Pre-assessment extraction + fuzzy scoring vs. the reference model
quiz.py MCQ and BOT question banks
logger.py PostgreSQL logging (one fresh connection per call)
schema.sql Database schema
tests/ pytest suite (see "Known issues")
You need Python 3.10+, an OpenAI API key, and a Postgres database. No system Graphviz install is needed — the browser renders the diagram.
1. Install
git clone https://github.com/Bruhoffer/systemsthinking-bot.git
cd systemsthinking-bot
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt2. Start Postgres with the schema loaded (pick one)
Docker (easiest):
docker run -d --name stbot-db \
-e POSTGRES_PASSWORD=stbot -e POSTGRES_DB=stbot -p 5432:5432 \
-v "$PWD/schema.sql:/docker-entrypoint-initdb.d/schema.sql" \
postgres:16Homebrew (macOS):
brew install postgresql@16 && brew services start postgresql@16
createdb stbot && psql stbot -f schema.sqlHosted: any Postgres works (e.g. a free Supabase project) — run schema.sql in its SQL editor and use its connection string.
3. Create .env in the project root:
OPENAI_API_KEY=sk-...
# Docker option:
DATABASE_URL=postgresql://postgres:stbot@localhost:5432/stbot
# Homebrew option (no password): postgresql://localhost:5432/stbot4. Run
streamlit run app.pyOpens at http://localhost:8501. To check the DB connection on its own: python test_db.py.
To let someone on the same network try it, add --server.address 0.0.0.0 and share http://<your-LAN-IP>:8501.
- 8 tests fail (
pytest): 4 intest_guardrails.pycallvalidate_linkwith its old signature, 3 intest_render.pyassert old edge colours / loop labels, 1 intest_llm.pyasserts an old prompt string. The code is fine; the tests are stale. - The app refuses to start without a reachable database (
st.stop()afterinit_sessioninapp.py). - Edge delays (
//marks) never appear: the prompt forceshas_delay=False, thoughrender.pysupports drawing them. - There is no numerical simulation in this bot (flubot has one; this does not). "Behaviour over time" here is a text Q&A.