Skip to content

Conversation

moonbox3
Copy link
Collaborator

Motivation and Context

Consolidated agent imports initially caused issues by eagerly loading all submodules, which forced users to install every optional dependency -- even if only one agent was needed. This PR introduces a lazy-loading mechanism via __getattr__ in the top-level __init__.py to defer imports until actually accessed. Additionally, a corresponding __init__.pyi type stub file is provided to restore full IDE autocompletion and type hints without compromising runtime behavior.

Description

Lazy load agent dependencies.

Contribution Checklist

@moonbox3 moonbox3 requested a review from a team as a code owner March 25, 2025 07:46
@markwallace-microsoft markwallace-microsoft added the python Pull requests for the Python Semantic Kernel label Mar 25, 2025
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Mar 25, 2025

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
semantic_kernel/agents
   __init__.py10280%31, 35
TOTAL21214245688% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3335 5 💤 0 ❌ 0 🔥 1m 31s ⏱️

@moonbox3 moonbox3 merged commit 2c20c5e into microsoft:main Mar 25, 2025
28 checks passed
jcruzmot-te pushed a commit to thousandeyes/aia-semantic-kernel that referenced this pull request Sep 15, 2025
### Motivation and Context

Consolidated agent imports initially caused issues by eagerly loading
all submodules, which forced users to install every optional dependency
-- even if only one agent was needed. This PR introduces a lazy-loading
mechanism via `__getattr__` in the top-level `__init__.py` to defer
imports until actually accessed. Additionally, a corresponding`
__init__.pyi` type stub file is provided to restore full IDE
autocompletion and type hints without compromising runtime behavior.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Lazy load agent dependencies.

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Pull requests for the Python Semantic Kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants