-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Condenser Interface and Defaults (#5306)
Co-authored-by: openhands <[email protected]> Co-authored-by: Calvin Smith <[email protected]> Co-authored-by: Engel Nyst <[email protected]>
- Loading branch information
1 parent
561f308
commit 6e4ff56
Showing
17 changed files
with
2,683 additions
and
1,805 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from typing import Literal | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
from openhands.core.config.llm_config import LLMConfig | ||
|
||
|
||
class NoOpCondenserConfig(BaseModel): | ||
"""Configuration for NoOpCondenser.""" | ||
|
||
type: Literal['noop'] = Field('noop') | ||
|
||
|
||
class ObservationMaskingCondenserConfig(BaseModel): | ||
"""Configuration for ObservationMaskingCondenser.""" | ||
|
||
type: Literal['observation_masking'] = Field('observation_masking') | ||
attention_window: int = Field( | ||
default=10, | ||
description='The number of most-recent events where observations will not be masked.', | ||
ge=1, | ||
) | ||
|
||
|
||
class RecentEventsCondenserConfig(BaseModel): | ||
"""Configuration for RecentEventsCondenser.""" | ||
|
||
type: Literal['recent'] = Field('recent') | ||
keep_first: int = Field( | ||
default=0, | ||
description='The number of initial events to condense.', | ||
ge=0, | ||
) | ||
max_events: int = Field( | ||
default=10, description='Maximum number of events to keep.', ge=1 | ||
) | ||
|
||
|
||
class LLMSummarizingCondenserConfig(BaseModel): | ||
"""Configuration for LLMCondenser.""" | ||
|
||
type: Literal['llm'] = Field('llm') | ||
llm_config: LLMConfig = Field( | ||
..., description='Configuration for the LLM to use for condensing.' | ||
) | ||
|
||
|
||
class AmortizedForgettingCondenserConfig(BaseModel): | ||
"""Configuration for AmortizedForgettingCondenser.""" | ||
|
||
type: Literal['amortized'] = Field('amortized') | ||
max_size: int = Field( | ||
default=100, | ||
description='Maximum size of the condensed history before triggering forgetting.', | ||
ge=2, | ||
) | ||
keep_first: int = Field( | ||
default=0, | ||
description='Number of initial events to always keep in history.', | ||
ge=0, | ||
) | ||
|
||
|
||
class LLMAttentionCondenserConfig(BaseModel): | ||
"""Configuration for LLMAttentionCondenser.""" | ||
|
||
type: Literal['llm_attention'] = Field('llm_attention') | ||
llm_config: LLMConfig = Field( | ||
..., description='Configuration for the LLM to use for attention.' | ||
) | ||
max_size: int = Field( | ||
default=100, | ||
description='Maximum size of the condensed history before triggering forgetting.', | ||
ge=2, | ||
) | ||
keep_first: int = Field( | ||
default=0, | ||
description='Number of initial events to always keep in history.', | ||
ge=0, | ||
) | ||
|
||
|
||
CondenserConfig = ( | ||
NoOpCondenserConfig | ||
| ObservationMaskingCondenserConfig | ||
| RecentEventsCondenserConfig | ||
| LLMSummarizingCondenserConfig | ||
| AmortizedForgettingCondenserConfig | ||
| LLMAttentionCondenserConfig | ||
) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from openhands.memory.condenser import MemoryCondenser | ||
from openhands.memory.condenser import Condenser | ||
from openhands.memory.memory import LongTermMemory | ||
|
||
__all__ = ['LongTermMemory', 'MemoryCondenser'] | ||
__all__ = ['LongTermMemory', 'Condenser'] |
Oops, something went wrong.