MCPcopy Index your code
hub / github.com/openai/openai-agents-python / _ensure_session_id

Method _ensure_session_id

examples/memory/file_session.py:31–40  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

29 self._dir.mkdir(parents=True, exist_ok=True)
30
31 async def _ensure_session_id(self) -> str:
32 if not self.session_id:
33 timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
34 # Prefix with wall-clock time so recent sessions are easy to spot on disk.
35 self.session_id = f"{timestamp}-{uuid4().hex[:12]}"
36 await asyncio.to_thread(self._dir.mkdir, parents=True, exist_ok=True)
37 file_path = self._items_path(self.session_id)
38 if not file_path.exists():
39 await asyncio.to_thread(file_path.write_text, "[]", encoding="utf-8")
40 return self.session_id
41
42 async def get_session_id(self) -> str:
43 """Return the session id, creating one if needed."""

Callers 6

get_session_idMethod · 0.95
get_itemsMethod · 0.95
add_itemsMethod · 0.95
pop_itemMethod · 0.95
load_state_jsonMethod · 0.95
save_state_jsonMethod · 0.95

Calls 2

_items_pathMethod · 0.95
existsMethod · 0.45

Tested by

no test coverage detected