Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

systemsthinking-bot — AI Socratic Tutor for Systems Thinking

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.html in a browser — it explains the diagram drawing, the guardrails, and what is (and isn't) simulated.


Student flow

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.

Files

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")

Run locally

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.txt

2. 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:16

Homebrew (macOS):

brew install postgresql@16 && brew services start postgresql@16
createdb stbot && psql stbot -f schema.sql

Hosted: 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/stbot

4. Run

streamlit run app.py

Opens 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.

Known issues

  • 8 tests fail (pytest): 4 in test_guardrails.py call validate_link with its old signature, 3 in test_render.py assert old edge colours / loop labels, 1 in test_llm.py asserts an old prompt string. The code is fine; the tests are stale.
  • The app refuses to start without a reachable database (st.stop() after init_session in app.py).
  • Edge delays (// marks) never appear: the prompt forces has_delay=False, though render.py supports 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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages