Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def _generate_condensation(
summary = first_content.text

return Condensation(
forgotten_event_ids=[event.id for event in forgotten_events],
forgotten_event_ids={event.id for event in forgotten_events},
summary=summary,
summary_offset=summary_offset,
llm_response_id=llm_response.id,
Expand Down
4 changes: 2 additions & 2 deletions openhands-sdk/openhands/sdk/event/condenser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
class Condensation(Event):
"""This action indicates a condensation of the conversation history is happening."""

forgotten_event_ids: list[EventID] = Field(
default_factory=list,
forgotten_event_ids: set[EventID] = Field(
default_factory=set,
description="The IDs of the events that are being forgotten "
Comment thread
csmith49 marked this conversation as resolved.
"(removed from the `View` given to the LLM).",
)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/tests/c01_thinking_block_condenser.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def condense(self, view: View, agent_llm: LLM | None = None) -> View | Condensat
)

# Get event IDs to forget
forgotten_event_ids = [event.id for event in view.events[start_idx:end_idx]]
forgotten_event_ids = {event.id for event in view.events[start_idx:end_idx]}

# Create condensation event
return Condensation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def test_get_condensation_with_previous_summary(mock_llm: LLM) -> None:
# Add a condensation to simulate previous summarization
# The summary will be inserted at keep_first due to summary_offset
condensation = Condensation(
forgotten_event_ids=[events[3].id, events[4].id],
forgotten_event_ids={events[3].id, events[4].id},
summary="Previous summary content",
summary_offset=keep_first,
llm_response_id="condensation_response_1",
Expand Down
4 changes: 2 additions & 2 deletions tests/sdk/context/condenser/test_rolling_condenser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_condensation(
)
# Return a simple condensation for successful case
return Condensation(
forgotten_event_ids=[view.events[0].id],
forgotten_event_ids={view.events[0].id},
summary="Mock summary",
summary_offset=0,
llm_response_id="mock-response-id",
Expand Down Expand Up @@ -221,7 +221,7 @@ def test_hard_context_reset_condensation_is_returned() -> None:

# Create a condensation that will be returned by hard_context_reset
hard_reset_condensation = Condensation(
forgotten_event_ids=[events[0].id, events[1].id],
forgotten_event_ids={events[0].id, events[1].id},
summary="Hard context reset summary",
summary_offset=0,
llm_response_id="hard_reset_response",
Expand Down
20 changes: 11 additions & 9 deletions tests/sdk/context/view/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_view_preserves_uncondensed_lists() -> None:
def test_view_forgets_events() -> None:
"""Tests that views drop forgotten events and the condensation actions."""
message_events: list[Event] = [message_event(f"Event {i}") for i in range(5)]
message_event_ids: list[str] = [event.id for event in message_events]
message_event_ids = {event.id for event in message_events}

# Build a list of events: M_1, ..., M_5, Condensation
# The condensation specifically targets the IDs of all M_i messages
Expand All @@ -45,7 +45,7 @@ def test_view_forgets_events() -> None:
def test_view_keeps_non_forgotten_events() -> None:
"""Tests that views keep non-forgotten events."""
message_events: list[Event] = [message_event(f"Event {i}") for i in range(5)]
message_event_ids: list[str] = [event.id for event in message_events]
message_event_ids = {event.id for event in message_events}

for forgotten_event_id in message_event_ids:
events: list[Event] = [
Expand All @@ -55,7 +55,7 @@ def test_view_keeps_non_forgotten_events() -> None:
# one of the events. That way we can check that the rest of the
# events are preserved.
Condensation(
forgotten_event_ids=[forgotten_event_id],
forgotten_event_ids={forgotten_event_id},
llm_response_id="condensation_response_1",
),
]
Expand All @@ -76,7 +76,7 @@ def test_view_inserts_summary() -> None:
events = [
*message_events,
Condensation(
forgotten_event_ids=[],
forgotten_event_ids=set(),
summary="My Summary",
summary_offset=offset,
llm_response_id="condensation_response_1",
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_no_condensation_action_in_view() -> None:
events.extend(message_events[:2])
events.append(
Condensation(
forgotten_event_ids=[message_events[0].id],
forgotten_event_ids={message_events[0].id},
llm_response_id="condensation_response_1",
)
)
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_handled_condensation_request_with_condensation_action() -> None:
)
events.append(
Condensation(
forgotten_event_ids=[event.id for event in events[:2]],
forgotten_event_ids={event.id for event in events[:2]},
llm_response_id="condensation_response_1",
)
)
Expand All @@ -197,7 +197,7 @@ def test_multiple_condensation_requests_pattern() -> None:
CondensationRequest(), # First request
message_event(content="Event 1"),
Condensation(
forgotten_event_ids=[], llm_response_id="condensation_response_1"
forgotten_event_ids=set(), llm_response_id="condensation_response_1"
), # Handles first request
message_event(content="Event 2"),
CondensationRequest(), # Second request - should be unhandled
Expand All @@ -222,7 +222,7 @@ def test_condensation_action_before_request() -> None:
events = [
message_event(content="Event 0"),
Condensation(
forgotten_event_ids=[], llm_response_id="condensation_response_1"
forgotten_event_ids=set(), llm_response_id="condensation_response_1"
), # This doesn't handle the later request
message_event(content="Event 1"),
CondensationRequest(), # This should be unhandled
Expand Down Expand Up @@ -282,7 +282,9 @@ def test_condensation_request_always_removed_from_view() -> None:
message_event(content="Event 0"),
CondensationRequest(),
message_event(content="Event 1"),
Condensation(forgotten_event_ids=[], llm_response_id="condensation_response_1"),
Condensation(
forgotten_event_ids=set(), llm_response_id="condensation_response_1"
),
message_event(content="Event 2"),
]
view_handled = View.from_events(events_handled)
Expand Down
30 changes: 15 additions & 15 deletions tests/sdk/context/view/test_view_append_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_condensation_forgets_events(self) -> None:
view.append_event(msg)

condensation = Condensation(
forgotten_event_ids=[msgs[0].id, msgs[2].id],
forgotten_event_ids={msgs[0].id, msgs[2].id},
llm_response_id="resp_1",
)
view.append_event(condensation)
Expand All @@ -86,7 +86,7 @@ def test_condensation_forgets_all_events(self) -> None:
view.append_event(msg)

condensation = Condensation(
forgotten_event_ids=[m.id for m in msgs],
forgotten_event_ids={m.id for m in msgs},
llm_response_id="resp_1",
)
view.append_event(condensation)
Expand All @@ -97,7 +97,7 @@ def test_condensation_forgets_all_events(self) -> None:
def test_condensation_on_empty_view(self) -> None:
view = View()
condensation = Condensation(
forgotten_event_ids=[],
forgotten_event_ids=set(),
llm_response_id="resp_1",
)
view.append_event(condensation)
Expand All @@ -111,7 +111,7 @@ def test_condensation_with_no_forgotten_ids(self) -> None:
view.append_event(msg)

condensation = Condensation(
forgotten_event_ids=[],
forgotten_event_ids=set(),
llm_response_id="resp_1",
)
view.append_event(condensation)
Expand All @@ -126,7 +126,7 @@ def test_condensation_inserts_summary(self) -> None:
view.append_event(msg)

condensation = Condensation(
forgotten_event_ids=[msgs[0].id],
forgotten_event_ids={msgs[0].id},
summary="Summary of msg 0",
summary_offset=0,
llm_response_id="resp_1",
Expand All @@ -146,7 +146,7 @@ def test_condensation_inserts_summary_at_end(self) -> None:
view.append_event(msg)

condensation = Condensation(
forgotten_event_ids=[],
forgotten_event_ids=set(),
summary="End summary",
summary_offset=2,
llm_response_id="resp_1",
Expand All @@ -167,7 +167,7 @@ def test_condensation_clears_unhandled_flag(self) -> None:
assert view.unhandled_condensation_request is True

view.append_event(
Condensation(forgotten_event_ids=[], llm_response_id="resp_1")
Condensation(forgotten_event_ids=set(), llm_response_id="resp_1")
)

assert view.unhandled_condensation_request is False
Expand All @@ -179,7 +179,7 @@ def test_condensation_clears_flag_even_without_prior_request(self) -> None:
assert view.unhandled_condensation_request is False

view.append_event(
Condensation(forgotten_event_ids=[], llm_response_id="resp_1")
Condensation(forgotten_event_ids=set(), llm_response_id="resp_1")
)

assert view.unhandled_condensation_request is False
Expand All @@ -188,7 +188,7 @@ def test_condensation_not_added_to_events(self) -> None:
view = View()
view.append_event(message_event("msg"))
view.append_event(
Condensation(forgotten_event_ids=[], llm_response_id="resp_1")
Condensation(forgotten_event_ids=set(), llm_response_id="resp_1")
)

for event in view.events:
Expand Down Expand Up @@ -263,7 +263,7 @@ def test_request_then_condensation_clears_flag(self) -> None:
assert view.unhandled_condensation_request is True

view.append_event(
Condensation(forgotten_event_ids=[], llm_response_id="resp_1")
Condensation(forgotten_event_ids=set(), llm_response_id="resp_1")
)

assert view.unhandled_condensation_request is False
Expand All @@ -272,7 +272,7 @@ def test_condensation_then_request_sets_flag(self) -> None:
view = View()
view.append_event(message_event("msg 0"))
view.append_event(
Condensation(forgotten_event_ids=[], llm_response_id="resp_1")
Condensation(forgotten_event_ids=set(), llm_response_id="resp_1")
)

assert view.unhandled_condensation_request is False
Expand All @@ -289,7 +289,7 @@ def test_multiple_condensations_in_sequence(self) -> None:

view.append_event(
Condensation(
forgotten_event_ids=[msgs[0].id, msgs[1].id],
forgotten_event_ids={msgs[0].id, msgs[1].id},
llm_response_id="resp_1",
)
)
Expand All @@ -298,7 +298,7 @@ def test_multiple_condensations_in_sequence(self) -> None:

view.append_event(
Condensation(
forgotten_event_ids=[msgs[2].id],
forgotten_event_ids={msgs[2].id},
llm_response_id="resp_2",
)
)
Expand All @@ -313,7 +313,7 @@ def test_interleaved_messages_and_condensations(self) -> None:
view.append_event(msg0)
view.append_event(
Condensation(
forgotten_event_ids=[msg0.id],
forgotten_event_ids={msg0.id},
summary="Summary of msg 0",
summary_offset=0,
llm_response_id="resp_1",
Expand Down Expand Up @@ -360,7 +360,7 @@ def test_full_lifecycle(self) -> None:
# Condensation handles the request
view.append_event(
Condensation(
forgotten_event_ids=[msgs[0].id, msgs[1].id],
forgotten_event_ids={msgs[0].id, msgs[1].id},
summary="Summary of early messages",
summary_offset=0,
llm_response_id="resp_1",
Expand Down
12 changes: 6 additions & 6 deletions tests/sdk/context/view/test_view_batch_atomicity.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_batch_atomicity_partial_batch_forgotten() -> None:
obs3,
obs4,
Condensation(
forgotten_event_ids=[action1.id, action2.id, action3.id],
forgotten_event_ids={action1.id, action2.id, action3.id},
llm_response_id="condensation_response_1",
),
]
Expand Down Expand Up @@ -116,7 +116,7 @@ def test_batch_atomicity_complete_batch_forgotten() -> None:
obs1,
obs2,
Condensation(
forgotten_event_ids=[action1.id, action2.id],
forgotten_event_ids={action1.id, action2.id},
llm_response_id="condensation_response_1",
),
]
Expand Down Expand Up @@ -164,7 +164,7 @@ def test_batch_atomicity_no_forgetting_preserves_batch() -> None:
obs2,
obs3,
Condensation(
forgotten_event_ids=[], llm_response_id="condensation_response_1"
forgotten_event_ids=set(), llm_response_id="condensation_response_1"
), # Don't forget anything
]

Expand Down Expand Up @@ -221,7 +221,7 @@ def test_batch_atomicity_multiple_batches() -> None:
obs2_1,
obs2_2,
Condensation(
forgotten_event_ids=[action1_1.id],
forgotten_event_ids={action1_1.id},
llm_response_id="condensation_response_1",
),
]
Expand Down Expand Up @@ -259,7 +259,7 @@ def test_batch_atomicity_single_action_batch() -> None:
action,
obs,
Condensation(
forgotten_event_ids=[action.id], llm_response_id="condensation_response_1"
forgotten_event_ids={action.id}, llm_response_id="condensation_response_1"
),
]

Expand Down Expand Up @@ -296,7 +296,7 @@ def test_batch_atomicity_no_thinking_blocks() -> None:
action3,
obs3,
Condensation(
forgotten_event_ids=[action1.id, action2.id],
forgotten_event_ids={action1.id, action2.id},
llm_response_id="condensation_response_1",
),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_batch_atomicity_when_observation_forgotten() -> None:
obs1,
obs2,
Condensation(
forgotten_event_ids=[obs1.id],
forgotten_event_ids={obs1.id},
llm_response_id="condensation_response_1",
),
]
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_batch_atomicity_when_multiple_observations_forgotten() -> None:
obs2,
obs3,
Condensation(
forgotten_event_ids=[obs1.id, obs2.id],
forgotten_event_ids={obs1.id, obs2.id},
llm_response_id="condensation_response_1",
),
]
Expand Down Expand Up @@ -162,7 +162,7 @@ def test_batch_atomicity_different_batches_independent() -> None:
obs2_1,
obs2_2,
Condensation(
forgotten_event_ids=[obs1_1.id],
forgotten_event_ids={obs1_1.id},
llm_response_id="condensation_response_1",
),
]
Expand Down Expand Up @@ -194,7 +194,7 @@ def test_single_action_batch_observation_forgotten() -> None:
action,
obs,
Condensation(
forgotten_event_ids=[obs.id],
forgotten_event_ids={obs.id},
llm_response_id="condensation_response_1",
),
]
Expand Down
Loading
Loading