langchain-dev-utils 1.2.14__py3-none-any.whl → 1.2.16__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.
- langchain_dev_utils/__init__.py +1 -1
- langchain_dev_utils/agents/factory.py +2 -1
- langchain_dev_utils/agents/middleware/format_prompt.py +1 -1
- langchain_dev_utils/agents/middleware/model_router.py +12 -7
- {langchain_dev_utils-1.2.14.dist-info → langchain_dev_utils-1.2.16.dist-info}/METADATA +26 -26
- {langchain_dev_utils-1.2.14.dist-info → langchain_dev_utils-1.2.16.dist-info}/RECORD +8 -8
- {langchain_dev_utils-1.2.14.dist-info → langchain_dev_utils-1.2.16.dist-info}/WHEEL +0 -0
- {langchain_dev_utils-1.2.14.dist-info → langchain_dev_utils-1.2.16.dist-info}/licenses/LICENSE +0 -0
langchain_dev_utils/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "1.2.
|
|
1
|
+
__version__ = "1.2.16"
|
|
@@ -7,6 +7,7 @@ from langchain.agents.middleware.types import (
|
|
|
7
7
|
ResponseT,
|
|
8
8
|
_InputAgentState,
|
|
9
9
|
_OutputAgentState,
|
|
10
|
+
StateT_co,
|
|
10
11
|
)
|
|
11
12
|
from langchain.agents.structured_output import ResponseFormat
|
|
12
13
|
from langchain_core.messages import SystemMessage
|
|
@@ -25,8 +26,8 @@ def create_agent( # noqa: PLR0915
|
|
|
25
26
|
tools: Sequence[BaseTool | Callable | dict[str, Any]] | None = None,
|
|
26
27
|
*,
|
|
27
28
|
system_prompt: str | SystemMessage | None = None,
|
|
28
|
-
middleware: Sequence[AgentMiddleware[AgentState[ResponseT], ContextT]] = (),
|
|
29
29
|
response_format: ResponseFormat[ResponseT] | type[ResponseT] | None = None,
|
|
30
|
+
middleware: Sequence[AgentMiddleware[StateT_co, ContextT]] = (),
|
|
30
31
|
state_schema: type[AgentState[ResponseT]] | None = None,
|
|
31
32
|
context_schema: type[ContextT] | None = None,
|
|
32
33
|
checkpointer: Checkpointer | None = None,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from typing import Any, Awaitable, Callable, NotRequired, Optional, cast
|
|
1
|
+
from typing import Annotated, Any, Awaitable, Callable, NotRequired, Optional, cast
|
|
2
2
|
|
|
3
3
|
from langchain.agents import AgentState
|
|
4
4
|
from langchain.agents.middleware import AgentMiddleware, ModelRequest, ModelResponse
|
|
5
|
-
from langchain.agents.middleware.types import ModelCallResult
|
|
5
|
+
from langchain.agents.middleware.types import ModelCallResult, OmitFromInput
|
|
6
6
|
from langchain_core.language_models import BaseChatModel
|
|
7
7
|
from langchain_core.messages import AnyMessage, SystemMessage
|
|
8
8
|
from langchain_core.tools import BaseTool
|
|
@@ -19,6 +19,7 @@ class ModelDict(TypedDict):
|
|
|
19
19
|
model_description: str
|
|
20
20
|
tools: NotRequired[list[BaseTool | dict[str, Any]]]
|
|
21
21
|
model_kwargs: NotRequired[dict[str, Any]]
|
|
22
|
+
model_instance: NotRequired[BaseChatModel]
|
|
22
23
|
model_system_prompt: NotRequired[str]
|
|
23
24
|
|
|
24
25
|
|
|
@@ -64,7 +65,7 @@ Strictly adhere to tool call requirements!
|
|
|
64
65
|
|
|
65
66
|
|
|
66
67
|
class ModelRouterState(AgentState):
|
|
67
|
-
router_model_selection: str
|
|
68
|
+
router_model_selection: Annotated[str, OmitFromInput]
|
|
68
69
|
|
|
69
70
|
|
|
70
71
|
class ModelRouterMiddleware(AgentMiddleware):
|
|
@@ -76,7 +77,7 @@ class ModelRouterMiddleware(AgentMiddleware):
|
|
|
76
77
|
model name or a BaseChatModel instance
|
|
77
78
|
model_list: List of available routing models, each containing model_name,
|
|
78
79
|
model_description, tools(Optional), model_kwargs(Optional),
|
|
79
|
-
model_system_prompt(Optional)
|
|
80
|
+
model_instance(Optional), model_system_prompt(Optional)
|
|
80
81
|
router_prompt: Routing prompt template, uses default template if None
|
|
81
82
|
|
|
82
83
|
Examples:
|
|
@@ -155,6 +156,7 @@ class ModelRouterMiddleware(AgentMiddleware):
|
|
|
155
156
|
"tools": item.get("tools", None),
|
|
156
157
|
"kwargs": item.get("model_kwargs", None),
|
|
157
158
|
"system_prompt": item.get("model_system_prompt", None),
|
|
159
|
+
"model_instance": item.get("model_instance", None),
|
|
158
160
|
}
|
|
159
161
|
for item in self.model_list
|
|
160
162
|
}
|
|
@@ -163,10 +165,13 @@ class ModelRouterMiddleware(AgentMiddleware):
|
|
|
163
165
|
override_kwargs = {}
|
|
164
166
|
if select_model_name != "default-model" and select_model_name in model_dict:
|
|
165
167
|
model_values = model_dict.get(select_model_name, {})
|
|
166
|
-
if model_values["
|
|
167
|
-
model =
|
|
168
|
+
if model_values["model_instance"] is not None:
|
|
169
|
+
model = model_values["model_instance"]
|
|
168
170
|
else:
|
|
169
|
-
|
|
171
|
+
if model_values["kwargs"] is not None:
|
|
172
|
+
model = load_chat_model(select_model_name, **model_values["kwargs"])
|
|
173
|
+
else:
|
|
174
|
+
model = load_chat_model(select_model_name)
|
|
170
175
|
override_kwargs["model"] = model
|
|
171
176
|
if model_values["tools"] is not None:
|
|
172
177
|
override_kwargs["tools"] = model_values["tools"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: langchain-dev-utils
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.16
|
|
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
|
|
@@ -54,38 +54,38 @@ Tired of writing repetitive code in LangChain development? `langchain-dev-utils`
|
|
|
54
54
|
|
|
55
55
|
## ⚡ Quick Start
|
|
56
56
|
|
|
57
|
-
1. Install `langchain-dev-utils
|
|
57
|
+
**1. Install `langchain-dev-utils`**
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
```bash
|
|
60
|
+
pip install -U "langchain-dev-utils[standard]"
|
|
61
|
+
```
|
|
62
62
|
|
|
63
|
-
2. Start using
|
|
63
|
+
**2. Start using**
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
70
|
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
# Register model provider
|
|
72
|
+
register_model_provider("vllm", "openai-compatible", base_url="http://localhost:8000/v1")
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
# Dynamically load model using string
|
|
80
|
+
model = load_chat_model("vllm:qwen3-4b")
|
|
81
|
+
response = model.invoke("Hello")
|
|
82
|
+
print(response)
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
89
|
|
|
90
90
|
**For more features of this library, please visit the [full documentation](https://tbice123123.github.io/langchain-dev-utils/)**
|
|
91
91
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
langchain_dev_utils/__init__.py,sha256=
|
|
1
|
+
langchain_dev_utils/__init__.py,sha256=7RIJ-Nh9kHJf5O5NvahUeP8DNXq6oIzbYcIt_yKv0lQ,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
|
|
5
|
-
langchain_dev_utils/agents/factory.py,sha256=
|
|
5
|
+
langchain_dev_utils/agents/factory.py,sha256=mr-Q3fxxV_yEN3l8p-Rk0uxXvKjDUGEZDtrg9HRwr-8,3732
|
|
6
6
|
langchain_dev_utils/agents/file_system.py,sha256=Yk3eetREE26WNrnTWLoiDUpOyCJ-rhjlfFDk6foLa1E,8468
|
|
7
7
|
langchain_dev_utils/agents/plan.py,sha256=WwhoiJBmVYVI9bT8HfjCzTJ_SIp9WFil0gOeznv2omQ,6497
|
|
8
8
|
langchain_dev_utils/agents/wrap.py,sha256=RuchoH_VotPmKFuYEn2SXoSgNxZhSA9jKM0Iv_8oHLk,4718
|
|
9
9
|
langchain_dev_utils/agents/middleware/__init__.py,sha256=EECbcYcHXQAMA-guJNRGwCVi9jG957d0nOaoIuyIKC0,832
|
|
10
|
-
langchain_dev_utils/agents/middleware/format_prompt.py,sha256=
|
|
10
|
+
langchain_dev_utils/agents/middleware/format_prompt.py,sha256=LzYiQXCRvkpfDhGPxhZwdepeU3j-HUWPJqcx3FWsfT4,2357
|
|
11
11
|
langchain_dev_utils/agents/middleware/model_fallback.py,sha256=nivtXXF4cwyOBv6p7RW12nXtNg87wjTWxO3BKIYiroI,1674
|
|
12
|
-
langchain_dev_utils/agents/middleware/model_router.py,sha256=
|
|
12
|
+
langchain_dev_utils/agents/middleware/model_router.py,sha256=qBspvj9ZoKfmC1pHWTO0EHHfxjgCUd-TuSbqvZl0kmg,7977
|
|
13
13
|
langchain_dev_utils/agents/middleware/plan.py,sha256=0qDCmenxgY_zrwMfOyYlgLfhYNw-HszNLeeOkfj14NA,16002
|
|
14
14
|
langchain_dev_utils/agents/middleware/summarization.py,sha256=IoZ2PM1OC3AXwf0DWpfreuPOAipeiYu0KPmAABWXuY0,3087
|
|
15
15
|
langchain_dev_utils/agents/middleware/tool_call_repair.py,sha256=oZF0Oejemqs9kSn8xbW79FWyVVarL4IGCz0gpqYBkFM,3529
|
|
@@ -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.
|
|
36
|
-
langchain_dev_utils-1.2.
|
|
37
|
-
langchain_dev_utils-1.2.
|
|
38
|
-
langchain_dev_utils-1.2.
|
|
35
|
+
langchain_dev_utils-1.2.16.dist-info/METADATA,sha256=2lobuT6h5sJqxw25CaeDtdEQrk2EvROnPLhuF-ny4mI,4516
|
|
36
|
+
langchain_dev_utils-1.2.16.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
37
|
+
langchain_dev_utils-1.2.16.dist-info/licenses/LICENSE,sha256=AWAOzNEcsvCEzHOF0qby5OKxviVH_eT9Yce1sgJTico,1084
|
|
38
|
+
langchain_dev_utils-1.2.16.dist-info/RECORD,,
|
|
File without changes
|
{langchain_dev_utils-1.2.14.dist-info → langchain_dev_utils-1.2.16.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|