From 9e25a2096a0282abe16e3c471769a0e90b7fe8b2 Mon Sep 17 00:00:00 2001 From: Luke Wriglesworth Date: Mon, 25 Aug 2025 13:32:25 -0400 Subject: [PATCH 1/2] Improve example for custom Session class implementation. --- docs/sessions.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/sessions.md b/docs/sessions.md index f7389cd67..1cbd60658 100644 --- a/docs/sessions.md +++ b/docs/sessions.md @@ -227,7 +227,7 @@ if __name__ == "__main__": You can implement your own session memory by creating a class that follows the [`Session`][agents.memory.session.Session] protocol: ```python -from agents.memory import Session +from agents.items import TResponseInputItem from typing import List class MyCustomSession: @@ -237,17 +237,17 @@ class MyCustomSession: self.session_id = session_id # Your initialization here - async def get_items(self, limit: int | None = None) -> List[dict]: + async def get_items(self, limit: int | None = None) -> List[TResponseInputItem]: """Retrieve conversation history for this session.""" # Your implementation here pass - async def add_items(self, items: List[dict]) -> None: + async def add_items(self, items: List[TResponseInputItem]) -> None: """Store new items for this session.""" # Your implementation here pass - async def pop_item(self) -> dict | None: + async def pop_item(self) -> TResponseInputItem | None: """Remove and return the most recent item from this session.""" # Your implementation here pass From 044981709e4235bb97896f3c25eae473eafeac47 Mon Sep 17 00:00:00 2001 From: Luke Wriglesworth Date: Tue, 26 Aug 2025 13:05:01 -0400 Subject: [PATCH 2/2] Make MyCustomSession inherit form SessionABC --- docs/sessions.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/sessions.md b/docs/sessions.md index 1cbd60658..edbd1b170 100644 --- a/docs/sessions.md +++ b/docs/sessions.md @@ -227,10 +227,11 @@ if __name__ == "__main__": You can implement your own session memory by creating a class that follows the [`Session`][agents.memory.session.Session] protocol: ```python +from agents.memory.session import SessionABC from agents.items import TResponseInputItem from typing import List -class MyCustomSession: +class MyCustomSession(SessionABC): """Custom session implementation following the Session protocol.""" def __init__(self, session_id: str):