Exercise 4 of 10 · 0 passed
Multi-turn Conversations
A single message is a prompt. A conversation is a sequence of messages where the model sees everything that came before.
Claude uses an alternating user / assistant list. After each response:
- Append the user message to history
- Call the API with the full history
- Append the assistant reply
- Send everything again on the next turn
Why care? Without history, your assistant forgets after one message. Every real chatbot needs this pattern — and getting the alternation order wrong breaks the API.
Task
Complete the Chat class:
historystarts emptyask(user_msg)appends the user message, calls the API with full history, appends the reply, returns the text
Click "Run tests". First time loads Python in your browser (~5s). After that, runs are instant on this page and ~1s on the others.
Loading tests…
Pass the tests to reveal the reference solution.
The point of the exercise is the struggle, not the answer. Once your tests are green, the reference solution unlocks here so you can compare patterns.
Loading solution…
That's the warm-up.
You ran ten exercises against a mocked SDK. The cohort builds the real thing: an AI agent shipped to production with 150+ passing tests, Telegram bot, FastAPI, Streamlit, Docker. Six weeks. Every PR reviewed.