mem_session_end
Signature
mem.mem_session_end(user_id: str, *, summary: str) -> Session
Closes the active session for user_id with a human-written summary. The closed session is marked is_auto_generated=False (distinguishing it from sessions auto-closed on timeout — see Braess #2).
Parameters
| Parámetro | Tipo | Requerido | Descripción |
|---|---|---|---|
user_id | str | sí | Owner of the session to close. |
summary | str | sí | Human-written session summary. Must be non-empty (whitespace-only is rejected). Recommended structure: Goal · Discoveries · Accomplished · Next Steps · Relevant Files. |
Returns
Session (Pydantic model):
id(str) — session identifier.user_id(str)started_at(str, ISO-8601 UTC)ended_at(str, ISO-8601 UTC) — set on close.last_activity_at(str, ISO-8601 UTC)summary(str) — the summary you provided.status(Literal["completed"])is_auto_generated(bool) — alwaysFalsehere.
Raises
ValueError—summaryis empty or whitespace-only.LookupError— no active session exists foruser_id(404 in the HTTP layer).
Examples
- Basic close
- Structured summary (recommended)
closed = mem.mem_session_end(
user_id="alice",
summary="Captured Alice's preferred greeting and confirmed the agent will use 'Ali'.",
)
print(closed.id, closed.ended_at)
print(closed.is_auto_generated) # False
summary = """
## Goal
Stand up an authentication flow for the dashboard.
## Discoveries
- FTS5 needs the LIKE fallback when the query is < 3 chars.
## Accomplished
- Implemented `/login` and `/logout` endpoints.
- Added rate limiting (100/min) for `/login`.
## Next Steps
- Wire the password reset email job.
## Relevant Files
- src/auth/routes.py
- tests/auth/test_routes.py
""".strip()
mem.mem_session_end(user_id="alice", summary=summary)
tip
If you need to save a checkpoint summary without closing the session, use mem_session_summary instead.