-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
feature: Condenser Interface and Defaults #5306
Conversation
- 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): |
There was a problem hiding this comment.
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.
OpenHands/openhands/core/config/utils.py
Line 42 in f0ca223
for field_name, field_type in sub_config.__annotations__.items(): |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it currently is, will this config class read its attributes from env? The other config instances read from env > then from toml > then fallback to the default values set in the dataclass.
Why is it a BaseModel, can it be a dataclass and still do what was useful in the BaseModel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This config is not currently read from the environment. Until we've got a condenser that we want on by default, the only way to set up anything besides the NoOpCondenser
is to programmatically build the config object.
Why is it a BaseModel, can it be a dataclass and still do what was useful in the BaseModel?
Not so compactly. TheBaseModel
implementation is there for two reasons:
- Easy field validation, notably for setting bounds on numerical values and ensuring the
type
field is instantiated with the literal. - Easy serialization. The
type
field sets up the configuration objects as a discriminated union, so there's trivial conversion to JSON and back withconfig.model_dump_json()
andCondenserConfig.model_validate_json()
.
I can re-implement 1 and 2 over dataclass
objects if you want to avoid the dependency here. But we don't lose access to, e.g., __annotations__
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, we can make an issue for this, and we can merge this PR as it is working in the development mode?
I do see at least two reasons why this matters:
- people usually run with
docker run
, where they pass settings via env, so this feature is unavailable basically, for now - inconsistency in code design, for us even, and more so for external contributors, to understand, follow and work with the code.
If we make an issue, we can discuss there if maybe there are benefits to go the other way around, make them all BaseModel. I am seeing this kind of thing (mix of dataclass with BaseModel) in other parts of the code too, and it is IMHO more complexity when we have two different ways, rather than whichever of them. 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
people usually run with docker run, where they pass settings via env, so this feature is unavailable basically, for now
That's true, and something I want to fix. I had OpenHands make a pass at extending the config pipeline (env + toml) to support condensers and it made a big mess that I couldn't seem to fix without blowing up the size of this PR.
One thing that made integration tricky was actually the discriminated union -- different condensers have different but overlapping config, and I couldn't see how to extend the env + toml implementation to support "recursive" configuration.
inconsistency in code design, for us even, and more so for external contributors, to understand, follow and work with the code.
I'd be happy to make an issue and we can get some more discussion there!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #6015 for the issue.
This is exciting and beautiful ❤️ |
- 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
- Add script to generate Vega graphs from evaluation data - Support token usage over time and cactus plots - Allow customization of graph dimensions - Fix pandas JSON reading warnings
- Add format detection based on output file suffix - Add input directory validation - Use click.Path for path validation - Centralize chart saving logic
- Add --browser flag to display charts in browser - Use chart.show() to display in browser when no output file - Keep default renderer when not using browser
@openhands-agent
Please run poetry lock --no-update Don't do anything else. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very exciting, it will allow us to experiment with greater ease and let everyone try approaches! Just plug in and play ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love seeing this coming into shape! I think the next step would be improving the condensation summarization prompt & get it to work - so we can at least have about the same perf on SWE-Bench
btw, we also need to do poetry lock --no-update
. It seems we changed a lot here
nvm it seems ok
End-user friendly description of the problem this fixes or functionality that this introduces
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 acondense: list[Event] -> list[Event]
function that can perform an arbitrary transformation on thehistory
of a state before it is seen by an agent, including:LLMCondenser
),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 theNoOpCondenser
, so while the agent is "using the condenser" there is no visible change unless otherwise configured. Currently, condensers must be set by manually initializing anAgentConfig
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
#5715