Session is the runtime object that ties those surfaces together. It carries identity, history, reply helpers, connected integrations, and scoped data for the current app user.
It carries:
- the current user identity
- message history
- per-session state
- connected integrations
- reply and streaming helpers
Why this matters
In many stacks, channel support is a separate integration problem and every new transport means more glue code. Capsule keeps transport, session state, and reply behavior aligned around the same runtime object, which is why channels feel like a platform capability instead of an afterthought.Session lifecycle
At a high level:- a user opens chat, calls the API, or arrives through a bound external channel
- Capsule creates or resumes a
Session - your message handler receives
sessionandmsg - the runtime persists updates to
session.historyandsession.data
enter() and exit() let you run code when sessions are created or closed.
What lives on Session
The most important fields are:
session.idsession.usersession.channelsession.historysession.datasession.integrationssession.db
session.data for lightweight conversation state. Use collections for durable application data.
Reply patterns
Capsule supports several reply modes:reply()for a complete responsenotify()for lightweight status messagesstream_reply()for chunked outputstream_reply_from()for piping async model streamsshow()for structured blocks like task cards or integration prompts
current_session()
cpsl.current_session() returns the active runtime session, when one exists.
It is especially useful when:
- helper code needs access to the current identity
- a scheduled handler wants owner-scoped context
- a background task runs without a direct
sessionargument
session explicitly is usually clearer.
Channels
Capsule separates transport from app logic.- built-in web chat is available implicitly
- named channel resources are referenced with
cpsl.Channel("name") API()gives you synchronous request/response access
Telegram(...), Slack(...), and WhatsApp(...) channel objects are deprecated.
User identity
session.user gives you the authenticated user and owner context:
idfor the individual useremailwhen availableowner_idsemantics for owner-scoped collections