Session
Session
Bases: Protocol
Protocol for session implementations.
Session stores conversation history for a specific session, allowing agents to maintain context without requiring explicit manual memory management.
Source code in src/agents/memory/session.py
get_items
async
get_items(
limit: int | None = None,
) -> list[TResponseInputItem]
Retrieve the conversation history for this session.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
limit
|
int | None
|
Maximum number of items to retrieve. If None, retrieves all items. When specified, returns the latest N items in chronological order. |
None
|
Returns:
Type | Description |
---|---|
list[TResponseInputItem]
|
List of input items representing the conversation history |
Source code in src/agents/memory/session.py
add_items
async
add_items(items: list[TResponseInputItem]) -> None
Add new items to the conversation history.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items
|
list[TResponseInputItem]
|
List of input items to add to the history |
required |
pop_item
async
pop_item() -> TResponseInputItem | None
Remove and return the most recent item from the session.
Returns:
Type | Description |
---|---|
TResponseInputItem | None
|
The most recent item if it exists, None if the session is empty |
SessionABC
Bases: ABC
Abstract base class for session implementations.
Session stores conversation history for a specific session, allowing agents to maintain context without requiring explicit manual memory management.
This ABC is intended for internal use and as a base class for concrete implementations. Third-party libraries should implement the Session protocol instead.
Source code in src/agents/memory/session.py
get_items
abstractmethod
async
get_items(
limit: int | None = None,
) -> list[TResponseInputItem]
Retrieve the conversation history for this session.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
limit
|
int | None
|
Maximum number of items to retrieve. If None, retrieves all items. When specified, returns the latest N items in chronological order. |
None
|
Returns:
Type | Description |
---|---|
list[TResponseInputItem]
|
List of input items representing the conversation history |
Source code in src/agents/memory/session.py
add_items
abstractmethod
async
add_items(items: list[TResponseInputItem]) -> None
Add new items to the conversation history.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items
|
list[TResponseInputItem]
|
List of input items to add to the history |
required |
pop_item
abstractmethod
async
pop_item() -> TResponseInputItem | None
Remove and return the most recent item from the session.
Returns:
Type | Description |
---|---|
TResponseInputItem | None
|
The most recent item if it exists, None if the session is empty |