langchain-dev-utils 1.2.10__py3-none-any.whl → 1.2.11__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.
@@ -1 +1 @@
1
- __version__ = "1.2.10"
1
+ __version__ = "1.2.11"
@@ -1,4 +1,4 @@
1
- from typing import Any, NotRequired, Optional, TypedDict, cast
1
+ from typing import Any, Optional, cast
2
2
 
3
3
  from langchain.chat_models.base import _SUPPORTED_PROVIDERS, _init_chat_model_helper
4
4
  from langchain_core.language_models.chat_models import BaseChatModel
@@ -9,17 +9,10 @@ from langchain_dev_utils._utils import (
9
9
  _get_base_url_field_name,
10
10
  )
11
11
 
12
- from .types import ChatModelType, CompatibilityOptions
13
-
14
- _MODEL_PROVIDERS_DICT = {}
12
+ from .types import ChatModelProvider, ChatModelType, CompatibilityOptions
15
13
 
16
14
 
17
- class ChatModelProvider(TypedDict):
18
- provider_name: str
19
- chat_model: ChatModelType
20
- base_url: NotRequired[str]
21
- model_profiles: NotRequired[dict[str, dict[str, Any]]]
22
- compatibility_options: NotRequired[CompatibilityOptions]
15
+ _MODEL_PROVIDERS_DICT = {}
23
16
 
24
17
 
25
18
  def _parse_model(model: str, model_provider: Optional[str]) -> tuple[str, str]:
@@ -1,4 +1,4 @@
1
- from typing import Literal, NotRequired, TypedDict, Union
1
+ from typing import Any, Literal, NotRequired, TypedDict, Union
2
2
 
3
3
  from langchain_core.language_models.chat_models import BaseChatModel
4
4
 
@@ -17,3 +17,11 @@ class CompatibilityOptions(TypedDict):
17
17
  supported_response_format: NotRequired[ResponseFormatType]
18
18
  reasoning_keep_policy: NotRequired[ReasoningKeepPolicy]
19
19
  include_usage: NotRequired[bool]
20
+
21
+
22
+ class ChatModelProvider(TypedDict):
23
+ provider_name: str
24
+ chat_model: ChatModelType
25
+ base_url: NotRequired[str]
26
+ model_profiles: NotRequired[dict[str, dict[str, Any]]]
27
+ compatibility_options: NotRequired[CompatibilityOptions]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langchain-dev-utils
3
- Version: 1.2.10
3
+ Version: 1.2.11
4
4
  Summary: A practical utility library for LangChain and LangGraph development
5
5
  Project-URL: Source Code, https://github.com/TBice123123/langchain-dev-utils
6
6
  Project-URL: repository, https://github.com/TBice123123/langchain-dev-utils
@@ -22,26 +22,26 @@ Description-Content-Type: text/markdown
22
22
  </p>
23
23
 
24
24
  <p align="center">
25
- 📚 <a href="https://tbice123123.github.io/langchain-dev-utils-docs/en/">English</a> •
26
- <a href="https://tbice123123.github.io/langchain-dev-utils-docs/zh/">中文</a>
25
+ 📚 <a href="https://tbice123123.github.io/langchain-dev-utils/">English</a> •
26
+ <a href="https://tbice123123.github.io/langchain-dev-utils/zh/">中文</a>
27
27
  </p>
28
28
 
29
29
  [![PyPI](https://img.shields.io/pypi/v/langchain-dev-utils.svg?color=%2334D058&label=pypi%20package)](https://pypi.org/project/langchain-dev-utils/)
30
30
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
31
31
  [![Python](https://img.shields.io/badge/python-3.11|3.12|3.13|3.14-%2334D058)](https://www.python.org/downloads)
32
32
  [![Downloads](https://static.pepy.tech/badge/langchain-dev-utils/month)](https://pepy.tech/project/langchain-dev-utils)
33
- [![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://tbice123123.github.io/langchain-dev-utils-docs/en/)
33
+ [![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://tbice123123.github.io/langchain-dev-utils/)
34
34
 
35
- > This is the English version. For the Chinese version, please visit [Chinese Documentation](https://github.com/TBice123123/langchain-dev-utils/blob/master/README_cn.md)
35
+ > This is the English version. For the Chinese version, please visit [中文文档](https://github.com/TBice123123/langchain-dev-utils/blob/master/README_cn.md)
36
36
 
37
- **langchain-dev-utils** is a utility library focused on enhancing the development experience with LangChain and LangGraph. It provides a series of out-of-the-box utility functions that can both reduce repetitive code writing and improve code consistency and readability. By simplifying development workflows, this library helps you prototype faster, iterate more smoothly, and create clearer, more reliable LLM-based AI applications.
37
+ **langchain-dev-utils** is a utility library focused on enhancing the development experience of LangChain and LangGraph. It provides a series of ready-to-use utility functions that can reduce repetitive code writing and improve code consistency and readability. By simplifying the development workflow, this library can help you build prototypes faster, iterate more smoothly, and create clearer and more reliable AI applications based on large language models.
38
38
 
39
39
  ## 🚀 Installation
40
40
 
41
41
  ```bash
42
42
  pip install -U langchain-dev-utils
43
43
 
44
- # Install the full-featured version:
44
+ # Install full-featured version:
45
45
  pip install -U langchain-dev-utils[standard]
46
46
  ```
47
47
 
@@ -49,16 +49,16 @@ pip install -U langchain-dev-utils[standard]
49
49
 
50
50
  ### 1. **Model Management**
51
51
 
52
- In `langchain`, the `init_chat_model`/`init_embeddings` functions can be used to initialize chat model instances/embedding model instances, but the model providers they support are relatively limited. This module provides a registration function (`register_model_provider`/`register_embeddings_provider`) to register any model provider for subsequent model loading using `load_chat_model` / `load_embeddings`.
52
+ In `langchain`, the `init_chat_model`/`init_embeddings` functions can be used to initialize chat model instances/embedding model instances, but they support a limited number of model providers. This module provides registration functions (`register_model_provider`/`register_embeddings_provider`) to easily register any model provider for later use with `load_chat_model` / `load_embeddings` for model loading.
53
53
 
54
54
  #### 1.1 Chat Model Management
55
55
 
56
- Mainly consists of the following two functions:
56
+ There are two main functions:
57
57
 
58
58
  - `register_model_provider`: Register a chat model provider
59
59
  - `load_chat_model`: Load a chat model
60
60
 
61
- Example for integrating a qwen3-4b model deployed using `vllm`:
61
+ Assuming you want to use the qwen3-4b model deployed with `vllm`, the reference code is as follows:
62
62
 
63
63
  ```python
64
64
  from langchain_dev_utils.chat_models import (
@@ -80,12 +80,12 @@ print(model.invoke("Hello"))
80
80
 
81
81
  #### 1.2 Embedding Model Management
82
82
 
83
- Mainly consists of the following two functions:
83
+ There are two main functions:
84
84
 
85
85
  - `register_embeddings_provider`: Register an embedding model provider
86
86
  - `load_embeddings`: Load an embedding model
87
87
 
88
- Example for integrating a qwen3-embedding-4b model deployed using `vllm`:
88
+ Assuming you want to use the qwen3-embedding-4b model deployed with `vllm`, the reference code is as follows:
89
89
 
90
90
  ```python
91
91
  from langchain_dev_utils.embeddings import register_embeddings_provider, load_embeddings
@@ -103,23 +103,21 @@ emb = embeddings.embed_query("Hello")
103
103
  print(emb)
104
104
  ```
105
105
 
106
- **For more information about model management, please refer to**: [Chat Model Management](https://tbice123123.github.io/langchain-dev-utils-docs/en/model-management/chat.html), [Embedding Model Management](https://tbice123123.github.io/langchain-dev-utils-docs/en/model-management/embedding.html)
107
106
 
108
107
  ### 2. **Message Conversion**
109
108
 
110
109
  Includes the following features:
111
110
 
112
- - Merge reasoning content into the final response
111
+ - Merge chain-of-thought content into final responses
113
112
  - Stream content merging
114
113
  - Content formatting tools
115
114
 
116
115
  #### 2.1 Stream Content Merging
117
116
 
118
- For stream responses obtained using `stream()` and `astream()`, you can use `merge_ai_message_chunk` to merge them into a final AIMessage.
117
+ For streaming responses obtained using `stream()` and `astream()`, you can use `merge_ai_message_chunk` to merge them into a final AIMessage.
119
118
 
120
119
  ```python
121
120
  from langchain_dev_utils.message_convert import merge_ai_message_chunk
122
-
123
121
  chunks = list(model.stream("Hello"))
124
122
  merged = merge_ai_message_chunk(chunks)
125
123
  ```
@@ -137,7 +135,6 @@ text = format_sequence([
137
135
  ], separator="\n", with_num=True)
138
136
  ```
139
137
 
140
- **For more information about message conversion, please refer to**: [Message Process](https://tbice123123.github.io/langchain-dev-utils-docs/en/message-conversion/message.html), [Formatting List Content](https://tbice123123.github.io/langchain-dev-utils-docs/en/message-conversion/format.html)
141
138
 
142
139
  ### 3. **Tool Calling**
143
140
 
@@ -157,10 +154,10 @@ from langchain_dev_utils.tool_calling import has_tool_calling, parse_tool_callin
157
154
 
158
155
  @tool
159
156
  def get_current_time() -> str:
160
- """Get the current timestamp"""
157
+ """Get current timestamp"""
161
158
  return str(datetime.datetime.now().timestamp())
162
159
 
163
- response = model.bind_tools([get_current_time]).invoke("What time is it?")
160
+ response = model.bind_tools([get_current_time]).invoke("What time is it now?")
164
161
 
165
162
  if has_tool_calling(response):
166
163
  name, args = parse_tool_calling(
@@ -184,24 +181,23 @@ import datetime
184
181
  @human_in_the_loop
185
182
  @tool
186
183
  def get_current_time() -> str:
187
- """Get the current timestamp"""
184
+ """Get current timestamp"""
188
185
  return str(datetime.datetime.now().timestamp())
189
186
  ```
190
187
 
191
- **For more information about tool calling, please refer to**: [Add Human-in-the-Loop Support](https://tbice123123.github.io/langchain-dev-utils-docs/en/tool-calling/human-in-the-loop.html), [Tool Call Handling](https://tbice123123.github.io/langchain-dev-utils-docs/en/tool-calling/tool.html)
192
188
 
193
189
  ### 4. **Agent Development**
194
190
 
195
- Includes the following capabilities:
191
+ Includes the following features:
196
192
 
197
- - Multi-agent construction
198
- - Commonly used middleware components
193
+ - Multi-agent construction
194
+ - Common middleware components
199
195
 
200
196
  #### 4.1 Multi-Agent Construction
201
197
 
202
- Wrapping an agent as a tool is a common implementation pattern in multi-agent systems, as elaborated in the official LangChain documentation. To support this pattern, this library provides a pre-built utility function `wrap_agent_as_tool`, which encapsulates an agent instance into a tool that can be invoked by other agents.
198
+ Wrapping agents as tools is a common implementation pattern in multi-agent systems, which is detailed in the official LangChain documentation. To this end, this library provides a pre-built function `wrap_agent_as_tool` to implement this pattern, which can wrap an agent instance into a tool that can be called by other agents.
203
199
 
204
- **Usage Example**:
200
+ Usage example:
205
201
 
206
202
  ```python
207
203
  import datetime
@@ -210,7 +206,7 @@ from langchain.agents import AgentState
210
206
 
211
207
  @tool
212
208
  def get_current_time() -> str:
213
- """Get the current time"""
209
+ """Get current time"""
214
210
  return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
215
211
 
216
212
  time_agent = create_agent("vllm:qwen3-4b", tools=[get_current_time], name="time-agent")
@@ -229,10 +225,11 @@ print(response)
229
225
 
230
226
  #### 4.2 Middleware
231
227
 
232
- Provides several commonly used middleware components. Below are examples using `ToolCallRepairMiddleware` and `PlanMiddleware`.
228
+ Provides some common middleware components. Below are examples using `ToolCallRepairMiddleware` and `PlanMiddleware`.
233
229
 
234
- - `ToolCallRepairMiddleware` automatically repairs malformed tool calls found in the model's `invalid_tool_calls` output.
235
- - `PlanMiddleware` enables task planning capabilities for agents.
230
+ `ToolCallRepairMiddleware` is used to fix `invaild_tool_calls` content from large models.
231
+
232
+ `PlanMiddleware` is used for agent planning.
236
233
 
237
234
  ```python
238
235
  from langchain_dev_utils.agents.middleware import (
@@ -240,33 +237,28 @@ from langchain_dev_utils.agents.middleware import (
240
237
  PlanMiddleware,
241
238
  )
242
239
 
243
- agent = create_agent(
240
+ agent=create_agent(
244
241
  "vllm:qwen3-4b",
245
242
  name="plan-agent",
246
- middleware=[
247
- ToolCallRepairMiddleware(),
248
- PlanMiddleware(use_read_plan_tool=False)
249
- ]
243
+ middleware=[ToolCallRepairMiddleware(), PlanMiddleware(
244
+ use_read_plan_tool=False
245
+ )]
250
246
  )
251
- response = agent.invoke({"messages": [{"role": "user", "content": "Give me a travel plan for visiting New York."}]})
247
+ response = agent.invoke({"messages": [{"role": "user", "content": "Give me a travel plan to New York"}]}))
252
248
  print(response)
253
249
  ```
254
250
 
255
- **For more details on agent development and a complete list of built-in middleware, please refer to**:
256
- [Multi-Agent Construction](https://tbice123123.github.io/langchain-dev-utils-docs/en/agent-development/multi-agent.html),
257
- [Middleware](https://tbice123123.github.io/langchain-dev-utils-docs/en/agent-development/middleware.html)
258
-
259
251
 
260
252
  ### 5. **State Graph Orchestration**
261
253
 
262
- Includes the following capabilities:
254
+ Includes the following features:
263
255
 
264
256
  - Sequential graph orchestration
265
257
  - Parallel graph orchestration
266
258
 
267
259
  #### 5.1 Sequential Graph Orchestration
268
260
 
269
- Use `create_sequential_pipeline` to orchestrate multiple subgraphs in sequential order:
261
+ Using `create_sequential_pipeline`, you can orchestrate multiple subgraphs in sequence:
270
262
 
271
263
  ```python
272
264
  from langchain.agents import AgentState
@@ -281,25 +273,25 @@ register_model_provider(
281
273
  base_url="http://localhost:8000/v1",
282
274
  )
283
275
 
284
- # Build a sequential pipeline (all subgraphs executed in order)
276
+ # Build sequential pipeline (all subgraphs execute in sequence)
285
277
  graph = create_sequential_pipeline(
286
278
  sub_graphs=[
287
279
  create_agent(
288
280
  model="vllm:qwen3-4b",
289
281
  tools=[get_current_time],
290
- system_prompt="You are a time-query assistant. You can only answer questions about the current time. If the question is unrelated to time, respond with 'I cannot answer that.'",
282
+ system_prompt="You are a time query assistant, you can only answer the current time. If this question is not related to time, please directly answer that you cannot answer",
291
283
  name="time_agent",
292
284
  ),
293
285
  create_agent(
294
286
  model="vllm:qwen3-4b",
295
287
  tools=[get_current_weather],
296
- system_prompt="You are a weather-query assistant. You can only answer questions about the current weather. If the question is unrelated to weather, respond with 'I cannot answer that.'",
288
+ system_prompt="You are a weather query assistant, you can only answer the current weather. If this question is not related to weather, please directly answer that you cannot answer",
297
289
  name="weather_agent",
298
290
  ),
299
291
  create_agent(
300
292
  model="vllm:qwen3-4b",
301
293
  tools=[get_current_user],
302
- system_prompt="You are a user-query assistant. You can only answer questions about the current user. If the question is unrelated to the user, respond with 'I cannot answer that.'",
294
+ system_prompt="You are a user query assistant, you can only answer the current user. If this question is not related to users, please directly answer that you cannot answer",
303
295
  name="user_agent",
304
296
  ),
305
297
  ],
@@ -312,44 +304,42 @@ print(response)
312
304
 
313
305
  #### 5.2 Parallel Graph Orchestration
314
306
 
315
- Use `create_parallel_pipeline` to orchestrate multiple subgraphs in parallel:
307
+ Using `create_parallel_pipeline`, you can orchestrate multiple subgraphs in parallel:
316
308
 
317
309
  ```python
318
310
  from langchain_dev_utils.pipeline import create_parallel_pipeline
319
311
 
320
- # Build a parallel pipeline (all subgraphs executed concurrently)
312
+ # Build parallel pipeline (all subgraphs execute in parallel)
321
313
  graph = create_parallel_pipeline(
322
314
  sub_graphs=[
323
315
  create_agent(
324
316
  model="vllm:qwen3-4b",
325
317
  tools=[get_current_time],
326
- system_prompt="You are a time-query assistant. You can only answer questions about the current time. If the question is unrelated to time, respond with 'I cannot answer that.'",
318
+ system_prompt="You are a time query assistant, you can only answer the current time. If this question is not related to time, please directly answer that you cannot answer",
327
319
  name="time_agent",
328
320
  ),
329
321
  create_agent(
330
322
  model="vllm:qwen3-4b",
331
323
  tools=[get_current_weather],
332
- system_prompt="You are a weather-query assistant. You can only answer questions about the current weather. If the question is unrelated to weather, respond with 'I cannot answer that.'",
324
+ system_prompt="You are a weather query assistant, you can only answer the current weather. If this question is not related to weather, please directly answer that you cannot answer",
333
325
  name="weather_agent",
334
326
  ),
335
327
  create_agent(
336
328
  model="vllm:qwen3-4b",
337
329
  tools=[get_current_user],
338
- system_prompt="You are a user-query assistant. You can only answer questions about the current user. If the question is unrelated to the user, respond with 'I cannot answer that.'",
330
+ system_prompt="You are a user query assistant, you can only answer the current user. If this question is not related to users, please directly answer that you cannot answer",
339
331
  name="user_agent",
340
332
  ),
341
333
  ],
342
334
  state_schema=AgentState,
343
335
  )
344
-
345
336
  response = graph.invoke({"messages": [HumanMessage("Hello")]})
346
337
  print(response)
347
338
  ```
348
339
 
349
- **For more information about state graph orchestration, please refer to**: [State Graph Orchestration](https://tbice123123.github.io/langchain-dev-utils-docs/en/graph-orchestration/pipeline.html)
350
340
 
351
341
  ## 💬 Join the Community
352
342
 
353
343
  - [GitHub Repository](https://github.com/TBice123123/langchain-dev-utils) — Browse source code, submit Pull Requests
354
344
  - [Issue Tracker](https://github.com/TBice123123/langchain-dev-utils/issues) — Report bugs or suggest improvements
355
- - We welcome contributions in all forms — whether code, documentation, or usage examples. Let's build a more powerful and practical LangChain development ecosystem together!
345
+ - We welcome all forms of contributions — whether code, documentation, or usage examples. Let's build a more powerful and practical LangChain development ecosystem together
@@ -1,4 +1,4 @@
1
- langchain_dev_utils/__init__.py,sha256=GI4rgymQsPWdk2_d96NgmZBRuFM6yOZB-kysnrjBjVo,23
1
+ langchain_dev_utils/__init__.py,sha256=aBWZsCYiXXcSUsUJr3tOTQWsH7ZDqJzyMYdQbOd5Qtc,23
2
2
  langchain_dev_utils/_utils.py,sha256=MFEzR1BjXMj6HEVwt2x2omttFuDJ_rYAEbNqe99r9pM,1338
3
3
  langchain_dev_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  langchain_dev_utils/agents/__init__.py,sha256=PJ-lSDZv_AXMYA3H4fx-HzJa14tPbkGmq1HX8LNfaPo,125
@@ -15,8 +15,8 @@ langchain_dev_utils/agents/middleware/tool_call_repair.py,sha256=oZF0Oejemqs9kSn
15
15
  langchain_dev_utils/agents/middleware/tool_emulator.py,sha256=OgtPhqturaWzF4fRSJ3f_IXvIrYrrAjlpOC5zmLtrkY,2031
16
16
  langchain_dev_utils/agents/middleware/tool_selection.py,sha256=dRH5ejR6N02Djwxt6Gd63MYkg6SV5pySlzaRt53OoZk,3113
17
17
  langchain_dev_utils/chat_models/__init__.py,sha256=YSLUyHrWEEj4y4DtGFCOnDW02VIYZdfAH800m4Klgeg,224
18
- langchain_dev_utils/chat_models/base.py,sha256=CVMfgqMRnIKv8z4babusa2c4RKVuiWTL39mPD8cHAf4,11880
19
- langchain_dev_utils/chat_models/types.py,sha256=kVLbT-IbvNtWPVmyVmh58le5r8XCqrEwuFB9-TWCBJk,672
18
+ langchain_dev_utils/chat_models/base.py,sha256=t-tjNMX4BSyNxvBCLX-BKfJzJcnzhUzJY4NTHhVhnPA,11627
19
+ langchain_dev_utils/chat_models/types.py,sha256=MD3cv_ZIe9fCdgwisNfuxAOhy-j4YSs1ZOQYyCjlNKs,927
20
20
  langchain_dev_utils/chat_models/adapters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  langchain_dev_utils/chat_models/adapters/openai_compatible.py,sha256=v9ewQFn75Fl6urtVo4fZgg2RRrzRXGluKf-egYAI5A0,22658
22
22
  langchain_dev_utils/embeddings/__init__.py,sha256=zbEOaV86TUi9Zrg_dH9dpdgacWg31HMJTlTQknA9EKk,244
@@ -31,7 +31,7 @@ langchain_dev_utils/pipeline/types.py,sha256=T3aROKKXeWvd0jcH5XkgMDQfEkLfPaiOhhV
31
31
  langchain_dev_utils/tool_calling/__init__.py,sha256=mu_WxKMcu6RoTf4vkTPbA1WSBSNc6YIqyBtOQ6iVQj4,322
32
32
  langchain_dev_utils/tool_calling/human_in_the_loop.py,sha256=7Z_QO5OZUR6K8nLoIcafc6osnvX2IYNorOJcbx6bVso,9672
33
33
  langchain_dev_utils/tool_calling/utils.py,sha256=S4-KXQ8jWmpGTXYZitovF8rxKpaSSUkFruM8LDwvcvE,2765
34
- langchain_dev_utils-1.2.10.dist-info/METADATA,sha256=2KpH7VEYB7v6uyWHJSvq0hyfNSLxlSsIZNueFbCIv44,13372
35
- langchain_dev_utils-1.2.10.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
36
- langchain_dev_utils-1.2.10.dist-info/licenses/LICENSE,sha256=AWAOzNEcsvCEzHOF0qby5OKxviVH_eT9Yce1sgJTico,1084
37
- langchain_dev_utils-1.2.10.dist-info/RECORD,,
34
+ langchain_dev_utils-1.2.11.dist-info/METADATA,sha256=4IGI_v0rIC8_SW13_j3h2JyPS_-rKPvdK6m6lTW2ymE,11853
35
+ langchain_dev_utils-1.2.11.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
36
+ langchain_dev_utils-1.2.11.dist-info/licenses/LICENSE,sha256=AWAOzNEcsvCEzHOF0qby5OKxviVH_eT9Yce1sgJTico,1084
37
+ langchain_dev_utils-1.2.11.dist-info/RECORD,,