nvidia-nat-semantic-kernel 1.4.0a20251122__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of nvidia-nat-semantic-kernel might be problematic. Click here for more details.

nat/meta/pypi.md ADDED
@@ -0,0 +1,23 @@
1
+ <!--
2
+ SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3
+ SPDX-License-Identifier: Apache-2.0
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ -->
17
+
18
+ ![NVIDIA NeMo Agent Toolkit](https://media.githubusercontent.com/media/NVIDIA/NeMo-Agent-Toolkit/refs/heads/main/docs/source/_static/banner.png "NeMo Agent toolkit banner image")
19
+
20
+ # NVIDIA NeMo Agent Toolkit Subpackage
21
+ This is a subpackage for Semantic-Kernel integration in NeMo Agent toolkit.
22
+
23
+ For more information about the NVIDIA NeMo Agent toolkit, please visit the [NeMo Agent toolkit GitHub Repo](https://github.com/NVIDIA/NeMo-Agent-Toolkit).
File without changes
@@ -0,0 +1,115 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ from typing import TypeVar
17
+
18
+ from nat.builder.builder import Builder
19
+ from nat.builder.framework_enum import LLMFrameworkEnum
20
+ from nat.cli.register_workflow import register_llm_client
21
+ from nat.data_models.common import get_secret_value
22
+ from nat.data_models.llm import LLMBaseConfig
23
+ from nat.data_models.retry_mixin import RetryMixin
24
+ from nat.data_models.thinking_mixin import ThinkingMixin
25
+ from nat.llm.azure_openai_llm import AzureOpenAIModelConfig
26
+ from nat.llm.openai_llm import OpenAIModelConfig
27
+ from nat.llm.utils.thinking import BaseThinkingInjector
28
+ from nat.llm.utils.thinking import FunctionArgumentWrapper
29
+ from nat.llm.utils.thinking import patch_with_thinking
30
+ from nat.utils.exception_handlers.automatic_retries import patch_with_retry
31
+ from nat.utils.responses_api import validate_no_responses_api
32
+ from nat.utils.type_utils import override
33
+
34
+ ModelType = TypeVar("ModelType")
35
+
36
+
37
+ def _patch_llm_based_on_config(client: ModelType, llm_config: LLMBaseConfig) -> ModelType:
38
+
39
+ from semantic_kernel.contents.chat_history import ChatHistory
40
+
41
+ class SemanticKernelThinkingInjector(BaseThinkingInjector):
42
+
43
+ @override
44
+ def inject(self, chat_history: ChatHistory, *args, **kwargs) -> FunctionArgumentWrapper:
45
+ """
46
+ Inject a system prompt into the chat_history.
47
+
48
+ The chat_history is the first (non-object) argument to the function.
49
+ The rest of the arguments are passed through unchanged.
50
+
51
+ Args:
52
+ chat_history: The ChatHistory object to inject the system prompt into.
53
+ *args: The rest of the arguments to the function.
54
+ **kwargs: The rest of the keyword arguments to the function.
55
+
56
+ Returns:
57
+ FunctionArgumentWrapper: An object that contains the transformed args and kwargs.
58
+ """
59
+ if chat_history.system_message is None:
60
+ new_messages = ChatHistory(chat_history.messages, system_message=self.system_prompt)
61
+ return FunctionArgumentWrapper(new_messages, *args, **kwargs)
62
+ else:
63
+ new_messages = ChatHistory(
64
+ chat_history.messages,
65
+ system_message=f"{self.system_prompt}\n\n{chat_history.system_message}",
66
+ )
67
+ return FunctionArgumentWrapper(new_messages, *args, **kwargs)
68
+
69
+ if isinstance(llm_config, RetryMixin):
70
+ client = patch_with_retry(client,
71
+ retries=llm_config.num_retries,
72
+ retry_codes=llm_config.retry_on_status_codes,
73
+ retry_on_messages=llm_config.retry_on_errors)
74
+
75
+ if isinstance(llm_config, ThinkingMixin) and llm_config.thinking_system_prompt is not None:
76
+ client = patch_with_thinking(
77
+ client,
78
+ SemanticKernelThinkingInjector(
79
+ system_prompt=llm_config.thinking_system_prompt,
80
+ function_names=[
81
+ "get_chat_message_contents",
82
+ "get_streaming_chat_message_contents",
83
+ ],
84
+ ))
85
+
86
+ return client
87
+
88
+
89
+ @register_llm_client(config_type=AzureOpenAIModelConfig, wrapper_type=LLMFrameworkEnum.SEMANTIC_KERNEL)
90
+ async def azure_openai_semantic_kernel(llm_config: AzureOpenAIModelConfig, _builder: Builder):
91
+
92
+ from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion
93
+
94
+ validate_no_responses_api(llm_config, LLMFrameworkEnum.SEMANTIC_KERNEL)
95
+
96
+ llm = AzureChatCompletion(
97
+ api_key=get_secret_value(llm_config.api_key),
98
+ api_version=llm_config.api_version,
99
+ endpoint=llm_config.azure_endpoint,
100
+ deployment_name=llm_config.azure_deployment,
101
+ )
102
+
103
+ yield _patch_llm_based_on_config(llm, llm_config)
104
+
105
+
106
+ @register_llm_client(config_type=OpenAIModelConfig, wrapper_type=LLMFrameworkEnum.SEMANTIC_KERNEL)
107
+ async def openai_semantic_kernel(llm_config: OpenAIModelConfig, _builder: Builder):
108
+
109
+ from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
110
+
111
+ validate_no_responses_api(llm_config, LLMFrameworkEnum.SEMANTIC_KERNEL)
112
+
113
+ llm = OpenAIChatCompletion(ai_model_id=llm_config.model_name)
114
+
115
+ yield _patch_llm_based_on_config(llm, llm_config)
@@ -0,0 +1,22 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # flake8: noqa
17
+ # isort:skip_file
18
+
19
+ # Import any providers which need to be automatically registered here
20
+
21
+ from . import llm
22
+ from . import tool_wrapper
@@ -0,0 +1,161 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import logging
17
+ import types
18
+ from collections.abc import Callable
19
+ from dataclasses import is_dataclass
20
+ from typing import Any
21
+ from typing import Union
22
+ from typing import get_args
23
+ from typing import get_origin
24
+
25
+ from pydantic import BaseModel
26
+
27
+ from nat.builder.builder import Builder
28
+ from nat.builder.framework_enum import LLMFrameworkEnum
29
+ from nat.builder.function import Function
30
+ from nat.cli.register_workflow import register_tool_wrapper
31
+
32
+ logger = logging.getLogger(__name__)
33
+
34
+
35
+ def get_type_info(field_type):
36
+ origin = get_origin(field_type)
37
+ if origin is None:
38
+ # It’s a simple type
39
+ return getattr(field_type, "__name__", str(field_type))
40
+
41
+ # Handle Union types specially
42
+ if origin in (Union, types.UnionType):
43
+ # Pick the first type that isn’t NoneType
44
+ non_none = [arg for arg in get_args(field_type) if arg is not type(None)]
45
+ if non_none:
46
+ return getattr(non_none[0], "__name__", str(non_none[0]))
47
+
48
+ return 'str' # fallback if union is only str (unlikely)
49
+
50
+ # For other generics, capture both the origin and its parameters
51
+ return getattr(origin, "__name__", str(origin))
52
+
53
+
54
+ def resolve_type(t):
55
+ origin = get_origin(t)
56
+ if origin in (Union, types.UnionType):
57
+ # Pick the first type that isn’t NoneType
58
+ for arg in get_args(t):
59
+ if arg is not None:
60
+ return arg
61
+
62
+ return t # fallback if union is only NoneType (unlikely)
63
+ return t
64
+
65
+
66
+ @register_tool_wrapper(wrapper_type=LLMFrameworkEnum.SEMANTIC_KERNEL)
67
+ def semantic_kernel_tool_wrapper(name: str, fn: Function, builder: Builder):
68
+
69
+ async def callable_ainvoke(*args, **kwargs):
70
+ return await fn.acall_invoke(*args, **kwargs)
71
+
72
+ async def callable_astream(*args, **kwargs):
73
+ async for item in fn.acall_stream(*args, **kwargs):
74
+ yield item
75
+
76
+ def nat_kernel_function(
77
+ func: Callable[..., object] | None = None,
78
+ nat_function: Function | None = None,
79
+ name: str | None = None,
80
+ description: str | None = None,
81
+ ) -> Callable[..., Any]:
82
+ """
83
+ Modified version of Semantic Kernel's kernel_function decorator.
84
+
85
+ Uses `nat` Function properties instead of doing type inference on the function's inner
86
+ """
87
+
88
+ def decorator(func: Callable[..., object]) -> Callable[..., object]:
89
+ """The actual decorator function."""
90
+ setattr(func, "__kernel_function__", True)
91
+ setattr(func, "__kernel_function_description__", description or nat_function.description)
92
+ setattr(func, "__kernel_function_name__", name or nat_function.config.type)
93
+
94
+ # Always defer to single output schema, if present, for now
95
+ # No need to check streaming output is present given one of the two is always present
96
+ has_single = nat_function.has_single_output
97
+ has_streaming = nat_function.has_streaming_output
98
+ output_schema = nat_function.single_output_schema if has_single else nat_function.streaming_output_schema
99
+ setattr(func, "__kernel_function_streaming__", not nat_function.has_single_output if has_single else True)
100
+
101
+ if has_single and has_streaming:
102
+ logger.warning("Function has both single and streaming output schemas. "
103
+ "Defaulting to single output schema.")
104
+
105
+ input_annotations = []
106
+ for arg_name, annotation in nat_function.input_schema.model_fields.items():
107
+ type_obj = resolve_type(annotation.annotation)
108
+ include_in_choices = True
109
+ if isinstance(type_obj, type) and (issubclass(type_obj, BaseModel) or is_dataclass(type_obj)):
110
+ logger.warning(
111
+ "Nested non-native model detected in input schema for parameter: %s. "
112
+ "Setting include_in_function_choices to False.",
113
+ arg_name)
114
+ # Don't error out here
115
+ # Just instead avoid showing the tool to the model
116
+ include_in_choices = False
117
+ input_annotations.append({
118
+ "is_required": annotation.is_required(),
119
+ "name": arg_name,
120
+ "type_": get_type_info(annotation.annotation),
121
+ "type_object": type_obj,
122
+ "include_in_function_choices": include_in_choices
123
+ })
124
+
125
+ setattr(func, "__kernel_function_parameters__", input_annotations)
126
+
127
+ return_annotations = []
128
+ for arg_name, annotation in output_schema.model_fields.items():
129
+ type_obj = resolve_type(annotation.annotation)
130
+ include_in_choices = True
131
+ if isinstance(type_obj, type) and (issubclass(type_obj, BaseModel) or is_dataclass(type_obj)):
132
+ logger.warning(
133
+ "Nested non-native model detected in output schema for parameter: %s. "
134
+ "Setting include_in_function_choices to False.",
135
+ arg_name)
136
+ include_in_choices = False
137
+ return_annotations.append({
138
+ "is_required": annotation.is_required(),
139
+ "name": arg_name,
140
+ "type_": get_type_info(annotation.annotation),
141
+ "type_object": type_obj,
142
+ "include_in_function_choices": include_in_choices
143
+ })
144
+ return_annotation = return_annotations[0]
145
+
146
+ setattr(func, "__kernel_function_return_type__", return_annotation.get("type_", "None"))
147
+ setattr(func, "__kernel_function_return_type_object__", return_annotation.get("type_object", None))
148
+ setattr(func, "__kernel_function_return_description__", return_annotation.get("description", ""))
149
+ setattr(func, "__kernel_function_return_required__", return_annotation.get("is_required", False))
150
+ return func
151
+
152
+ if func:
153
+ return decorator(func)
154
+ return decorator
155
+
156
+ if fn.has_streaming_output and not fn.has_single_output:
157
+ kernel_func = nat_kernel_function(func=callable_astream, nat_function=fn, name=name, description=fn.description)
158
+ else:
159
+ kernel_func = nat_kernel_function(func=callable_ainvoke, nat_function=fn, name=name, description=fn.description)
160
+
161
+ return {name: kernel_func}
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.4
2
+ Name: nvidia-nat-semantic-kernel
3
+ Version: 1.4.0a20251122
4
+ Summary: Subpackage for Semantic-Kernel integration in NeMo Agent toolkit
5
+ Author: NVIDIA Corporation
6
+ Maintainer: NVIDIA Corporation
7
+ License: Apache-2.0
8
+ Project-URL: documentation, https://docs.nvidia.com/nemo/agent-toolkit/latest/
9
+ Project-URL: source, https://github.com/NVIDIA/NeMo-Agent-Toolkit
10
+ Keywords: ai,rag,agents
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Requires-Python: <3.14,>=3.11
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE-3rd-party.txt
18
+ License-File: LICENSE.md
19
+ Requires-Dist: nvidia-nat==v1.4.0a20251122
20
+ Requires-Dist: semantic-kernel~=1.35
21
+ Dynamic: license-file
22
+
23
+ <!--
24
+ SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
25
+ SPDX-License-Identifier: Apache-2.0
26
+
27
+ Licensed under the Apache License, Version 2.0 (the "License");
28
+ you may not use this file except in compliance with the License.
29
+ You may obtain a copy of the License at
30
+
31
+ http://www.apache.org/licenses/LICENSE-2.0
32
+
33
+ Unless required by applicable law or agreed to in writing, software
34
+ distributed under the License is distributed on an "AS IS" BASIS,
35
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36
+ See the License for the specific language governing permissions and
37
+ limitations under the License.
38
+ -->
39
+
40
+ ![NVIDIA NeMo Agent Toolkit](https://media.githubusercontent.com/media/NVIDIA/NeMo-Agent-Toolkit/refs/heads/main/docs/source/_static/banner.png "NeMo Agent toolkit banner image")
41
+
42
+ # NVIDIA NeMo Agent Toolkit Subpackage
43
+ This is a subpackage for Semantic-Kernel integration in NeMo Agent toolkit.
44
+
45
+ For more information about the NVIDIA NeMo Agent toolkit, please visit the [NeMo Agent toolkit GitHub Repo](https://github.com/NVIDIA/NeMo-Agent-Toolkit).
@@ -0,0 +1,12 @@
1
+ nat/meta/pypi.md,sha256=rFmwVds3akmoz0TE1SOjCjCUbB6SWfaRex_Vi5OfUAk,1116
2
+ nat/plugins/semantic_kernel/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ nat/plugins/semantic_kernel/llm.py,sha256=nuadrIqpc4SXQT6EWii8M7I6_cCZR0qPArZtfnpKUGo,4908
4
+ nat/plugins/semantic_kernel/register.py,sha256=_R3bhGmz___696_NwyIcpw3koMBiWqIFoWEFJ0VAgXs,831
5
+ nat/plugins/semantic_kernel/tool_wrapper.py,sha256=N6WGEdveLYFKtOKjxEMMNT5vG8QJUoSddtswQ1fPEzQ,7121
6
+ nvidia_nat_semantic_kernel-1.4.0a20251122.dist-info/licenses/LICENSE-3rd-party.txt,sha256=fOk5jMmCX9YoKWyYzTtfgl-SUy477audFC5hNY4oP7Q,284609
7
+ nvidia_nat_semantic_kernel-1.4.0a20251122.dist-info/licenses/LICENSE.md,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
8
+ nvidia_nat_semantic_kernel-1.4.0a20251122.dist-info/METADATA,sha256=44zL_FgBnbAGMEQrqfZ4mXMWbQTvAFWWbat24K9t9N8,1946
9
+ nvidia_nat_semantic_kernel-1.4.0a20251122.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ nvidia_nat_semantic_kernel-1.4.0a20251122.dist-info/entry_points.txt,sha256=0jCtQBAn5Ohs9XoVCF34WvNCV33OwAsH8bjFzgw_ByM,76
11
+ nvidia_nat_semantic_kernel-1.4.0a20251122.dist-info/top_level.txt,sha256=8-CJ2cP6-f0ZReXe5Hzqp-5pvzzHz-5Ds5H2bGqh1-U,4
12
+ nvidia_nat_semantic_kernel-1.4.0a20251122.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [nat.components]
2
+ nat_semantic_kernel = nat.plugins.semantic_kernel.register