Adds unit test for the interaction between agent controller truncation and condenser (#7186)

Co-authored-by: Calvin Smith <calvin@all-hands.dev>
This commit is contained in:
Calvin Smith 2025-03-11 09:57:15 -06:00 committed by GitHub
parent 5e521a4a6e
commit 637a1d5c17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -378,6 +378,51 @@ def test_llm_summarizing_condenser_llm_call(mock_llm, mock_state):
assert mock_state.extra_data['condenser_meta'][0]['metrics'] == {'test_metric': 1.0}
def test_llm_summarizing_condenser_resets_when_given_truncated_history(
mock_llm, mock_state
):
"""Test that the condenser, when it sees a shorter history than it has in the past (due to truncation), will reset its tracking."""
max_size = 4
keep_first = 1
condenser = LLMSummarizingCondenser(
max_size=max_size, keep_first=keep_first, llm=mock_llm
)
# Add initial event
first_event = create_test_event('Event 0')
mock_state.history.append(first_event)
# Set up mock LLM response
mock_llm.set_mock_response_content('Summary of forgotten events')
# Add enough events to trigger forgetting
for i in range(max_size + 3): # +3 to ensure we're well past max_size
event = create_test_event(f'Event {i+1}')
mock_state.history.append(event)
# Get the condensed history
results = condenser.condensed_history(mock_state)
# We should have exactly 3 events:
# 1. First event (keep_first = 1)
# 2. Summary event
# 3. Most recent event
assert len(results) == 3, f'Expected 3 events, got {len(results)}: {results}'
# Now, call condensation on a small history that contains only two events.
alternate_history = [
create_test_event('Alt. Event 0'),
create_test_event('Alt. Event 1'),
]
mock_state.history = alternate_history
# When we do this, the condenser should start tracking the alternative history
# as the de-facto history. That means we lose the summarization event and any
# other events that were in the previous history.
results = condenser.condensed_history(mock_state)
assert results == alternate_history
def test_amortized_forgetting_condenser_from_config():
"""Test that AmortizedForgettingCondenser objects can be made from config."""
max_size = 50