Resize & Strategy Extension
Applies to: 4.0.8+
resize governs:
context_windowsize- optional
memoupdates
1) Default flow: max_length + simple_cut
Built-in analyzer:
- if
session.max_lengthis int and window exceeds it -> strategysimple_cut
Built-in simple_cut executor:
- keeps newest messages until total length <=
max_length
Config:
python
agent.set_settings("session.max_length", 12000)2) Automatic vs manual trigger
- automatic: with
auto_resize=True - manual: call
session.resize()
python
agent.activate_session(session_id="resize_demo")
session = agent.activated_session
session.resize()
# await session.async_resize()3) Custom strategy: keep last N turns
python
def analysis_handler(full_context, context_window, memo, session_settings):
if len(context_window) > 10:
return "keep_last_ten"
return None
def keep_last_ten(full_context, context_window, memo, session_settings):
return None, list(context_window[-10:]), memo
session.register_analysis_handler(analysis_handler)
session.register_execution_handlers("keep_last_ten", keep_last_ten)4) When to disable auto_resize
For batch writes where you want one explicit compaction pass:
python
from agently.core import Session
session = Session(auto_resize=False, settings=agent.settings)
# write many messages
session.resize()5) Common pitfalls
- setting
session.max_lengthwithout activating a session - returning an unregistered strategy name
- returning invalid executor tuple shape