Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pandasai/agent/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ def start_new_conversation(self):
Clears the previous conversation
"""
self.clear_memory()
self._state.last_code_generated = None
self._state.last_prompt_used = None

def _process_query(self, query: str, output_type: Optional[str] = None):
"""Process a user query and return the result."""
Expand Down
8 changes: 8 additions & 0 deletions tests/unit_tests/agent/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ def test_start_new_conversation(self, sample_df, config):
memory = agent._state.memory.all()
assert len(memory) == 0

def test_start_new_conversation_resets_state(self, sample_df, config):
agent = Agent(sample_df, config, memory_size=10)
agent._state.last_code_generated = "result = df.head()"
agent._state.last_prompt_used = "Show me the first 5 rows"
agent.start_new_conversation()
assert agent._state.last_code_generated is None
assert agent._state.last_prompt_used is None

def test_code_generation_success(self, agent: Agent):
# Mock the code generator
agent._code_generator = Mock()
Expand Down