Core Concepts
Applies to: 4.0.8.1+
1. Session architecture layers
How to read this diagram
Sessionowns state and strategy execution.SessionExtensionattaches Session behavior to the Agent request lifecycle.
2. How the three core states interact
Design rationale
full_contextis for auditability and full recoverycontext_windowis what actually reaches the modelmemois for long-lived structured facts, preferences, and constraints
The modern session model has two layers:
Sessionfor state and strategy executionSessionExtensionfor Agent lifecycle integration
That split lets you:
- use
Sessiondirectly as a pure state/strategy object - or use it through
Agentfor automatic injection and recording
3. Automatic trimming (auto_resize)
By default, auto_resize=True:
resizeruns afterset_chat_history/add_chat_history- the default analyzer reads
session.max_length - when over the limit, the default
simple_cutstrategy runs
Example:
python
agent.set_settings("session.max_length", 12000)4. Programmable extension points
4.1 Analyzer (decides strategy name)
python
def analysis_handler(full_context, context_window, memo, session_settings):
if len(context_window) > 6:
return "keep_last_six"
return None4.2 Executor (returns new state)
The executor returns:
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 them:
python
session.register_analysis_handler(analysis_handler)
session.register_execution_handlers("keep_last_six", keep_last_six)5. SessionExtension in the Agent lifecycle
request_prefixes: injectscontext_windowintochat_historyfinally: extracts request input and reply, then writes them back into Session
Input/output extraction keys:
session.input_keyssession.reply_keys
Supported key styles:
- dot path:
info.task - slash path:
info/task - special prefixes:
.request.*,.agent.*
6. Interface evolution
Legacy Session shortcuts are no longer the recommended path.
Prefer activate_session/deactivate_session, session.max_length, and register_*_handler.
Recommended reading: Session activation and migration