|
1 | | -"""Session memory backends living in the extensions namespace. |
2 | | -
|
3 | | -This package contains optional, production-grade session implementations that |
4 | | -introduce extra third-party dependencies (database drivers, ORMs, etc.). They |
5 | | -conform to the :class:`agents.memory.session.Session` protocol so they can be |
6 | | -used as a drop-in replacement for :class:`agents.memory.session.SQLiteSession`. |
7 | | -""" |
8 | | - |
9 | | -from __future__ import annotations |
10 | | - |
11 | | -from typing import TYPE_CHECKING, Any |
12 | | - |
13 | | -if TYPE_CHECKING: |
14 | | - from .advanced_sqlite_session import AdvancedSQLiteSession |
15 | | - from .async_sqlite_session import AsyncSQLiteSession |
16 | | - from .dapr_session import ( |
17 | | - DAPR_CONSISTENCY_EVENTUAL, |
18 | | - DAPR_CONSISTENCY_STRONG, |
19 | | - DaprSession, |
20 | | - ) |
21 | | - from .encrypt_session import EncryptedSession |
22 | | - from .mongodb_session import MongoDBSession |
23 | | - from .redis_session import RedisSession |
24 | | - from .sqlalchemy_session import SQLAlchemySession |
25 | | - |
26 | | -__all__: list[str] = [ |
27 | | - "AdvancedSQLiteSession", |
28 | | - "AsyncSQLiteSession", |
29 | | - "DAPR_CONSISTENCY_EVENTUAL", |
30 | | - "DAPR_CONSISTENCY_STRONG", |
31 | | - "DaprSession", |
32 | | - "EncryptedSession", |
33 | | - "MongoDBSession", |
34 | | - "RedisSession", |
35 | | - "SQLAlchemySession", |
36 | | -] |
37 | | - |
38 | | - |
39 | | -def __getattr__(name: str) -> Any: |
40 | | - if name == "EncryptedSession": |
41 | | - try: |
42 | | - from .encrypt_session import EncryptedSession # noqa: F401 |
43 | | - |
44 | | - return EncryptedSession |
45 | | - except ModuleNotFoundError as e: |
46 | | - raise ImportError( |
47 | | - "EncryptedSession requires the 'cryptography' extra. " |
48 | | - "Install it with: pip install openai-agents[encrypt]" |
49 | | - ) from e |
50 | | - |
51 | | - if name == "RedisSession": |
52 | | - try: |
53 | | - from .redis_session import RedisSession # noqa: F401 |
54 | | - |
55 | | - return RedisSession |
56 | | - except ModuleNotFoundError as e: |
57 | | - raise ImportError( |
58 | | - "RedisSession requires the 'redis' extra. " |
59 | | - "Install it with: pip install openai-agents[redis]" |
60 | | - ) from e |
61 | | - |
62 | | - if name == "SQLAlchemySession": |
63 | | - try: |
64 | | - from .sqlalchemy_session import SQLAlchemySession # noqa: F401 |
65 | | - |
66 | | - return SQLAlchemySession |
67 | | - except ModuleNotFoundError as e: |
68 | | - raise ImportError( |
69 | | - "SQLAlchemySession requires the 'sqlalchemy' extra. " |
70 | | - "Install it with: pip install openai-agents[sqlalchemy]" |
71 | | - ) from e |
72 | | - |
73 | | - if name == "AdvancedSQLiteSession": |
74 | | - try: |
75 | | - from .advanced_sqlite_session import AdvancedSQLiteSession # noqa: F401 |
76 | | - |
77 | | - return AdvancedSQLiteSession |
78 | | - except ModuleNotFoundError as e: |
79 | | - raise ImportError(f"Failed to import AdvancedSQLiteSession: {e}") from e |
80 | | - |
81 | | - if name == "AsyncSQLiteSession": |
82 | | - try: |
83 | | - from .async_sqlite_session import AsyncSQLiteSession # noqa: F401 |
84 | | - |
85 | | - return AsyncSQLiteSession |
86 | | - except ModuleNotFoundError as e: |
87 | | - raise ImportError(f"Failed to import AsyncSQLiteSession: {e}") from e |
88 | | - |
89 | | - if name == "DaprSession": |
90 | | - try: |
91 | | - from .dapr_session import DaprSession # noqa: F401 |
92 | | - |
93 | | - return DaprSession |
94 | | - except ModuleNotFoundError as e: |
95 | | - raise ImportError( |
96 | | - "DaprSession requires the 'dapr' extra. " |
97 | | - "Install it with: pip install openai-agents[dapr]" |
98 | | - ) from e |
99 | | - |
100 | | - if name == "DAPR_CONSISTENCY_EVENTUAL": |
101 | | - try: |
102 | | - from .dapr_session import DAPR_CONSISTENCY_EVENTUAL # noqa: F401 |
103 | | - |
104 | | - return DAPR_CONSISTENCY_EVENTUAL |
105 | | - except ModuleNotFoundError as e: |
106 | | - raise ImportError( |
107 | | - "DAPR_CONSISTENCY_EVENTUAL requires the 'dapr' extra. " |
108 | | - "Install it with: pip install openai-agents[dapr]" |
109 | | - ) from e |
110 | | - |
111 | | - if name == "DAPR_CONSISTENCY_STRONG": |
112 | | - try: |
113 | | - from .dapr_session import DAPR_CONSISTENCY_STRONG # noqa: F401 |
114 | | - |
115 | | - return DAPR_CONSISTENCY_STRONG |
116 | | - except ModuleNotFoundError as e: |
117 | | - raise ImportError( |
118 | | - "DAPR_CONSISTENCY_STRONG requires the 'dapr' extra. " |
119 | | - "Install it with: pip install openai-agents[dapr]" |
120 | | - ) from e |
121 | | - |
122 | | - if name == "MongoDBSession": |
123 | | - try: |
124 | | - from .mongodb_session import MongoDBSession # noqa: F401 |
125 | | - |
126 | | - return MongoDBSession |
127 | | - except ModuleNotFoundError as e: |
128 | | - raise ImportError( |
129 | | - "MongoDBSession requires the 'mongodb' extra. " |
130 | | - "Install it with: pip install openai-agents[mongodb]" |
131 | | - ) from e |
132 | | - |
133 | | - raise AttributeError(f"module {__name__} has no attribute {name}") |
| 1 | +"""Session memory backends living in the extensions namespace. |
| 2 | +
|
| 3 | +This package contains optional, production-grade session implementations that |
| 4 | +introduce extra third-party dependencies (database drivers, ORMs, etc.). They |
| 5 | +conform to the [`Session`][agents.memory.session.Session] protocol so they can be |
| 6 | +used as a drop-in replacement for [`SQLiteSession`][agents.memory.sqlite_session.SQLiteSession]. |
| 7 | +""" |
| 8 | + |
| 9 | +from __future__ import annotations |
| 10 | + |
| 11 | +from typing import TYPE_CHECKING, Any |
| 12 | + |
| 13 | +if TYPE_CHECKING: |
| 14 | + from .advanced_sqlite_session import AdvancedSQLiteSession |
| 15 | + from .async_sqlite_session import AsyncSQLiteSession |
| 16 | + from .dapr_session import ( |
| 17 | + DAPR_CONSISTENCY_EVENTUAL, |
| 18 | + DAPR_CONSISTENCY_STRONG, |
| 19 | + DaprSession, |
| 20 | + ) |
| 21 | + from .encrypt_session import EncryptedSession |
| 22 | + from .mongodb_session import MongoDBSession |
| 23 | + from .redis_session import RedisSession |
| 24 | + from .sqlalchemy_session import SQLAlchemySession |
| 25 | + |
| 26 | +__all__: list[str] = [ |
| 27 | + "AdvancedSQLiteSession", |
| 28 | + "AsyncSQLiteSession", |
| 29 | + "DAPR_CONSISTENCY_EVENTUAL", |
| 30 | + "DAPR_CONSISTENCY_STRONG", |
| 31 | + "DaprSession", |
| 32 | + "EncryptedSession", |
| 33 | + "MongoDBSession", |
| 34 | + "RedisSession", |
| 35 | + "SQLAlchemySession", |
| 36 | +] |
| 37 | + |
| 38 | + |
| 39 | +def __getattr__(name: str) -> Any: |
| 40 | + if name == "EncryptedSession": |
| 41 | + try: |
| 42 | + from .encrypt_session import EncryptedSession # noqa: F401 |
| 43 | + |
| 44 | + return EncryptedSession |
| 45 | + except ModuleNotFoundError as e: |
| 46 | + raise ImportError( |
| 47 | + "EncryptedSession requires the 'cryptography' extra. " |
| 48 | + "Install it with: pip install openai-agents[encrypt]" |
| 49 | + ) from e |
| 50 | + |
| 51 | + if name == "RedisSession": |
| 52 | + try: |
| 53 | + from .redis_session import RedisSession # noqa: F401 |
| 54 | + |
| 55 | + return RedisSession |
| 56 | + except ModuleNotFoundError as e: |
| 57 | + raise ImportError( |
| 58 | + "RedisSession requires the 'redis' extra. " |
| 59 | + "Install it with: pip install openai-agents[redis]" |
| 60 | + ) from e |
| 61 | + |
| 62 | + if name == "SQLAlchemySession": |
| 63 | + try: |
| 64 | + from .sqlalchemy_session import SQLAlchemySession # noqa: F401 |
| 65 | + |
| 66 | + return SQLAlchemySession |
| 67 | + except ModuleNotFoundError as e: |
| 68 | + raise ImportError( |
| 69 | + "SQLAlchemySession requires the 'sqlalchemy' extra. " |
| 70 | + "Install it with: pip install openai-agents[sqlalchemy]" |
| 71 | + ) from e |
| 72 | + |
| 73 | + if name == "AdvancedSQLiteSession": |
| 74 | + try: |
| 75 | + from .advanced_sqlite_session import AdvancedSQLiteSession # noqa: F401 |
| 76 | + |
| 77 | + return AdvancedSQLiteSession |
| 78 | + except ModuleNotFoundError as e: |
| 79 | + raise ImportError(f"Failed to import AdvancedSQLiteSession: {e}") from e |
| 80 | + |
| 81 | + if name == "AsyncSQLiteSession": |
| 82 | + try: |
| 83 | + from .async_sqlite_session import AsyncSQLiteSession # noqa: F401 |
| 84 | + |
| 85 | + return AsyncSQLiteSession |
| 86 | + except ModuleNotFoundError as e: |
| 87 | + raise ImportError(f"Failed to import AsyncSQLiteSession: {e}") from e |
| 88 | + |
| 89 | + if name == "DaprSession": |
| 90 | + try: |
| 91 | + from .dapr_session import DaprSession # noqa: F401 |
| 92 | + |
| 93 | + return DaprSession |
| 94 | + except ModuleNotFoundError as e: |
| 95 | + raise ImportError( |
| 96 | + "DaprSession requires the 'dapr' extra. " |
| 97 | + "Install it with: pip install openai-agents[dapr]" |
| 98 | + ) from e |
| 99 | + |
| 100 | + if name == "DAPR_CONSISTENCY_EVENTUAL": |
| 101 | + try: |
| 102 | + from .dapr_session import DAPR_CONSISTENCY_EVENTUAL # noqa: F401 |
| 103 | + |
| 104 | + return DAPR_CONSISTENCY_EVENTUAL |
| 105 | + except ModuleNotFoundError as e: |
| 106 | + raise ImportError( |
| 107 | + "DAPR_CONSISTENCY_EVENTUAL requires the 'dapr' extra. " |
| 108 | + "Install it with: pip install openai-agents[dapr]" |
| 109 | + ) from e |
| 110 | + |
| 111 | + if name == "DAPR_CONSISTENCY_STRONG": |
| 112 | + try: |
| 113 | + from .dapr_session import DAPR_CONSISTENCY_STRONG # noqa: F401 |
| 114 | + |
| 115 | + return DAPR_CONSISTENCY_STRONG |
| 116 | + except ModuleNotFoundError as e: |
| 117 | + raise ImportError( |
| 118 | + "DAPR_CONSISTENCY_STRONG requires the 'dapr' extra. " |
| 119 | + "Install it with: pip install openai-agents[dapr]" |
| 120 | + ) from e |
| 121 | + |
| 122 | + if name == "MongoDBSession": |
| 123 | + try: |
| 124 | + from .mongodb_session import MongoDBSession # noqa: F401 |
| 125 | + |
| 126 | + return MongoDBSession |
| 127 | + except ModuleNotFoundError as e: |
| 128 | + raise ImportError( |
| 129 | + "MongoDBSession requires the 'mongodb' extra. " |
| 130 | + "Install it with: pip install openai-agents[mongodb]" |
| 131 | + ) from e |
| 132 | + |
| 133 | + raise AttributeError(f"module {__name__} has no attribute {name}") |
0 commit comments