Core Concepts
Applies to: 4.0.8+
1) Layered architecture
Session management now has two layers:
Session: state + strategy runtimeSessionExtension: binds session into agent request lifecycle
This separation lets you:
- run Session standalone for data/control logic
- use Agent for automatic injection and recording
2) Three core state fields
full_context: complete transcriptcontext_window: active prompt windowmemo: custom durable memory payload
3) Auto-resize behavior
With auto_resize=True:
- every history write can trigger
resize - default analyzer checks
session.max_length - default strategy
simple_cuttruncates window when needed
Config example:
python
agent.set_settings("session.max_length", 12000)4) Extension points
4.1 Analyzer
Returns strategy name (or None):
python
def analysis_handler(full_context, context_window, memo, session_settings):
if len(context_window) > 6:
return "keep_last_six"
return None4.2 Strategy executor
Returns tuple:
new_full_contextorNonenew_context_windoworNonenew_memoorNone
python
def keep_last_six(full_context, context_window, memo, session_settings):
return None, list(context_window[-6:]), memoRegister both:
python
session.register_analysis_handler(analysis_handler)
session.register_execution_handlers("keep_last_six", keep_last_six)5) SessionExtension lifecycle hooks
request_prefixes: injectscontext_windowinto promptfinally: records input/output back into session
Recording selectors:
session.input_keyssession.reply_keys
Supported key styles:
- dot path:
info.task - slash path:
info/task - special prefixes:
.request.*,.agent.*
6) API evolution note
Legacy quick/lite/memo helper style is no longer recommended in new docs/projects.
Use activate_session/deactivate_session, session.max_length, and register_*_handler patterns.
Reference: Session Toggle & Migration