Chat Sessions (🧪Beta)
albert.collections.chat_sessions.ChatSessionCollection
Manage "Ask Albert" chat sessions in the Albert platform (🧪 Beta).
A chat session is a single conversation with Albert's AI assistant, "Ask
Albert". Each session (ChatSession) holds an
ordered series of message turns
(ChatMessage, managed by
ChatMessageCollection) and can be
filed under a folder
(ChatFolder, managed by
ChatFolderCollection).
This is an async collection accessed as client.chat_sessions on an
AsyncAlbert client.
Beta Feature!
Please do not use in production or without explicit guidance from Albert. You might otherwise have a bad experience. This feature currently falls outside of the Albert support contract, but we'd love your feedback!
Example
from albert import AsyncAlbert
from albert.resources.chats import ChatSession
async with AsyncAlbert() as client:
session = await client.chat_sessions.create(
session=ChatSession(name="Titanium dioxide questions", source_session_id="ext-123")
)
async for s in client.chat_sessions.get_all(name=["titanium"]):
print(s.id, s.name)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AsyncAlbertSession
|
The authenticated Albert async session used for API calls. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
base_path |
str
|
The base API route for chat session requests. |
Methods:
| Name | Description |
|---|---|
create |
Create a new chat session. |
get_by_id |
Get a single session by its ID. |
get_by_source_session_id |
Get a session by its external source session ID. |
get_all |
Iterate over sessions, with optional filters. |
update |
Rename a session or move it between folders. |
delete |
Delete a session by its ID. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AsyncAlbertSession
|
The authenticated Albert async session used for API calls. |
required |
Source code in src/albert/collections/chat_sessions.py
create
create(*, session: ChatSession) -> ChatSession
Create a new chat session.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
ChatSession
|
The session to create. |
required |
Returns:
| Type | Description |
|---|---|
ChatSession
|
The created session, populated with its server-assigned |
Source code in src/albert/collections/chat_sessions.py
get_by_id
get_by_id(*, id: str) -> ChatSession
Get a chat session by its ID.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The identifier of the session to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
ChatSession
|
The fully populated session. |
Source code in src/albert/collections/chat_sessions.py
get_by_source_session_id
get_by_source_session_id(
*, source_session_id: str
) -> ChatSession
Get a chat session by its external source session ID.
Use this to look up a session by the identifier that links it to a source
system, rather than by its Albert id.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_session_id
|
str
|
The external source session identifier (the session's
|
required |
Returns:
| Type | Description |
|---|---|
ChatSession
|
The matching session. |
Source code in src/albert/collections/chat_sessions.py
get_all
get_all(
*,
name: list[str] | None = None,
exact_match: bool = False,
parent_id: str | None = None,
max_items: int | None = None,
) -> AsyncIterator[ChatSession]
Iterate over chat sessions, with optional filters.
Transparently pages through results, yielding one session at a time.
Returns the paginator directly so has_more remains available.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
list[str] | None
|
Filter to sessions whose name matches any of the given values. |
None
|
exact_match
|
bool
|
When |
False
|
parent_id
|
str | None
|
Filter to sessions filed under the given
|
None
|
max_items
|
int | None
|
Maximum number of sessions to yield in total. If |
None
|
Returns:
| Type | Description |
|---|---|
AsyncIterator[ChatSession]
|
Sessions matching the given filters. |
Source code in src/albert/collections/chat_sessions.py
update
update(
*,
id: str,
name: str | None = None,
parent_id: str | None | _UnsetType = _UNSET,
) -> ChatSession
Update a chat session.
Rename a session and/or move it between folders. Only the arguments you pass are changed; omitted arguments are left untouched.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The identifier of the session to update. |
required |
name
|
str | None
|
A new display name for the session. |
None
|
parent_id
|
str | None
|
The |
_UNSET
|
Returns:
| Type | Description |
|---|---|
ChatSession
|
The updated session. |
Notes
The following fields can be updated: name, parent_id.
Source code in src/albert/collections/chat_sessions.py
delete
delete(*, id: str) -> None
Delete a chat session by its ID.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The identifier of the session to delete. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|