nvidia-nat-langchain 1.3.0a20251002__py3-none-any.whl → 1.4.0a20251129__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-langchain might be problematic. Click here for more details.

@@ -28,7 +28,13 @@ async def azure_openai_langchain(embedder_config: AzureOpenAIEmbedderModelConfig
28
28
 
29
29
  from langchain_openai import AzureOpenAIEmbeddings
30
30
 
31
- client = AzureOpenAIEmbeddings(**embedder_config.model_dump(exclude={"type"}, by_alias=True, exclude_none=True))
31
+ client = AzureOpenAIEmbeddings(
32
+ **embedder_config.model_dump(exclude={"type", "api_version"},
33
+ by_alias=True,
34
+ exclude_none=True,
35
+ exclude_unset=True),
36
+ api_version=embedder_config.api_version,
37
+ )
32
38
 
33
39
  if isinstance(embedder_config, RetryMixin):
34
40
  client = patch_with_retry(client,
@@ -44,7 +50,8 @@ async def nim_langchain(embedder_config: NIMEmbedderModelConfig, builder: Builde
44
50
 
45
51
  from langchain_nvidia_ai_endpoints import NVIDIAEmbeddings
46
52
 
47
- client = NVIDIAEmbeddings(**embedder_config.model_dump(exclude={"type"}, by_alias=True, exclude_none=True))
53
+ client = NVIDIAEmbeddings(
54
+ **embedder_config.model_dump(exclude={"type"}, by_alias=True, exclude_none=True, exclude_unset=True))
48
55
 
49
56
  if isinstance(embedder_config, RetryMixin):
50
57
  client = patch_with_retry(client,
@@ -60,7 +67,8 @@ async def openai_langchain(embedder_config: OpenAIEmbedderModelConfig, builder:
60
67
 
61
68
  from langchain_openai import OpenAIEmbeddings
62
69
 
63
- client = OpenAIEmbeddings(**embedder_config.model_dump(exclude={"type"}, by_alias=True, exclude_none=True))
70
+ client = OpenAIEmbeddings(
71
+ **embedder_config.model_dump(exclude={"type"}, by_alias=True, exclude_none=True, exclude_unset=True))
64
72
 
65
73
  if isinstance(embedder_config, RetryMixin):
66
74
  client = patch_with_retry(client,
@@ -12,13 +12,16 @@
12
12
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
+ # pylint: disable=unused-argument
15
16
 
17
+ import logging
16
18
  from collections.abc import Sequence
17
19
  from typing import TypeVar
18
20
 
19
21
  from nat.builder.builder import Builder
20
22
  from nat.builder.framework_enum import LLMFrameworkEnum
21
23
  from nat.cli.register_workflow import register_llm_client
24
+ from nat.data_models.llm import APITypeEnum
22
25
  from nat.data_models.llm import LLMBaseConfig
23
26
  from nat.data_models.retry_mixin import RetryMixin
24
27
  from nat.data_models.thinking_mixin import ThinkingMixin
@@ -31,8 +34,11 @@ from nat.llm.utils.thinking import BaseThinkingInjector
31
34
  from nat.llm.utils.thinking import FunctionArgumentWrapper
32
35
  from nat.llm.utils.thinking import patch_with_thinking
33
36
  from nat.utils.exception_handlers.automatic_retries import patch_with_retry
37
+ from nat.utils.responses_api import validate_no_responses_api
34
38
  from nat.utils.type_utils import override
35
39
 
40
+ logger = logging.getLogger(__name__)
41
+
36
42
  ModelType = TypeVar("ModelType")
37
43
 
38
44
 
@@ -65,20 +71,22 @@ def _patch_llm_based_on_config(client: ModelType, llm_config: LLMBaseConfig) ->
65
71
  Raises:
66
72
  ValueError: If the messages are not a valid type for LanguageModelInput.
67
73
  """
68
- system_message = SystemMessage(content=self.system_prompt)
69
- if isinstance(messages, BaseMessage):
70
- new_messages = [system_message, messages]
71
- return FunctionArgumentWrapper(new_messages, *args, **kwargs)
72
- elif isinstance(messages, PromptValue):
73
- new_messages = [system_message, *messages.to_messages()]
74
- return FunctionArgumentWrapper(new_messages, *args, **kwargs)
74
+ if isinstance(messages, PromptValue):
75
+ messages = messages.to_messages()
75
76
  elif isinstance(messages, str):
76
- new_messages = [system_message, HumanMessage(content=messages)]
77
- return FunctionArgumentWrapper(new_messages, *args, **kwargs)
78
- elif isinstance(messages, Sequence):
79
- if all(isinstance(m, BaseMessage) for m in messages):
80
- new_messages = [system_message, *list(messages)]
81
- return FunctionArgumentWrapper(new_messages, *args, **kwargs)
77
+ messages = [HumanMessage(content=messages)]
78
+
79
+ if isinstance(messages, Sequence) and all(isinstance(m, BaseMessage) for m in messages):
80
+ for i, message in enumerate(messages):
81
+ if isinstance(message, SystemMessage):
82
+ if self.system_prompt not in str(message.content):
83
+ messages = list(messages)
84
+ messages[i] = SystemMessage(content=f"{message.content}\n{self.system_prompt}")
85
+ break
86
+ else:
87
+ messages = list(messages)
88
+ messages.insert(0, SystemMessage(content=self.system_prompt))
89
+ return FunctionArgumentWrapper(messages, *args, **kwargs)
82
90
  raise ValueError(f"Unsupported message type: {type(messages)}")
83
91
 
84
92
  if isinstance(llm_config, RetryMixin):
@@ -108,10 +116,13 @@ async def aws_bedrock_langchain(llm_config: AWSBedrockModelConfig, _builder: Bui
108
116
 
109
117
  from langchain_aws import ChatBedrockConverse
110
118
 
119
+ validate_no_responses_api(llm_config, LLMFrameworkEnum.LANGCHAIN)
120
+
111
121
  client = ChatBedrockConverse(**llm_config.model_dump(
112
- exclude={"type", "context_size", "thinking"},
122
+ exclude={"type", "context_size", "thinking", "api_type"},
113
123
  by_alias=True,
114
124
  exclude_none=True,
125
+ exclude_unset=True,
115
126
  ))
116
127
 
117
128
  yield _patch_llm_based_on_config(client, llm_config)
@@ -122,7 +133,15 @@ async def azure_openai_langchain(llm_config: AzureOpenAIModelConfig, _builder: B
122
133
 
123
134
  from langchain_openai import AzureChatOpenAI
124
135
 
125
- client = AzureChatOpenAI(**llm_config.model_dump(exclude={"type", "thinking"}, by_alias=True, exclude_none=True))
136
+ validate_no_responses_api(llm_config, LLMFrameworkEnum.LANGCHAIN)
137
+
138
+ client = AzureChatOpenAI(
139
+ **llm_config.model_dump(exclude={"type", "thinking", "api_type", "api_version"},
140
+ by_alias=True,
141
+ exclude_none=True,
142
+ exclude_unset=True),
143
+ api_version=llm_config.api_version,
144
+ )
126
145
 
127
146
  yield _patch_llm_based_on_config(client, llm_config)
128
147
 
@@ -132,9 +151,16 @@ async def nim_langchain(llm_config: NIMModelConfig, _builder: Builder):
132
151
 
133
152
  from langchain_nvidia_ai_endpoints import ChatNVIDIA
134
153
 
154
+ validate_no_responses_api(llm_config, LLMFrameworkEnum.LANGCHAIN)
155
+
135
156
  # prefer max_completion_tokens over max_tokens
136
157
  client = ChatNVIDIA(
137
- **llm_config.model_dump(exclude={"type", "max_tokens", "thinking"}, by_alias=True, exclude_none=True),
158
+ **llm_config.model_dump(
159
+ exclude={"type", "max_tokens", "thinking", "api_type"},
160
+ by_alias=True,
161
+ exclude_none=True,
162
+ exclude_unset=True,
163
+ ),
138
164
  max_completion_tokens=llm_config.max_tokens,
139
165
  )
140
166
 
@@ -146,13 +172,25 @@ async def openai_langchain(llm_config: OpenAIModelConfig, _builder: Builder):
146
172
 
147
173
  from langchain_openai import ChatOpenAI
148
174
 
149
- # If stream_usage is specified, it will override the default value of True.
150
- client = ChatOpenAI(stream_usage=True,
151
- **llm_config.model_dump(
152
- exclude={"type", "thinking"},
153
- by_alias=True,
154
- exclude_none=True,
155
- ))
175
+ if llm_config.api_type == APITypeEnum.RESPONSES:
176
+ client = ChatOpenAI(stream_usage=True,
177
+ use_responses_api=True,
178
+ use_previous_response_id=True,
179
+ **llm_config.model_dump(
180
+ exclude={"type", "thinking", "api_type"},
181
+ by_alias=True,
182
+ exclude_none=True,
183
+ exclude_unset=True,
184
+ ))
185
+ else:
186
+ # If stream_usage is specified, it will override the default value of True.
187
+ client = ChatOpenAI(stream_usage=True,
188
+ **llm_config.model_dump(
189
+ exclude={"type", "thinking", "api_type"},
190
+ by_alias=True,
191
+ exclude_none=True,
192
+ exclude_unset=True,
193
+ ))
156
194
 
157
195
  yield _patch_llm_based_on_config(client, llm_config)
158
196
 
@@ -162,6 +200,9 @@ async def litellm_langchain(llm_config: LiteLlmModelConfig, _builder: Builder):
162
200
 
163
201
  from langchain_litellm import ChatLiteLLM
164
202
 
165
- client = ChatLiteLLM(**llm_config.model_dump(exclude={"type", "thinking"}, by_alias=True, exclude_none=True))
203
+ validate_no_responses_api(llm_config, LLMFrameworkEnum.LANGCHAIN)
204
+
205
+ client = ChatLiteLLM(**llm_config.model_dump(
206
+ exclude={"type", "thinking", "api_type"}, by_alias=True, exclude_none=True, exclude_unset=True))
166
207
 
167
208
  yield _patch_llm_based_on_config(client, llm_config)
@@ -13,9 +13,13 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ from pydantic import Field
17
+
16
18
  from nat.builder.builder import Builder
17
19
  from nat.builder.function_info import FunctionInfo
18
20
  from nat.cli.register_workflow import register_function
21
+ from nat.data_models.common import SerializableSecretStr
22
+ from nat.data_models.common import get_secret_value
19
23
  from nat.data_models.function import FunctionBaseConfig
20
24
 
21
25
 
@@ -26,7 +30,7 @@ class TavilyInternetSearchToolConfig(FunctionBaseConfig, name="tavily_internet_s
26
30
  Requires a TAVILY_API_KEY.
27
31
  """
28
32
  max_results: int = 3
29
- api_key: str = ""
33
+ api_key: SerializableSecretStr = Field(default="", description="The API key for the Tavily service.")
30
34
 
31
35
 
32
36
  @register_function(config_type=TavilyInternetSearchToolConfig)
@@ -36,7 +40,8 @@ async def tavily_internet_search(tool_config: TavilyInternetSearchToolConfig, bu
36
40
  from langchain_tavily import TavilySearch
37
41
 
38
42
  if not os.environ.get("TAVILY_API_KEY"):
39
- os.environ["TAVILY_API_KEY"] = tool_config.api_key
43
+ if tool_config.api_key:
44
+ os.environ["TAVILY_API_KEY"] = get_secret_value(tool_config.api_key)
40
45
  # This tavily tool requires an API Key and it must be set as an environment variable (TAVILY_API_KEY)
41
46
  # Refer to create_customize_workflow.md for instructions of getting the API key
42
47
 
@@ -1,7 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nvidia-nat-langchain
3
- Version: 1.3.0a20251002
3
+ Version: 1.4.0a20251129
4
4
  Summary: Subpackage for LangChain/LangGraph 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
5
10
  Keywords: ai,rag,agents
6
11
  Classifier: Programming Language :: Python
7
12
  Classifier: Programming Language :: Python :: 3.11
@@ -9,7 +14,10 @@ Classifier: Programming Language :: Python :: 3.12
9
14
  Classifier: Programming Language :: Python :: 3.13
10
15
  Requires-Python: <3.14,>=3.11
11
16
  Description-Content-Type: text/markdown
12
- Requires-Dist: nvidia-nat==v1.3.0a20251002
17
+ License-File: LICENSE-3rd-party.txt
18
+ License-File: LICENSE.md
19
+ Requires-Dist: nvidia-nat==v1.4.0a20251129
20
+ Requires-Dist: langchain~=0.3.27
13
21
  Requires-Dist: langchain-aws~=0.2.31
14
22
  Requires-Dist: langchain-core~=0.3.75
15
23
  Requires-Dist: langchain-litellm~=0.2.3
@@ -18,6 +26,7 @@ Requires-Dist: langchain-nvidia-ai-endpoints~=0.3.17
18
26
  Requires-Dist: langchain-openai~=0.3.32
19
27
  Requires-Dist: langchain-tavily~=0.2.11
20
28
  Requires-Dist: langgraph~=0.6.7
29
+ Dynamic: license-file
21
30
 
22
31
  <!--
23
32
  SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
@@ -1,17 +1,19 @@
1
1
  nat/meta/pypi.md,sha256=T_KFtTXVxhFM8Y6K3OlNByA5sTXLQuqqUpHgNOCvZBU,1120
2
2
  nat/plugins/langchain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- nat/plugins/langchain/embedder.py,sha256=ZSESaazyz7y3F0GSSsWRe_xfvxOe0Mwd45wEAkQ2jJk,3339
4
- nat/plugins/langchain/llm.py,sha256=vlR_4bMLmmpXTv4kp3xFOB1eFeJ-wX1_DqnsQpPunAo,7110
3
+ nat/plugins/langchain/embedder.py,sha256=Ie-J4N4lvygW0zNKklKZVSYxYFcRW6p_QlRdcz0WxcE,3607
4
+ nat/plugins/langchain/llm.py,sha256=FaEPleu_aBCsQ-6tt3ofr1A2Oa_ta60tMb0yGGhiWSo,8561
5
5
  nat/plugins/langchain/register.py,sha256=jgq6wSJoGQIZFJhS8RbUs25cLgNJjCkFu4M6qaWJS_4,906
6
6
  nat/plugins/langchain/retriever.py,sha256=SWbXXOezEUuPACnmSSU497NAmEVEMj2SrFJGodkRg34,2644
7
7
  nat/plugins/langchain/tool_wrapper.py,sha256=Zgb2_XB4bEhjPPeqS-ZH_OJT_pcQmteX7u03N_qCLfc,2121
8
8
  nat/plugins/langchain/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  nat/plugins/langchain/tools/code_generation_tool.py,sha256=f5pna0WMOx3QOS4WnaMFKD7tBZ1-tS0PfI0IMYobtTQ,2723
10
10
  nat/plugins/langchain/tools/register.py,sha256=uemxqLxcNk1bGX4crV52oMphLTZWonStzkXwTZeG2Rw,889
11
- nat/plugins/langchain/tools/tavily_internet_search.py,sha256=UFMP1xh_kC3fydMQBeV-oDZ-M7jnLcs5OkMSzgm7mng,2653
11
+ nat/plugins/langchain/tools/tavily_internet_search.py,sha256=W5sdZ9hobPc3xbnWPSbtFBClIn14EM8xT0XUVF2HpWo,2928
12
12
  nat/plugins/langchain/tools/wikipedia_search.py,sha256=431YwLsjoC_mdvMZ_gY0Q37Uqaue2ASnAHpwr4jWCaU,2197
13
- nvidia_nat_langchain-1.3.0a20251002.dist-info/METADATA,sha256=Qn2MSPoBNuK-dXVY1V_7EaO8Z2itHlP2iwUEAIe5hoI,1924
14
- nvidia_nat_langchain-1.3.0a20251002.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
- nvidia_nat_langchain-1.3.0a20251002.dist-info/entry_points.txt,sha256=4deXsMn97I012HhDw0UjoqcZ8eEoZ7BnqaRx5QmzebY,123
16
- nvidia_nat_langchain-1.3.0a20251002.dist-info/top_level.txt,sha256=8-CJ2cP6-f0ZReXe5Hzqp-5pvzzHz-5Ds5H2bGqh1-U,4
17
- nvidia_nat_langchain-1.3.0a20251002.dist-info/RECORD,,
13
+ nvidia_nat_langchain-1.4.0a20251129.dist-info/licenses/LICENSE-3rd-party.txt,sha256=fOk5jMmCX9YoKWyYzTtfgl-SUy477audFC5hNY4oP7Q,284609
14
+ nvidia_nat_langchain-1.4.0a20251129.dist-info/licenses/LICENSE.md,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
15
+ nvidia_nat_langchain-1.4.0a20251129.dist-info/METADATA,sha256=Xn_gNxlhmgfYGVSOKm3zrEfbrR20kJYpeUoMuzdu0ro,2263
16
+ nvidia_nat_langchain-1.4.0a20251129.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
+ nvidia_nat_langchain-1.4.0a20251129.dist-info/entry_points.txt,sha256=4deXsMn97I012HhDw0UjoqcZ8eEoZ7BnqaRx5QmzebY,123
18
+ nvidia_nat_langchain-1.4.0a20251129.dist-info/top_level.txt,sha256=8-CJ2cP6-f0ZReXe5Hzqp-5pvzzHz-5Ds5H2bGqh1-U,4
19
+ nvidia_nat_langchain-1.4.0a20251129.dist-info/RECORD,,