Add conversation memory for multi-turn questions#14
Merged
Conversation
QAAgent.ask now takes an optional conversation_history list of
{"role": "user"|"assistant", "content": str} dicts. When provided, the
past turns are filtered, trimmed to the last max_history_turns
exchanges (default 10), and prepended to the messages array sent to
the Anthropic API. The retrieval and the new question keep their
context-injected formatting on the latest user turn.
Demo mode is unchanged: history only matters when an LLM is actually
called.
Refs #13
st.session_state.messages already kept the full conversation for rendering. Now it is also passed to QAAgent.ask via the new conversation_history parameter, so the assistant can resolve follow-up questions like "and the year before?" against the prior turns. The last message (the user's just-asked question) is excluded to avoid duplication. Refs #13
Five new tests cover: - No history → still sends exactly one user message (no regression) - History is forwarded in the right order with the new question last - max_history_turns trims the oldest exchanges (last N pairs kept) - Unexpected roles, missing content, and non-dict items are filtered - Demo mode accepts conversation_history but ignores it (no API call) Closes #13
eugen-goebel
added a commit
that referenced
this pull request
Jun 2, 2026
Add conversation memory for multi-turn questions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
QAAgent.asknow takes an optionalconversation_historyof{"role": "user"|"assistant", "content": str}dictsmax_history_turnsexchanges (default 10), and prepended to the Anthropicmessagesarrayst.session_state.messages(minus the new turn) so follow-ups like "and the year before?" resolve against prior contextCloses #13
Test plan
pytest -q)