Skip to content

Import & Export

Applies to: 4.0.8+

Session supports JSON/YAML serialization for:

  • persistence
  • cross-process handoff
  • runtime snapshots/audit

1) Export

python
session_json = session.get_json_session()
session_yaml = session.get_yaml_session()

# aliases
session_json_2 = session.to_json()
session_yaml_2 = session.to_yaml()

Export includes:

  • id
  • auto_resize
  • full_context
  • context_window
  • memo
  • session_settings

2) Import (string or file path)

python
from agently.core import Session

session = Session(settings=agent.settings)
session.load_json_session(session_json)
session.load_yaml_session("./session.snapshot.yaml")

# aliases
session.load_json(session_json)
session.load_yaml("./session.snapshot.yaml")

3) Import from nested payload (session_key_path)

python
session.load_json_session(
    "./snapshot.json",
    session_key_path="payload.session",
)

4) Restore into agent session pool

python
restored = Session(settings=agent.settings)
restored.load_json_session("./session.snapshot.json")

agent.sessions[restored.id] = restored
agent.activate_session(session_id=restored.id)

5) Compatibility recommendations

  • store your own snapshot schema version
  • validate critical memo fields after load
  • treat external snapshots as untrusted input