Skip to content

Agent Integration Details

Applies to: 4.0.8+

SessionExtension is mixed into default Agent. This page explains lifecycle behavior and recording controls.

1) Lifecycle hooks

Before request (request_prefixes)

  • injects activated_session.context_window into chat_history
  • injects CHAT SESSION MEMO if memo exists

After request (finally)

  • extracts input/output
  • appends records into session history

2) Session pool model

Agent stores:

  • agent.sessions: dict[str, Session]
  • agent.activated_session: Session | None

Recommended usage:

python
agent.activate_session(session_id=user_id)
# ...
agent.deactivate_session()

3) Selective recording

Input selectors: session.input_keys

python
agent.set_settings("session.input_keys", [
    ".request",
    "info.task",
    "input/lang",
    ".agent.system",
])

Reply selectors: session.reply_keys

python
agent.set_settings("session.reply_keys", ["summary", "scores.total"])

If selectors are None, full prompt/result is recorded.

4) History APIs when session is active

These methods operate on current session state:

  • set_chat_history(...)
  • add_chat_history(...)
  • reset_chat_history()
  • clean_context_window()

5) Temp request inside strategy handlers

Use create_temp_request() for memo summarization inside handlers.

Why:

  • does not inherit current agent prompt/session handlers
  • avoids recursive contamination of main session context
python
memo_request = agent.create_temp_request()

6) Team convention

Use only v4.0.8+ Session APIs in new code/docs:

  • activate_session / deactivate_session
  • session.max_length
  • register_analysis_handler / register_execution_handlers