Skip to content

Implement conversation history persistence between agent turns #3

@coderabbitai

Description

@coderabbitai

Issue Description

Currently, the agent implementation in agent.py does not maintain conversation history between user inputs. Each time a user enters a new query, only that single message is sent to the LLM without any context from previous exchanges.

Why This Matters

This limitation prevents the agent from:

  • Referencing previous user questions or its own answers
  • Building contextual understanding over a conversation
  • Following the prompt instruction to "answer from conversation history"

Proposed Solution

Implement conversation history persistence by:

  1. Creating a conversation_history list at the start of the main loop
  2. Appending each user message to this history
  3. Passing the full history to the agent on each invocation
  4. Saving the assistant's responses back to the history
# Retain full chat history across turns
conversation_history: list[BaseMessage] = []
while True:
    user_input = input("\nYou: ")
    if user_input.lower() in ["quit", "exit"]:
        break
    
    conversation_history.append(HumanMessage(content=user_input))
    inputs = {"messages": conversation_history}
    
    # ... existing code ...
    
    # Save assistant reply to history to preserve context
    conversation_history.append(final_answer)

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions