langchain-dev-utils 1.2.12__py3-none-any.whl → 1.2.14__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.12"
1
+ __version__ = "1.2.14"
@@ -20,7 +20,13 @@ from langchain_core.callbacks import (
20
20
  CallbackManagerForLLMRun,
21
21
  )
22
22
  from langchain_core.language_models import LangSmithParams, LanguageModelInput
23
- from langchain_core.messages import AIMessage, AIMessageChunk, BaseMessage, HumanMessage
23
+ from langchain_core.messages import (
24
+ AIMessage,
25
+ AIMessageChunk,
26
+ BaseMessage,
27
+ HumanMessage,
28
+ ToolMessage,
29
+ )
24
30
  from langchain_core.outputs import ChatGenerationChunk, ChatResult
25
31
  from langchain_core.runnables import Runnable
26
32
  from langchain_core.tools import BaseTool
@@ -63,6 +69,58 @@ def _get_last_human_message_index(messages: list[BaseMessage]) -> int:
63
69
  )
64
70
 
65
71
 
72
+ def _transform_video_block(block: dict[str, Any]) -> dict:
73
+ """Transform video block to video_url block."""
74
+ if "url" in block:
75
+ return {
76
+ "type": "video_url",
77
+ "video_url": {
78
+ "url": block["url"],
79
+ },
80
+ }
81
+ if "base64" in block or block.get("source_type") == "base64":
82
+ if "mime_type" not in block:
83
+ error_message = "mime_type key is required for base64 data."
84
+ raise ValueError(error_message)
85
+ mime_type = block["mime_type"]
86
+ base64_data = block["data"] if "data" in block else block["base64"]
87
+ return {
88
+ "type": "video_url",
89
+ "video_url": {
90
+ "url": f"data:{mime_type};base64,{base64_data}",
91
+ },
92
+ }
93
+ error_message = "Unsupported source type. Only 'url' and 'base64' are supported."
94
+ raise ValueError(error_message)
95
+
96
+
97
+ def _process_video_input(message: BaseMessage):
98
+ """
99
+ Process BaseMessage with video input.
100
+
101
+ Args:
102
+ message (BaseMessage): The HumanMessage instance to process.
103
+
104
+ Returns:
105
+ None: The method modifies the message in-place.
106
+ """
107
+ if not message.content:
108
+ return message
109
+ content = message.content
110
+
111
+ if not isinstance(content, list):
112
+ return message
113
+
114
+ formatted_content = []
115
+ for block in content:
116
+ if isinstance(block, dict) and block.get("type") == "video":
117
+ formatted_content.append(_transform_video_block(block))
118
+ else:
119
+ formatted_content.append(block)
120
+ message = message.model_copy(update={"content": formatted_content})
121
+ return message
122
+
123
+
66
124
  class _BaseChatOpenAICompatible(BaseChatOpenAI):
67
125
  """
68
126
  Base template class for OpenAI-compatible chat model implementations.
@@ -183,6 +241,10 @@ class _BaseChatOpenAICompatible(BaseChatOpenAI):
183
241
  )
184
242
  payload_messages.append(msg_dict)
185
243
  else:
244
+ if (
245
+ isinstance(m, HumanMessage) or isinstance(m, ToolMessage)
246
+ ) and isinstance(m.content, list):
247
+ m = _process_video_input(m)
186
248
  payload_messages.append(_convert_message_to_dict(m))
187
249
 
188
250
  payload["messages"] = payload_messages
@@ -11,7 +11,6 @@ from langchain_dev_utils._utils import (
11
11
 
12
12
  from .types import ChatModelProvider, ChatModelType, CompatibilityOptions
13
13
 
14
-
15
14
  _MODEL_PROVIDERS_DICT = {}
16
15
 
17
16
 
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: langchain-dev-utils
3
+ Version: 1.2.14
4
+ Summary: A practical utility library for LangChain and LangGraph development
5
+ Project-URL: Source Code, https://github.com/TBice123123/langchain-dev-utils
6
+ Project-URL: repository, https://github.com/TBice123123/langchain-dev-utils
7
+ Project-URL: documentation, https://tbice123123.github.io/langchain-dev-utils
8
+ Author-email: tiebingice <tiebingice123@outlook.com>
9
+ License-File: LICENSE
10
+ Requires-Python: >=3.11
11
+ Requires-Dist: langchain>=1.1.0
12
+ Requires-Dist: langgraph>=1.0.0
13
+ Provides-Extra: standard
14
+ Requires-Dist: json-repair>=0.53.1; extra == 'standard'
15
+ Requires-Dist: langchain-openai; extra == 'standard'
16
+ Description-Content-Type: text/markdown
17
+
18
+ # 🦜️🧰 langchain-dev-utils
19
+
20
+ <p align="center">
21
+ <em>🚀 High-efficiency toolkit designed for LangChain and LangGraph developers</em>
22
+ </p>
23
+
24
+ <p align="center">
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
+ </p>
28
+
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
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
31
+ [![Python](https://img.shields.io/badge/python-3.11|3.12|3.13|3.14-%2334D058)](https://www.python.org/downloads)
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)
34
+
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
+
37
+ ## ✨ Why choose langchain-dev-utils?
38
+
39
+ Tired of writing repetitive code in LangChain development? `langchain-dev-utils` is the solution you need! This lightweight yet powerful toolkit is designed to enhance the development experience of LangChain and LangGraph, helping you:
40
+
41
+ - ⚡ **Boost development efficiency** - Reduce boilerplate code, allowing you to focus on core functionality
42
+ - 🧩 **Simplify complex workflows** - Easily manage multi-model, multi-tool, and multi-agent applications
43
+ - 🔧 **Enhance code quality** - Improve consistency and readability, reducing maintenance costs
44
+ - 🎯 **Accelerate prototype development** - Quickly implement ideas, iterate and validate faster
45
+
46
+
47
+ ## 🎯 Core Features
48
+
49
+ - **🔌 Unified model management** - Specify model providers through strings, easily switch and combine different models
50
+ - **💬 Flexible message handling** - Support for chain-of-thought concatenation, streaming processing, and message formatting
51
+ - **🛠️ Powerful tool calling** - Built-in tool call detection, parameter parsing, and human review functionality
52
+ - **🤖 Efficient Agent development** - Simplify agent creation process, expand more common middleware
53
+ - **📊 Flexible state graph composition** - Support for serial and parallel composition of multiple StateGraphs
54
+
55
+ ## ⚡ Quick Start
56
+
57
+ 1. Install `langchain-dev-utils`:
58
+
59
+ ```bash
60
+ pip install -U langchain[openai] langchain-dev-utils
61
+ ```
62
+
63
+ 2. Start using:
64
+
65
+ ```python
66
+ from langchain.tools import tool
67
+ from langchain_core.messages import HumanMessage
68
+ from langchain_dev_utils.chat_models import register_model_provider, load_chat_model
69
+ from langchain_dev_utils.agents import create_agent
70
+
71
+ # Register model provider
72
+ register_model_provider("vllm", "openai-compatible", "http://localhost:8000/v1")
73
+
74
+ @tool
75
+ def get_current_weather(location: str) -> str:
76
+ """Get the current weather for the specified location"""
77
+ return f"25 degrees, {location}"
78
+
79
+ # Dynamically load model using string
80
+ model = load_chat_model("vllm:qwen3-4b")
81
+ response = model.invoke("Hello")
82
+ print(response)
83
+
84
+ # Create agent
85
+ agent = create_agent("vllm:qwen3-4b", tools=[get_current_weather])
86
+ response = agent.invoke({"messages": [HumanMessage(content="What's the weather like in New York today?")]})
87
+ print(response)
88
+ ```
89
+
90
+ **For more features of this library, please visit the [full documentation](https://tbice123123.github.io/langchain-dev-utils/)**
91
+
92
+
93
+ ## 🛠️ GitHub Repository
94
+
95
+ Visit the [GitHub repository](https://github.com/TBice123123/langchain-dev-utils) to view the source code and report issues.
96
+
97
+ ---
98
+
99
+ <div align="center">
100
+ <p>Developed with ❤️ and ☕</p>
101
+ <p>If this project helps you, please give us a ⭐️</p>
102
+ </div>
@@ -1,4 +1,4 @@
1
- langchain_dev_utils/__init__.py,sha256=dbW85A2PinQCZabwD2DNDTfOE9315GDtQQKAsJP8IXk,23
1
+ langchain_dev_utils/__init__.py,sha256=mxzjGyB-ihJR05pHYcBiUe_XT5X9wj6cBHLxOXBhAeM,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
@@ -16,10 +16,10 @@ langchain_dev_utils/agents/middleware/tool_call_repair.py,sha256=oZF0Oejemqs9kSn
16
16
  langchain_dev_utils/agents/middleware/tool_emulator.py,sha256=OgtPhqturaWzF4fRSJ3f_IXvIrYrrAjlpOC5zmLtrkY,2031
17
17
  langchain_dev_utils/agents/middleware/tool_selection.py,sha256=dRH5ejR6N02Djwxt6Gd63MYkg6SV5pySlzaRt53OoZk,3113
18
18
  langchain_dev_utils/chat_models/__init__.py,sha256=YSLUyHrWEEj4y4DtGFCOnDW02VIYZdfAH800m4Klgeg,224
19
- langchain_dev_utils/chat_models/base.py,sha256=t-tjNMX4BSyNxvBCLX-BKfJzJcnzhUzJY4NTHhVhnPA,11627
19
+ langchain_dev_utils/chat_models/base.py,sha256=BzaoCIv145eE8b5wNDsbZDHn4EAxe4vdlptp7qXPWKk,11625
20
20
  langchain_dev_utils/chat_models/types.py,sha256=MD3cv_ZIe9fCdgwisNfuxAOhy-j4YSs1ZOQYyCjlNKs,927
21
21
  langchain_dev_utils/chat_models/adapters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- langchain_dev_utils/chat_models/adapters/openai_compatible.py,sha256=v9ewQFn75Fl6urtVo4fZgg2RRrzRXGluKf-egYAI5A0,22658
22
+ langchain_dev_utils/chat_models/adapters/openai_compatible.py,sha256=4iJgMGAReiJ668O9ZGAZbduxNY2PhEJJonDhQDBge44,24596
23
23
  langchain_dev_utils/embeddings/__init__.py,sha256=zbEOaV86TUi9Zrg_dH9dpdgacWg31HMJTlTQknA9EKk,244
24
24
  langchain_dev_utils/embeddings/base.py,sha256=BGoWY0L7nG9iRV3d4sSagXhECXrwvS1xA-A_OVltn3k,9406
25
25
  langchain_dev_utils/message_convert/__init__.py,sha256=ZGrHGXPKMrZ_p9MqfIVZ4jgbEyb7aC4Q7X-muuThIYU,457
@@ -32,7 +32,7 @@ langchain_dev_utils/pipeline/types.py,sha256=T3aROKKXeWvd0jcH5XkgMDQfEkLfPaiOhhV
32
32
  langchain_dev_utils/tool_calling/__init__.py,sha256=mu_WxKMcu6RoTf4vkTPbA1WSBSNc6YIqyBtOQ6iVQj4,322
33
33
  langchain_dev_utils/tool_calling/human_in_the_loop.py,sha256=7Z_QO5OZUR6K8nLoIcafc6osnvX2IYNorOJcbx6bVso,9672
34
34
  langchain_dev_utils/tool_calling/utils.py,sha256=S4-KXQ8jWmpGTXYZitovF8rxKpaSSUkFruM8LDwvcvE,2765
35
- langchain_dev_utils-1.2.12.dist-info/METADATA,sha256=5MjLniCOhGN8a0L6cNLD69PUMNzf5K0nS4Cfifdl5CI,11853
36
- langchain_dev_utils-1.2.12.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
37
- langchain_dev_utils-1.2.12.dist-info/licenses/LICENSE,sha256=AWAOzNEcsvCEzHOF0qby5OKxviVH_eT9Yce1sgJTico,1084
38
- langchain_dev_utils-1.2.12.dist-info/RECORD,,
35
+ langchain_dev_utils-1.2.14.dist-info/METADATA,sha256=QDvbo10fXRhdu1AP-afZ3aa9Tl39fKW1mMI06hY4GVI,4594
36
+ langchain_dev_utils-1.2.14.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
37
+ langchain_dev_utils-1.2.14.dist-info/licenses/LICENSE,sha256=AWAOzNEcsvCEzHOF0qby5OKxviVH_eT9Yce1sgJTico,1084
38
+ langchain_dev_utils-1.2.14.dist-info/RECORD,,
@@ -1,345 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: langchain-dev-utils
3
- Version: 1.2.12
4
- Summary: A practical utility library for LangChain and LangGraph development
5
- Project-URL: Source Code, https://github.com/TBice123123/langchain-dev-utils
6
- Project-URL: repository, https://github.com/TBice123123/langchain-dev-utils
7
- Project-URL: documentation, https://tbice123123.github.io/langchain-dev-utils-docs/en/
8
- Author-email: tiebingice <tiebingice123@outlook.com>
9
- License-File: LICENSE
10
- Requires-Python: >=3.11
11
- Requires-Dist: langchain>=1.1.0
12
- Requires-Dist: langgraph>=1.0.0
13
- Provides-Extra: standard
14
- Requires-Dist: json-repair>=0.53.1; extra == 'standard'
15
- Requires-Dist: langchain-openai; extra == 'standard'
16
- Description-Content-Type: text/markdown
17
-
18
- # 🦜️🧰 langchain-dev-utils
19
-
20
- <p align="center">
21
- <em>A utility library for LangChain and LangGraph development.</em>
22
- </p>
23
-
24
- <p align="center">
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
- </p>
28
-
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
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
31
- [![Python](https://img.shields.io/badge/python-3.11|3.12|3.13|3.14-%2334D058)](https://www.python.org/downloads)
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/)
34
-
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
-
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
-
39
- ## 🚀 Installation
40
-
41
- ```bash
42
- pip install -U langchain-dev-utils
43
-
44
- # Install full-featured version:
45
- pip install -U langchain-dev-utils[standard]
46
- ```
47
-
48
- ## 📦 Core Features
49
-
50
- ### 1. **Model Management**
51
-
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
-
54
- #### 1.1 Chat Model Management
55
-
56
- There are two main functions:
57
-
58
- - `register_model_provider`: Register a chat model provider
59
- - `load_chat_model`: Load a chat model
60
-
61
- Assuming you want to use the qwen3-4b model deployed with `vllm`, the reference code is as follows:
62
-
63
- ```python
64
- from langchain_dev_utils.chat_models import (
65
- register_model_provider,
66
- load_chat_model,
67
- )
68
-
69
- # Register model provider
70
- register_model_provider(
71
- provider_name="vllm",
72
- chat_model="openai-compatible",
73
- base_url="http://localhost:8000/v1",
74
- )
75
-
76
- # Load model
77
- model = load_chat_model("vllm:qwen3-4b")
78
- print(model.invoke("Hello"))
79
- ```
80
-
81
- #### 1.2 Embedding Model Management
82
-
83
- There are two main functions:
84
-
85
- - `register_embeddings_provider`: Register an embedding model provider
86
- - `load_embeddings`: Load an embedding model
87
-
88
- Assuming you want to use the qwen3-embedding-4b model deployed with `vllm`, the reference code is as follows:
89
-
90
- ```python
91
- from langchain_dev_utils.embeddings import register_embeddings_provider, load_embeddings
92
-
93
- # Register embedding model provider
94
- register_embeddings_provider(
95
- provider_name="vllm",
96
- embeddings_model="openai-compatible",
97
- base_url="http://localhost:8000/v1",
98
- )
99
-
100
- # Load embedding model
101
- embeddings = load_embeddings("vllm:qwen3-embedding-4b")
102
- emb = embeddings.embed_query("Hello")
103
- print(emb)
104
- ```
105
-
106
-
107
- ### 2. **Message Conversion**
108
-
109
- Includes the following features:
110
-
111
- - Merge chain-of-thought content into final responses
112
- - Stream content merging
113
- - Content formatting tools
114
-
115
- #### 2.1 Stream Content Merging
116
-
117
- For streaming responses obtained using `stream()` and `astream()`, you can use `merge_ai_message_chunk` to merge them into a final AIMessage.
118
-
119
- ```python
120
- from langchain_dev_utils.message_convert import merge_ai_message_chunk
121
- chunks = list(model.stream("Hello"))
122
- merged = merge_ai_message_chunk(chunks)
123
- ```
124
-
125
- #### 2.2 Format List Content
126
-
127
- For a list, you can use `format_sequence` to format it.
128
-
129
- ```python
130
- from langchain_dev_utils.message_convert import format_sequence
131
- text = format_sequence([
132
- "str1",
133
- "str2",
134
- "str3"
135
- ], separator="\n", with_num=True)
136
- ```
137
-
138
-
139
- ### 3. **Tool Calling**
140
-
141
- Includes the following features:
142
-
143
- - Check and parse tool calls
144
- - Add human-in-the-loop functionality
145
-
146
- #### 3.1 Check and Parse Tool Calls
147
-
148
- `has_tool_calling` and `parse_tool_calling` are used to check and parse tool calls.
149
-
150
- ```python
151
- import datetime
152
- from langchain_core.tools import tool
153
- from langchain_dev_utils.tool_calling import has_tool_calling, parse_tool_calling
154
-
155
- @tool
156
- def get_current_time() -> str:
157
- """Get current timestamp"""
158
- return str(datetime.datetime.now().timestamp())
159
-
160
- response = model.bind_tools([get_current_time]).invoke("What time is it now?")
161
-
162
- if has_tool_calling(response):
163
- name, args = parse_tool_calling(
164
- response, first_tool_call_only=True
165
- )
166
- print(name, args)
167
- ```
168
-
169
- #### 3.2 Add Human-in-the-Loop Functionality
170
-
171
- - `human_in_the_loop`: For synchronous tool functions
172
- - `human_in_the_loop_async`: For asynchronous tool functions
173
-
174
- Both can accept a `handler` parameter for custom breakpoint return and response handling logic.
175
-
176
- ```python
177
- from langchain_dev_utils.tool_calling import human_in_the_loop
178
- from langchain_core.tools import tool
179
- import datetime
180
-
181
- @human_in_the_loop
182
- @tool
183
- def get_current_time() -> str:
184
- """Get current timestamp"""
185
- return str(datetime.datetime.now().timestamp())
186
- ```
187
-
188
-
189
- ### 4. **Agent Development**
190
-
191
- Includes the following features:
192
-
193
- - Multi-agent construction
194
- - Common middleware components
195
-
196
- #### 4.1 Multi-Agent Construction
197
-
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.
199
-
200
- Usage example:
201
-
202
- ```python
203
- import datetime
204
- from langchain_dev_utils.agents import create_agent, wrap_agent_as_tool
205
- from langchain.agents import AgentState
206
-
207
- @tool
208
- def get_current_time() -> str:
209
- """Get current time"""
210
- return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
211
-
212
- time_agent = create_agent("vllm:qwen3-4b", tools=[get_current_time], name="time-agent")
213
- call_time_agent_tool = wrap_agent_as_tool(time_agent)
214
-
215
- agent = create_agent(
216
- "vllm:qwen3-4b",
217
- name="agent",
218
- tools=[call_time_agent_tool],
219
- )
220
- response = agent.invoke(
221
- {"messages": [{"role": "user", "content": "What time is it now?"}]}
222
- )
223
- print(response)
224
- ```
225
-
226
- #### 4.2 Middleware
227
-
228
- Provides some common middleware components. Below are examples using `ToolCallRepairMiddleware` and `PlanMiddleware`.
229
-
230
- `ToolCallRepairMiddleware` is used to fix `invaild_tool_calls` content from large models.
231
-
232
- `PlanMiddleware` is used for agent planning.
233
-
234
- ```python
235
- from langchain_dev_utils.agents.middleware import (
236
- ToolCallRepairMiddleware,
237
- PlanMiddleware,
238
- )
239
-
240
- agent=create_agent(
241
- "vllm:qwen3-4b",
242
- name="plan-agent",
243
- middleware=[ToolCallRepairMiddleware(), PlanMiddleware(
244
- use_read_plan_tool=False
245
- )]
246
- )
247
- response = agent.invoke({"messages": [{"role": "user", "content": "Give me a travel plan to New York"}]}))
248
- print(response)
249
- ```
250
-
251
-
252
- ### 5. **State Graph Orchestration**
253
-
254
- Includes the following features:
255
-
256
- - Sequential graph orchestration
257
- - Parallel graph orchestration
258
-
259
- #### 5.1 Sequential Graph Orchestration
260
-
261
- Using `create_sequential_pipeline`, you can orchestrate multiple subgraphs in sequence:
262
-
263
- ```python
264
- from langchain.agents import AgentState
265
- from langchain_core.messages import HumanMessage
266
- from langchain_dev_utils.agents import create_agent
267
- from langchain_dev_utils.pipeline import create_sequential_pipeline
268
- from langchain_dev_utils.chat_models import register_model_provider
269
-
270
- register_model_provider(
271
- provider_name="vllm",
272
- chat_model="openai-compatible",
273
- base_url="http://localhost:8000/v1",
274
- )
275
-
276
- # Build sequential pipeline (all subgraphs execute in sequence)
277
- graph = create_sequential_pipeline(
278
- sub_graphs=[
279
- create_agent(
280
- model="vllm:qwen3-4b",
281
- tools=[get_current_time],
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",
283
- name="time_agent",
284
- ),
285
- create_agent(
286
- model="vllm:qwen3-4b",
287
- tools=[get_current_weather],
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",
289
- name="weather_agent",
290
- ),
291
- create_agent(
292
- model="vllm:qwen3-4b",
293
- tools=[get_current_user],
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",
295
- name="user_agent",
296
- ),
297
- ],
298
- state_schema=AgentState,
299
- )
300
-
301
- response = graph.invoke({"messages": [HumanMessage("Hello")]})
302
- print(response)
303
- ```
304
-
305
- #### 5.2 Parallel Graph Orchestration
306
-
307
- Using `create_parallel_pipeline`, you can orchestrate multiple subgraphs in parallel:
308
-
309
- ```python
310
- from langchain_dev_utils.pipeline import create_parallel_pipeline
311
-
312
- # Build parallel pipeline (all subgraphs execute in parallel)
313
- graph = create_parallel_pipeline(
314
- sub_graphs=[
315
- create_agent(
316
- model="vllm:qwen3-4b",
317
- tools=[get_current_time],
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",
319
- name="time_agent",
320
- ),
321
- create_agent(
322
- model="vllm:qwen3-4b",
323
- tools=[get_current_weather],
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",
325
- name="weather_agent",
326
- ),
327
- create_agent(
328
- model="vllm:qwen3-4b",
329
- tools=[get_current_user],
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",
331
- name="user_agent",
332
- ),
333
- ],
334
- state_schema=AgentState,
335
- )
336
- response = graph.invoke({"messages": [HumanMessage("Hello")]})
337
- print(response)
338
- ```
339
-
340
-
341
- ## 💬 Join the Community
342
-
343
- - [GitHub Repository](https://github.com/TBice123123/langchain-dev-utils) — Browse source code, submit Pull Requests
344
- - [Issue Tracker](https://github.com/TBice123123/langchain-dev-utils/issues) — Report bugs or suggest improvements
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