Skip to content

Commit e9c428b

Browse files
authored
chore: Define precedence for deprecated 'auth_tokens' vs. 'auth_headers' (#237)
This PR addresses the scenario where a user provides both `auth_tokens` and `auth_headers`, both of which are deprecated arguments. ### Problem Previously, if a user provided both `auth_tokens` and `auth_headers`, the authentication tokens from `auth_headers` were prioritized. This created an inconsistent behavior, especially considering that `auth_tokens` was deprecated more recently than `auth_headers`. ### Solution This change shifts the precedence to `auth_tokens`. Now, if both `auth_tokens` and `auth_headers` are present, only the authentication tokens specified in `auth_tokens` will be considered. ### Reasoning 1. `auth_tokens` was deprecated more recently than `auth_headers`. Prioritizing the more recently deprecated argument provides a clearer signal to users about the intended deprecation path and guides them towards the recommended, non-deprecated args. 2. We opted *not* to merge authentication tokens from both deprecated arguments. Merging could lead to increased user confusion and inadvertently encourage continued reliance on these legacy features, hindering migration efforts. 3. This approach aligns with our broader deprecation strategy. For instance, when a user provides `auth_token_getters` (the current recommended approach) alongside a deprecated argument like `auth_tokens`, `auth_token_getters` takes precedence and overrides the deprecated argument. This PR extends that "latest argument wins" principle to the deprecated arguments themselves, ensuring consistent behavior.
1 parent 9527824 commit e9c428b

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

packages/toolbox-langchain/src/toolbox_langchain/async_client.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,31 @@ async def aload_tool(
6868
Returns:
6969
A tool loaded from the Toolbox.
7070
"""
71-
if auth_headers:
71+
if auth_tokens:
7272
if auth_token_getters:
7373
warn(
74-
"Both `auth_token_getters` and `auth_headers` are provided. `auth_headers` is deprecated, and `auth_token_getters` will be used.",
74+
"Both `auth_token_getters` and `auth_tokens` are provided. `auth_tokens` is deprecated, and `auth_token_getters` will be used.",
7575
DeprecationWarning,
7676
)
7777
else:
7878
warn(
79-
"Argument `auth_headers` is deprecated. Use `auth_token_getters` instead.",
79+
"Argument `auth_tokens` is deprecated. Use `auth_token_getters` instead.",
8080
DeprecationWarning,
8181
)
82-
auth_token_getters = auth_headers
82+
auth_token_getters = auth_tokens
8383

84-
if auth_tokens:
84+
if auth_headers:
8585
if auth_token_getters:
8686
warn(
87-
"Both `auth_token_getters` and `auth_tokens` are provided. `auth_tokens` is deprecated, and `auth_token_getters` will be used.",
87+
"Both `auth_token_getters` and `auth_headers` are provided. `auth_headers` is deprecated, and `auth_token_getters` will be used.",
8888
DeprecationWarning,
8989
)
9090
else:
9191
warn(
92-
"Argument `auth_tokens` is deprecated. Use `auth_token_getters` instead.",
92+
"Argument `auth_headers` is deprecated. Use `auth_token_getters` instead.",
9393
DeprecationWarning,
9494
)
95-
auth_token_getters = auth_tokens
95+
auth_token_getters = auth_headers
9696

9797
url = f"{self.__url}/api/tool/{tool_name}"
9898
manifest: ManifestSchema = await _load_manifest(url, self.__session)
@@ -136,31 +136,31 @@ async def aload_toolset(
136136
Returns:
137137
A list of all tools loaded from the Toolbox.
138138
"""
139-
if auth_headers:
139+
if auth_tokens:
140140
if auth_token_getters:
141141
warn(
142-
"Both `auth_token_getters` and `auth_headers` are provided. `auth_headers` is deprecated, and `auth_token_getters` will be used.",
142+
"Both `auth_token_getters` and `auth_tokens` are provided. `auth_tokens` is deprecated, and `auth_token_getters` will be used.",
143143
DeprecationWarning,
144144
)
145145
else:
146146
warn(
147-
"Argument `auth_headers` is deprecated. Use `auth_token_getters` instead.",
147+
"Argument `auth_tokens` is deprecated. Use `auth_token_getters` instead.",
148148
DeprecationWarning,
149149
)
150-
auth_token_getters = auth_headers
150+
auth_token_getters = auth_tokens
151151

152-
if auth_tokens:
152+
if auth_headers:
153153
if auth_token_getters:
154154
warn(
155-
"Both `auth_token_getters` and `auth_tokens` are provided. `auth_tokens` is deprecated, and `auth_token_getters` will be used.",
155+
"Both `auth_token_getters` and `auth_headers` are provided. `auth_headers` is deprecated, and `auth_token_getters` will be used.",
156156
DeprecationWarning,
157157
)
158158
else:
159159
warn(
160-
"Argument `auth_tokens` is deprecated. Use `auth_token_getters` instead.",
160+
"Argument `auth_headers` is deprecated. Use `auth_token_getters` instead.",
161161
DeprecationWarning,
162162
)
163-
auth_token_getters = auth_tokens
163+
auth_token_getters = auth_headers
164164

165165
url = f"{self.__url}/api/toolset/{toolset_name or ''}"
166166
manifest: ManifestSchema = await _load_manifest(url, self.__session)

0 commit comments

Comments
 (0)