|
57 | 57 | CredentialUpdateInput, |
58 | 58 | RelatedResource, |
59 | 59 | ) |
60 | | -# Memory Collection |
61 | | -from agentrun.memory_collection import ( |
62 | | - EmbedderConfig, |
63 | | - EmbedderConfigConfig, |
64 | | - LLMConfig, |
65 | | - LLMConfigConfig, |
66 | | - MemoryCollection, |
67 | | - MemoryCollectionClient, |
68 | | - MemoryCollectionCreateInput, |
69 | | - MemoryCollectionListInput, |
70 | | - MemoryCollectionListOutput, |
71 | | - MemoryCollectionUpdateInput, |
72 | | - NetworkConfiguration, |
73 | | - VectorStoreConfig, |
74 | | - VectorStoreConfigConfig, |
75 | | -) |
| 60 | + |
| 61 | +# Memory Collection - 延迟导入以避免 tablestore/mem0ai 等重型依赖 |
| 62 | +# Lazy import to avoid heavy dependencies (tablestore, mem0ai, numpy, etc.) |
| 63 | +# Type hints for IDE and type checkers |
| 64 | +if TYPE_CHECKING: |
| 65 | + from agentrun.memory_collection import ( |
| 66 | + EmbedderConfig, |
| 67 | + EmbedderConfigConfig, |
| 68 | + LLMConfig, |
| 69 | + LLMConfigConfig, |
| 70 | + MemoryCollection, |
| 71 | + MemoryCollectionClient, |
| 72 | + MemoryCollectionCreateInput, |
| 73 | + MemoryCollectionListInput, |
| 74 | + MemoryCollectionListOutput, |
| 75 | + MemoryCollectionUpdateInput, |
| 76 | + NetworkConfiguration, |
| 77 | + VectorStoreConfig, |
| 78 | + VectorStoreConfigConfig, |
| 79 | + ) |
76 | 80 | # Model Service |
77 | 81 | from agentrun.model import ( |
78 | 82 | BackendType, |
|
304 | 308 | "Config", |
305 | 309 | ] |
306 | 310 |
|
| 311 | +# Memory Collection 模块的所有导出(延迟加载) |
| 312 | +# Memory Collection module exports (lazy loaded) |
| 313 | +_MEMORY_COLLECTION_EXPORTS = { |
| 314 | + "MemoryCollection", |
| 315 | + "MemoryCollectionClient", |
| 316 | + "EmbedderConfig", |
| 317 | + "EmbedderConfigConfig", |
| 318 | + "LLMConfig", |
| 319 | + "LLMConfigConfig", |
| 320 | + "NetworkConfiguration", |
| 321 | + "VectorStoreConfig", |
| 322 | + "VectorStoreConfigConfig", |
| 323 | + "MemoryCollectionCreateInput", |
| 324 | + "MemoryCollectionUpdateInput", |
| 325 | + "MemoryCollectionListInput", |
| 326 | + "MemoryCollectionListOutput", |
| 327 | +} |
| 328 | + |
307 | 329 | # Server 模块的所有导出 |
308 | 330 | _SERVER_EXPORTS = { |
309 | 331 | "AgentRunServer", |
|
346 | 368 |
|
347 | 369 |
|
348 | 370 | def __getattr__(name: str): |
349 | | - """延迟加载 server 模块的导出,避免可选依赖导致导入失败 |
| 371 | + """延迟加载 server / memory_collection 模块的导出,避免重型依赖在 |
| 372 | + import agentrun 时被立即加载。 |
350 | 373 |
|
351 | | - 当用户访问 server 相关的类时,才尝试导入 server 模块。 |
352 | | - 如果 server 可选依赖未安装,会抛出清晰的错误提示。 |
| 374 | + Lazy-load server / memory_collection module exports to avoid pulling in |
| 375 | + heavy dependencies (tablestore, mem0ai, fastapi, etc.) at import time. |
353 | 376 | """ |
| 377 | + # Memory Collection 模块(延迟加载以避免 tablestore/mem0ai 依赖) |
| 378 | + if name in _MEMORY_COLLECTION_EXPORTS: |
| 379 | + from agentrun import memory_collection |
| 380 | + |
| 381 | + return getattr(memory_collection, name) |
| 382 | + |
| 383 | + # Server 模块(延迟加载以避免 fastapi/uvicorn 依赖) |
354 | 384 | if name in _SERVER_EXPORTS: |
355 | 385 | try: |
356 | 386 | from agentrun import server |
|
0 commit comments