langchain-dev-utils 1.2.8__tar.gz → 1.2.10__tar.gz

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.
Files changed (57) hide show
  1. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/PKG-INFO +38 -20
  2. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/README.md +37 -19
  3. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/README_cn.md +22 -7
  4. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/pyproject.toml +1 -1
  5. langchain_dev_utils-1.2.10/src/langchain_dev_utils/__init__.py +1 -0
  6. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/chat_models/adapters/openai_compatible.py +584 -577
  7. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/chat_models/types.py +2 -2
  8. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/embeddings/base.py +26 -26
  9. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/message_convert/content.py +18 -8
  10. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/tool_calling/utils.py +7 -7
  11. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/tests/test_load_model.py +1 -1
  12. langchain_dev_utils-1.2.8/src/langchain_dev_utils/__init__.py +0 -1
  13. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/.gitignore +0 -0
  14. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/.python-version +0 -0
  15. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/.vscode/settings.json +0 -0
  16. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/LICENSE +0 -0
  17. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/_utils.py +0 -0
  18. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/agents/__init__.py +0 -0
  19. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/agents/factory.py +0 -0
  20. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/agents/file_system.py +0 -0
  21. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/agents/middleware/__init__.py +0 -0
  22. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/agents/middleware/model_fallback.py +0 -0
  23. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/agents/middleware/model_router.py +0 -0
  24. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/agents/middleware/plan.py +0 -0
  25. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/agents/middleware/summarization.py +0 -0
  26. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/agents/middleware/tool_call_repair.py +0 -0
  27. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/agents/middleware/tool_emulator.py +0 -0
  28. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/agents/middleware/tool_selection.py +0 -0
  29. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/agents/plan.py +0 -0
  30. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/agents/wrap.py +0 -0
  31. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/chat_models/__init__.py +0 -0
  32. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/chat_models/adapters/__init__.py +0 -0
  33. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/chat_models/base.py +0 -0
  34. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/embeddings/__init__.py +0 -0
  35. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/message_convert/__init__.py +0 -0
  36. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/message_convert/format.py +0 -0
  37. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/pipeline/__init__.py +0 -0
  38. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/pipeline/parallel.py +0 -0
  39. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/pipeline/sequential.py +0 -0
  40. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/pipeline/types.py +0 -0
  41. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/py.typed +0 -0
  42. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/tool_calling/__init__.py +0 -0
  43. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/src/langchain_dev_utils/tool_calling/human_in_the_loop.py +0 -0
  44. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/tests/__init__.py +0 -0
  45. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/tests/test_agent.py +0 -0
  46. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/tests/test_chat_models.py +0 -0
  47. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/tests/test_human_in_the_loop.py +0 -0
  48. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/tests/test_load_embbeding.py +0 -0
  49. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/tests/test_messages.py +0 -0
  50. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/tests/test_model_tool_emulator.py +0 -0
  51. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/tests/test_pipline.py +0 -0
  52. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/tests/test_plan_middleware.py +0 -0
  53. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/tests/test_router_model.py +0 -0
  54. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/tests/test_tool_call_repair.py +0 -0
  55. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/tests/test_tool_calling.py +0 -0
  56. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/tests/test_wrap_agent.py +0 -0
  57. {langchain_dev_utils-1.2.8 → langchain_dev_utils-1.2.10}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langchain-dev-utils
3
- Version: 1.2.8
3
+ Version: 1.2.10
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
@@ -192,52 +192,70 @@ def get_current_time() -> str:
192
192
 
193
193
  ### 4. **Agent Development**
194
194
 
195
- Includes the following features:
195
+ Includes the following capabilities:
196
196
 
197
- - Predefined agent factory functions
198
- - Common middleware components
197
+ - Multi-agent construction
198
+ - Commonly used middleware components
199
199
 
200
- #### 4.1 Agent Factory Functions
200
+ #### 4.1 Multi-Agent Construction
201
201
 
202
- In LangChain v1, the official `create_agent` function can be used to create a single agent; its `model` parameter accepts either a BaseChatModel instance or a specific string (when a string is provided, only models supported by `init_chat_model` are allowed). To extend the flexibility of specifying models via string, this library provides an equivalent `create_agent` function that lets you designate any model supported by `load_chat_model` (registration required beforehand).
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.
203
203
 
204
- Usage example:
204
+ **Usage Example**:
205
205
 
206
206
  ```python
207
- from langchain_dev_utils.agents import create_agent
207
+ import datetime
208
+ from langchain_dev_utils.agents import create_agent, wrap_agent_as_tool
208
209
  from langchain.agents import AgentState
209
210
 
210
- agent = create_agent("vllm:qwen3-4b", tools=[get_current_time], name="time-agent")
211
- response = agent.invoke({"messages": [{"role": "user", "content": "What time is it?"}]})
211
+ @tool
212
+ def get_current_time() -> str:
213
+ """Get the current time"""
214
+ return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
215
+
216
+ time_agent = create_agent("vllm:qwen3-4b", tools=[get_current_time], name="time-agent")
217
+ call_time_agent_tool = wrap_agent_as_tool(time_agent)
218
+
219
+ agent = create_agent(
220
+ "vllm:qwen3-4b",
221
+ name="agent",
222
+ tools=[call_time_agent_tool],
223
+ )
224
+ response = agent.invoke(
225
+ {"messages": [{"role": "user", "content": "What time is it now?"}]}
226
+ )
212
227
  print(response)
213
228
  ```
214
229
 
215
230
  #### 4.2 Middleware
216
231
 
217
- Provides some commonly used middleware components. Below, we illustrate with `ToolCallRepairMiddleware` and `PlanMiddleware`.
218
-
219
- `ToolCallRepairMiddleware` is used to repair `invalid_tool_calls` generated by large language models.
232
+ Provides several commonly used middleware components. Below are examples using `ToolCallRepairMiddleware` and `PlanMiddleware`.
220
233
 
221
- `PlanMiddleware` is used for agent planning.
234
+ - `ToolCallRepairMiddleware` automatically repairs malformed tool calls found in the model's `invalid_tool_calls` output.
235
+ - `PlanMiddleware` enables task planning capabilities for agents.
222
236
 
223
237
  ```python
224
238
  from langchain_dev_utils.agents.middleware import (
225
- ToolcallRepairMiddleware,
239
+ ToolCallRepairMiddleware,
226
240
  PlanMiddleware,
227
241
  )
228
242
 
229
243
  agent = create_agent(
230
244
  "vllm:qwen3-4b",
231
245
  name="plan-agent",
232
- middleware=[ToolCallRepairMiddleware(), PlanMiddleware(
233
- use_read_plan_tool=False
234
- )]
246
+ middleware=[
247
+ ToolCallRepairMiddleware(),
248
+ PlanMiddleware(use_read_plan_tool=False)
249
+ ]
235
250
  )
236
- response = agent.invoke({"messages": [{"role": "user", "content": "Give me a travel plan to New York"}]})
251
+ response = agent.invoke({"messages": [{"role": "user", "content": "Give me a travel plan for visiting New York."}]})
237
252
  print(response)
238
253
  ```
239
254
 
240
- **For more information about agent development and all built-in middleware, please refer to**: [Pre-built Agent Functions](https://tbice123123.github.io/langchain-dev-utils-docs/en/agent-development/prebuilt.html), [Middleware](https://tbice123123.github.io/langchain-dev-utils-docs/en/agent-development/middleware.html)
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
+
241
259
 
242
260
  ### 5. **State Graph Orchestration**
243
261
 
@@ -175,52 +175,70 @@ def get_current_time() -> str:
175
175
 
176
176
  ### 4. **Agent Development**
177
177
 
178
- Includes the following features:
178
+ Includes the following capabilities:
179
179
 
180
- - Predefined agent factory functions
181
- - Common middleware components
180
+ - Multi-agent construction
181
+ - Commonly used middleware components
182
182
 
183
- #### 4.1 Agent Factory Functions
183
+ #### 4.1 Multi-Agent Construction
184
184
 
185
- In LangChain v1, the official `create_agent` function can be used to create a single agent; its `model` parameter accepts either a BaseChatModel instance or a specific string (when a string is provided, only models supported by `init_chat_model` are allowed). To extend the flexibility of specifying models via string, this library provides an equivalent `create_agent` function that lets you designate any model supported by `load_chat_model` (registration required beforehand).
185
+ 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.
186
186
 
187
- Usage example:
187
+ **Usage Example**:
188
188
 
189
189
  ```python
190
- from langchain_dev_utils.agents import create_agent
190
+ import datetime
191
+ from langchain_dev_utils.agents import create_agent, wrap_agent_as_tool
191
192
  from langchain.agents import AgentState
192
193
 
193
- agent = create_agent("vllm:qwen3-4b", tools=[get_current_time], name="time-agent")
194
- response = agent.invoke({"messages": [{"role": "user", "content": "What time is it?"}]})
194
+ @tool
195
+ def get_current_time() -> str:
196
+ """Get the current time"""
197
+ return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
198
+
199
+ time_agent = create_agent("vllm:qwen3-4b", tools=[get_current_time], name="time-agent")
200
+ call_time_agent_tool = wrap_agent_as_tool(time_agent)
201
+
202
+ agent = create_agent(
203
+ "vllm:qwen3-4b",
204
+ name="agent",
205
+ tools=[call_time_agent_tool],
206
+ )
207
+ response = agent.invoke(
208
+ {"messages": [{"role": "user", "content": "What time is it now?"}]}
209
+ )
195
210
  print(response)
196
211
  ```
197
212
 
198
213
  #### 4.2 Middleware
199
214
 
200
- Provides some commonly used middleware components. Below, we illustrate with `ToolCallRepairMiddleware` and `PlanMiddleware`.
201
-
202
- `ToolCallRepairMiddleware` is used to repair `invalid_tool_calls` generated by large language models.
215
+ Provides several commonly used middleware components. Below are examples using `ToolCallRepairMiddleware` and `PlanMiddleware`.
203
216
 
204
- `PlanMiddleware` is used for agent planning.
217
+ - `ToolCallRepairMiddleware` automatically repairs malformed tool calls found in the model's `invalid_tool_calls` output.
218
+ - `PlanMiddleware` enables task planning capabilities for agents.
205
219
 
206
220
  ```python
207
221
  from langchain_dev_utils.agents.middleware import (
208
- ToolcallRepairMiddleware,
222
+ ToolCallRepairMiddleware,
209
223
  PlanMiddleware,
210
224
  )
211
225
 
212
226
  agent = create_agent(
213
227
  "vllm:qwen3-4b",
214
228
  name="plan-agent",
215
- middleware=[ToolCallRepairMiddleware(), PlanMiddleware(
216
- use_read_plan_tool=False
217
- )]
229
+ middleware=[
230
+ ToolCallRepairMiddleware(),
231
+ PlanMiddleware(use_read_plan_tool=False)
232
+ ]
218
233
  )
219
- response = agent.invoke({"messages": [{"role": "user", "content": "Give me a travel plan to New York"}]})
234
+ response = agent.invoke({"messages": [{"role": "user", "content": "Give me a travel plan for visiting New York."}]})
220
235
  print(response)
221
236
  ```
222
237
 
223
- **For more information about agent development and all built-in middleware, please refer to**: [Pre-built Agent Functions](https://tbice123123.github.io/langchain-dev-utils-docs/en/agent-development/prebuilt.html), [Middleware](https://tbice123123.github.io/langchain-dev-utils-docs/en/agent-development/middleware.html)
238
+ **For more details on agent development and a complete list of built-in middleware, please refer to**:
239
+ [Multi-Agent Construction](https://tbice123123.github.io/langchain-dev-utils-docs/en/agent-development/multi-agent.html),
240
+ [Middleware](https://tbice123123.github.io/langchain-dev-utils-docs/en/agent-development/middleware.html)
241
+
224
242
 
225
243
  ### 5. **State Graph Orchestration**
226
244
 
@@ -176,21 +176,36 @@ def get_current_time() -> str:
176
176
 
177
177
  包含以下功能:
178
178
 
179
- - 预设的智能体工厂函数
179
+ - 多智能体构建
180
180
  - 常用的中间件组件
181
181
 
182
- #### 4.1 智能体工厂函数
182
+ #### 4.1 多智能体构建
183
183
 
184
- LangChain v1 版本中,官方提供的 `create_agent` 函数可以用于创建单智能体,其中 model 参数支持传入 BaseChatModel 实例或特定字符串(当传入字符串时,仅限于 `init_chat_model` 支持的模型)。为扩展字符串指定模型的灵活性,本库提供了功能相同的 `create_agent` 函数,使您能够通过字符串指定 `load_chat_model` 支持的模型(需要提前注册)。
184
+ 将智能体封装为工具是多智能体系统中的一种常见实现模式,LangChain 官方文档对此有详细阐述。为此,本库提供了预构建函数`wrap_agent_as_tool` 来实现此模式,该函数能够将一个智能体实例封装成一个可供其它智能体调用的工具。
185
185
 
186
186
  使用示例:
187
187
 
188
188
  ```python
189
- from langchain_dev_utils.agents import create_agent
189
+ import datetime
190
+ from langchain_dev_utils.agents import create_agent, wrap_agent_as_tool
190
191
  from langchain.agents import AgentState
191
192
 
192
- agent = create_agent("vllm:qwen3-4b", tools=[get_current_time], name="time-agent")
193
- response = agent.invoke({"messages": [{"role": "user", "content": "现在几点了?"}]})
193
+ @tool
194
+ def get_current_time() -> str:
195
+ """获取当前时间"""
196
+ return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
197
+
198
+ time_agent = create_agent("vllm:qwen3-4b", tools=[get_current_time], name="time-agent")
199
+ call_time_agent_tool = wrap_agent_as_tool(time_agent)
200
+
201
+ agent = create_agent(
202
+ "vllm:qwen3-4b",
203
+ name="agent",
204
+ tools=[call_time_agent_tool],
205
+ )
206
+ response = agent.invoke(
207
+ {"messages": [{"role": "user", "content": "现在几点了?"}]}
208
+ )
194
209
  print(response)
195
210
  ```
196
211
 
@@ -219,7 +234,7 @@ response = agent.invoke({"messages": [{"role": "user", "content": "给我一个
219
234
  print(response)
220
235
  ```
221
236
 
222
- **对于更多关于智能体开发以及所有的内置中间件的相关介绍,请参考**: [预构建智能体函数](https://tbice123123.github.io/langchain-dev-utils-docs/zh/agent-development/prebuilt.html),[中间件](https://tbice123123.github.io/langchain-dev-utils-docs/zh/agent-development/middleware.html)
237
+ **对于更多关于智能体开发以及所有的内置中间件的相关介绍,请参考**: [多智能体构建](https://tbice123123.github.io/langchain-dev-utils-docs/zh/agent-development/multi-agent.html),[中间件](https://tbice123123.github.io/langchain-dev-utils-docs/zh/agent-development/middleware.html)
223
238
 
224
239
  ### 5. **状态图编排**
225
240
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "langchain-dev-utils"
3
- version = "1.2.8"
3
+ version = "1.2.10"
4
4
  description = "A practical utility library for LangChain and LangGraph development"
5
5
  readme = "README.md"
6
6
  authors = [{ name = "tiebingice", email = "tiebingice123@outlook.com" }]
@@ -0,0 +1 @@
1
+ __version__ = "1.2.10"