Skip to content

Core Concepts

Applies to: 4.0.8+

1) Layered architecture

Session management now has two layers:

  • Session: state + strategy runtime
  • SessionExtension: 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 transcript
  • context_window: active prompt window
  • memo: 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_cut truncates 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 None

4.2 Strategy executor

Returns tuple:

  1. new_full_context or None
  2. new_context_window or None
  3. new_memo or None
python
def keep_last_six(full_context, context_window, memo, session_settings):
    return None, list(context_window[-6:]), memo

Register both:

python
session.register_analysis_handler(analysis_handler)
session.register_execution_handlers("keep_last_six", keep_last_six)

5) SessionExtension lifecycle hooks

  • request_prefixes: injects context_window into prompt
  • finally: records input/output back into session

Recording selectors:

  • session.input_keys
  • session.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