★ Final Challenge
› Run the Whole Conversation
50 ptsYour chatbot is done: it starts from a system prompt, loops through turns,
remembers the conversation, trims to a budget, and survives flaky calls. The
final challenge is the engine of that app as one function — everything you
built, with the interactive input() loop replaced by a list of scripted
user inputs and the real API replaced by an injected client. It doesn't
mutate user_inputs or return anything shared, so with a deterministic fake
client (as in the tests) it behaves like a pure function; wire in the real
anthropic_client and it's exactly your app's loop, network calls included.
Implement run_conversation(user_inputs, client, system_prompt=None, max_messages=None):
- Start the history the way
make_conversationdoes: empty ifsystem_promptisNone/blank, otherwise one system message with the prompt stripped. - For each string in
user_inputs, in order, run one turn the waychat_turndoes: append the user message, callclient(history)with the full current history, append the assistant reply. - After each turn, if
max_messagesis notNone, trim the history the waytrim_historydoes: keep a leading system message (if present) plus the most recent messages, at mostmax_messagestotal. You may assumemax_messages >= 3when provided. - Return the final history list.
Log in to submit a solution and earn points.