Skip to content

refactor(utils): Introduce lazy imports for BailianClient/GPDBClient …#82

Open
Sodawyx wants to merge 1 commit intomainfrom
adapt-for-cli
Open

refactor(utils): Introduce lazy imports for BailianClient/GPDBClient …#82
Sodawyx wants to merge 1 commit intomainfrom
adapt-for-cli

Conversation

@Sodawyx
Copy link
Copy Markdown
Collaborator

@Sodawyx Sodawyx commented Apr 13, 2026

…and memory_collection module

This change refactors the code to use lazy imports for BailianClient, GPDBClient, and the entire memory_collection module. By doing so, we defer the loading of these components until they're actually needed, which helps reduce startup time and avoids importing unnecessary dependencies like tablestore, mem0ai, numpy, fastapi, uvicorn, etc., when simply importing the agentrun package.

The key changes include:

  • Moving BailianClient and GPDBClient imports inside their respective methods using local imports.
  • Adding conditional imports (TYPE_CHECKING) for memory_collection items.
  • Implementing a custom __getattr__ function that lazily loads modules on demand rather than during initial import.

Co-developed-by: Aone Copilot noreply@alibaba-inc.com

Thank you for creating a pull request to contribute to Serverless Devs agentrun-sdk-python code! Before you open the request please answer the following questions to help it be more easily integrated. Please check the boxes "[ ]" with "[x]" when done too.
Please select one of the PR types below to complete


Fix bugs

Bug detail

The specific manifestation of the bug or the associated issue.

Pull request tasks

  • Add test cases for the changes
  • Passed the CI test

Update docs

Reason for update

Why do you need to update your documentation?

Pull request tasks

  • Update Chinese documentation
  • Update English documentation

Add contributor

Contributed content

  • Code
  • Document

Content detail

if content_type == 'code' || content_type == 'document':
    please tell us `PR url`,like: https://github.com/Serverless-Devs/agentrun-sdk-python/pull/1
else:
    please describe your contribution in detail

Others

Reason for update

Why do you need to update your documentation?

…and memory_collection module

This change refactors the code to use lazy imports for `BailianClient`, `GPDBClient`, and the entire `memory_collection` module. By doing so, we defer the loading of these components until they're actually needed, which helps reduce startup time and avoids importing unnecessary dependencies like tablestore, mem0ai, numpy, fastapi, uvicorn, etc., when simply importing the `agentrun` package.

The key changes include:
- Moving `BailianClient` and `GPDBClient` imports inside their respective methods using local imports.
- Adding conditional imports (`TYPE_CHECKING`) for `memory_collection` items.
- Implementing a custom `__getattr__` function that lazily loads modules on demand rather than during initial import.

Co-developed-by: Aone Copilot <noreply@alibaba-inc.com>
Signed-off-by: Sodawyx <sodawyx@126.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant