1010import json
1111from datetime import datetime
1212from pathlib import Path
13- from typing import Any
13+ from typing import TYPE_CHECKING , Any
1414from uuid import uuid4
1515
1616from agents .memory .session import Session
1717from agents .memory .session_settings import SessionSettings
1818
19+ if TYPE_CHECKING :
20+ from agents .items import TResponseInputItem
21+ from agents .run_context import RunContextWrapper
22+
1923
2024class FileSession (Session ):
2125 """Persist session items to a JSON file on disk."""
@@ -43,14 +47,26 @@ async def get_session_id(self) -> str:
4347 """Return the session id, creating one if needed."""
4448 return await self ._ensure_session_id ()
4549
46- async def get_items (self , limit : int | None = None ) -> list [Any ]:
50+ async def get_items (
51+ self ,
52+ limit : int | None = None ,
53+ * ,
54+ wrapper : RunContextWrapper [Any ] | None = None ,
55+ ) -> list [TResponseInputItem ]:
56+ del wrapper
4757 session_id = await self ._ensure_session_id ()
4858 items = await self ._read_items (session_id )
4959 if limit is not None and limit >= 0 :
5060 return items [- limit :]
5161 return items
5262
53- async def add_items (self , items : list [Any ]) -> None :
63+ async def add_items (
64+ self ,
65+ items : list [TResponseInputItem ],
66+ * ,
67+ wrapper : RunContextWrapper [Any ] | None = None ,
68+ ) -> None :
69+ del wrapper
5470 if not items :
5571 return
5672 session_id = await self ._ensure_session_id ()
@@ -59,7 +75,12 @@ async def add_items(self, items: list[Any]) -> None:
5975 cloned = json .loads (json .dumps (items ))
6076 await self ._write_items (session_id , current + cloned )
6177
62- async def pop_item (self ) -> Any | None :
78+ async def pop_item (
79+ self ,
80+ * ,
81+ wrapper : RunContextWrapper [Any ] | None = None ,
82+ ) -> TResponseInputItem | None :
83+ del wrapper
6384 session_id = await self ._ensure_session_id ()
6485 items = await self ._read_items (session_id )
6586 if not items :
@@ -89,7 +110,7 @@ def _items_path(self, session_id: str) -> Path:
89110 def _state_path (self , session_id : str ) -> Path :
90111 return self ._dir / f"{ session_id } -state.json"
91112
92- async def _read_items (self , session_id : str ) -> list [Any ]:
113+ async def _read_items (self , session_id : str ) -> list [TResponseInputItem ]:
93114 file_path = self ._items_path (session_id )
94115 try :
95116 data = await asyncio .to_thread (file_path .read_text , "utf-8" )
@@ -98,7 +119,7 @@ async def _read_items(self, session_id: str) -> list[Any]:
98119 except FileNotFoundError :
99120 return []
100121
101- async def _write_items (self , session_id : str , items : list [Any ]) -> None :
122+ async def _write_items (self , session_id : str , items : list [TResponseInputItem ]) -> None :
102123 file_path = self ._items_path (session_id )
103124 payload = json .dumps (items , indent = 2 , ensure_ascii = False )
104125 await asyncio .to_thread (self ._dir .mkdir , parents = True , exist_ok = True )
0 commit comments