Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Condenser Interface and Defaults #5306

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

csmith49
Copy link
Contributor

End-user friendly description of the problem this fixes or functionality that this introduces

  • Include this change in the Release Notes. If checked, you must provide an end-user friendly description for your change below

Give a summary of what the PR does, explaining any non-trivial design decisions

This PR adds an abstract memory condenser interface, provides a few default condenser implementations, and updates the CodeActAgent to use the configured condenser during inference.

Condensers exist to reduce the size of the state that must be considered during an agent's step function. They provide a condense: list[Event] -> list[Event] function that can perform an arbitrary transformation on the history of a state before it is seen by an agent, including:

  • Summarizing the history in a new event (as in the LLMCondenser),
  • Removing old events (as in the `RecentEventsCondenser), or
  • Returning the history as-is (as in the NoOpCondenser).

This does not change the underlying state, but can be used by agents as a form of attention and to manage the size of the context in long-running jobs. For an example, see the implementation in CodeActAgent -- the default condenser is the NoOpCondenser, so while the agent is "using the condenser" there is no visible change unless otherwise configured. Currently, condensers must be set by manually initializing an AgentConfig object.

The intent of this PR is to lay the groundwork for an evaluation framework that will let us assess the efficacy of different condenser implementations and, if warranted, support switching between condensers with simple configuration options.

Link of any specific issues this addresses

openhands-agent and others added 7 commits November 26, 2024 18:30
- Add abstract Condenser base class
- Add NoopCondenser, RecentEventsCondenser, and LLMCondenser implementations
- Add configuration system using pydantic models
- Make NoopCondenser the default
- Add comprehensive unit tests
- Replace const parameter with Literal type in condenser configs
- Update from_config to check type field directly
- Fix Event creation in LLMCondenser to use direct attribute assignment
- Update memory module imports
…ndling

- Move condenser_config.py from memory/ to core/config/
- Rename AgentConfig.condenser_config to condenser
- Add proper handling of Pydantic models in env var loading
- Add test for condenser config loading
- Add example of LLM condenser config in config.toml
from openhands.core.config.llm_config import LLMConfig


class CondenserConfig(BaseModel):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small detail, you may want to check this bit, the other config classes are dataclasses instead of BaseModel. Some bunch of utility code works with them as dataclasses and assumes they all are, I think - stuff like ensure that their values are loaded correctly etc, e.g.

for field_name, field_type in sub_config.__annotations__.items():

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll double-check. Easy enough to change to data classes if needed!

@enyst
Copy link
Collaborator

enyst commented Nov 27, 2024

This is exciting and beautiful ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants