Repository navigation
Core context condensation implementation - #61
Conversation
👍 I don’t see a reason not to. I do think it’s worth thinking about designing condensation in such way that per tokens is easy/possible. V1 seems like a good time to consider if / how we could switch to make per tokens the primary way, if not the only way. We now know what works and how (summaries, browser mask), and I do think the ability to set an approximate token limit is important. Just now we’re looking at two SOTA LLMs, Sonnet-4 and GPT-5, which have different context window limits and likely different ‘tolerance’ at different levels. Condensation per tokens has somehow become kinda difficult or too weird to do, in OpenHands V0. I think maybe we can try to think about either
What do you think? |
I think the execution flow from v0 was actually amenable to this kind of token-first condensation, so I've ported it over mostly unchanged. The real challenge in v0 was in getting good per-token estimates for each event, which was made tricky by:
Assuming we've got a decent way to get tokens per event in v1 it's trivial to make a condenser that goes by token count: in |
|
|
||
| # The relevant summary is always in the last condensation event (i.e., the most recent one). | ||
| for event in reversed(events): | ||
| if isinstance(event, Condensation): |
There was a problem hiding this comment.
If I understand correctly the status in V1, we continue to have a store for events, and another for ConversationState. Could we think about moving the Condensation event to state?
The difference should be (is?) that what is stored in state can change, from a session restore to another. While the events, I think, will continue to not change.
If I switch from Sonnet-4 (200k or what context it has now) to GPT-5 (400k), or the other way around, then the old condensation event will not “match”. It seems the natural behavior of the software would be to recompute and replace it, save the new one for next time. 🤔 Granted, with events it would add another, so it should work too. What do you think makes sense, or is this a matter of choice/preference?
There was a problem hiding this comment.
I think there's multiple ways to engineer this, but my preference would be to keep the condensation information in the events. Two main reasons:
First, for experiments, debugging, and anything else that wants reproducibility, I think we want to be storing all condensations -- when they happen, which events they touch, and what their resulting summary is (if anything). That's possible to store in the state but we'd need to sync the condensations with the events anyways and that's unnecessary complexity (both during implementation and trying to piece together the history of a run after the fact).
Second, the condensation events have a huge impact on what the agent sees and consequently what action it takes next. I think conceptually it fits with the other events in the state.
If I switch from Sonnet-4 (200k or what context it has now) to GPT-5 (400k), or the other way around, then the old condensation event will not “match”. It seems the natural behavior of the software would be to recompute and replace it, save the new one for next time. 🤔 Granted, with events it would add another, so it should work too. What do you think makes sense, or is this a matter of choice/preference?
Switching from the larger context model to the smaller context model shouldn't be a problem, we'd run into a context window error and condense immediately. Going the other way does mean the condensation isn't "tuned" for that particular model, but recomputing also seems strange to me: the agent has already taken some actions conditioned on the old summaries. Either way you can't get a true roll-out of the new model.
The difference should be (is?) that what is stored in state can change, from a session restore to another. While the events, I think, will continue to not change.
I like this framing and we'd probably be well-served trying to codify these assumptions. I recall at one point we were recomputing condensations when loading old sessions because the history kept getting off-track with the stored view and it took us ages to figure out -- the fix was shoving all this info in the append-only history.
Honestly, I'd be in favor of taking this even further and lifting certain state-changes up to events. Why not have an event that records when a model was changed or some tool was added?
xingyaoww
left a comment
There was a problem hiding this comment.
Can you add an examples/agent_with_condenser.py to illustrate how we can use condenser in an agent loop?
|
I can, but until I add the other implementations it won't actually do any condensation. Are you okay with me adding that example in the next PR? |
|
@csmith49 ahh in that case let's defer it to future PRs |
|
Looks like there are a few issues preventing this PR from being merged!
If you'd like me to help, just leave a comment, like Feel free to include any additional details that might help me get this PR into a better state. You can manage your notification settings |
xingyaoww
left a comment
There was a problem hiding this comment.
A few nit, otherwise LGTM. Feel free to merge directly when you've addressed them
| llm_convertible_events = condensation_result.events | ||
|
|
||
| case Condensation(): | ||
| state.events.append(condensation_result) |
There was a problem hiding this comment.
the .append should be handled by the on_event callback now - so no need to re-append
| | CondensationRequest | ||
| ) | ||
|
|
||
|
|
There was a problem hiding this comment.
You want to add these two to __all__?
There was a problem hiding this comment.
i kinda want to rename this condenser.py
Co-authored-by: Calvin Smith <calvin@all-hands.dev> Co-authored-by: Xingyao Wang <xingyao@all-hands.dev>
This PR ports over the core of the condensation logic from the OSS repo.
This PR adds:
CondensationandCondensationRequestevents.Viewclass and associated tests.CondenserandRollingCondenserbase classes.NoOpCondenserfor testing/placeholder purposes.CodeActAgent.step.This represents a complete solution for #56 and most of a solution for #55.
Some changes made from the source:
Condensationobjects don't track start/stop IDs, just a list of IDs to forget. New ID structure is UUID-based and so notrange(...)-able like the integers of old.View | Condensation, but theCondensationis an actual event and not a shallow wrapper around an event.State-based metadata tracking has been removed. IIRC it was only ever used for experiments but there are easier ways now (especially with the cleaner logging).