langchain-dev-utils 1.2.13__tar.gz → 1.2.15__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 (61) hide show
  1. langchain_dev_utils-1.2.15/PKG-INFO +102 -0
  2. langchain_dev_utils-1.2.15/README.md +85 -0
  3. langchain_dev_utils-1.2.15/README_cn.md +86 -0
  4. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/pyproject.toml +1 -1
  5. langchain_dev_utils-1.2.15/src/langchain_dev_utils/__init__.py +1 -0
  6. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/agents/middleware/model_router.py +9 -4
  7. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/uv.lock +221 -189
  8. langchain_dev_utils-1.2.13/PKG-INFO +0 -345
  9. langchain_dev_utils-1.2.13/README.md +0 -328
  10. langchain_dev_utils-1.2.13/README_cn.md +0 -328
  11. langchain_dev_utils-1.2.13/src/langchain_dev_utils/__init__.py +0 -1
  12. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/.gitignore +0 -0
  13. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/.python-version +0 -0
  14. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/.vscode/settings.json +0 -0
  15. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/LICENSE +0 -0
  16. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/_utils.py +0 -0
  17. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/agents/__init__.py +0 -0
  18. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/agents/factory.py +0 -0
  19. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/agents/file_system.py +0 -0
  20. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/agents/middleware/__init__.py +0 -0
  21. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/agents/middleware/format_prompt.py +0 -0
  22. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/agents/middleware/model_fallback.py +0 -0
  23. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/agents/middleware/plan.py +0 -0
  24. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/agents/middleware/summarization.py +0 -0
  25. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/agents/middleware/tool_call_repair.py +0 -0
  26. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/agents/middleware/tool_emulator.py +0 -0
  27. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/agents/middleware/tool_selection.py +0 -0
  28. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/agents/plan.py +0 -0
  29. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/agents/wrap.py +0 -0
  30. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/chat_models/__init__.py +0 -0
  31. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/chat_models/adapters/__init__.py +0 -0
  32. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/chat_models/adapters/openai_compatible.py +0 -0
  33. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/chat_models/base.py +0 -0
  34. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/chat_models/types.py +0 -0
  35. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/embeddings/__init__.py +0 -0
  36. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/embeddings/base.py +0 -0
  37. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/message_convert/__init__.py +0 -0
  38. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/message_convert/content.py +0 -0
  39. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/message_convert/format.py +0 -0
  40. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/pipeline/__init__.py +0 -0
  41. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/pipeline/parallel.py +0 -0
  42. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/pipeline/sequential.py +0 -0
  43. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/pipeline/types.py +0 -0
  44. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/py.typed +0 -0
  45. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/tool_calling/__init__.py +0 -0
  46. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/tool_calling/human_in_the_loop.py +0 -0
  47. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/src/langchain_dev_utils/tool_calling/utils.py +0 -0
  48. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/tests/__init__.py +0 -0
  49. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/tests/test_agent.py +0 -0
  50. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/tests/test_chat_models.py +0 -0
  51. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/tests/test_human_in_the_loop.py +0 -0
  52. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/tests/test_load_embbeding.py +0 -0
  53. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/tests/test_load_model.py +0 -0
  54. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/tests/test_messages.py +0 -0
  55. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/tests/test_model_tool_emulator.py +0 -0
  56. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/tests/test_pipline.py +0 -0
  57. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/tests/test_plan_middleware.py +0 -0
  58. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/tests/test_router_model.py +0 -0
  59. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/tests/test_tool_call_repair.py +0 -0
  60. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/tests/test_tool_calling.py +0 -0
  61. {langchain_dev_utils-1.2.13 → langchain_dev_utils-1.2.15}/tests/test_wrap_agent.py +0 -0
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: langchain-dev-utils
3
+ Version: 1.2.15
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-dev-utils[standard]"
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", base_url="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>
@@ -0,0 +1,85 @@
1
+ # 🦜️🧰 langchain-dev-utils
2
+
3
+ <p align="center">
4
+ <em>🚀 High-efficiency toolkit designed for LangChain and LangGraph developers</em>
5
+ </p>
6
+
7
+ <p align="center">
8
+ 📚 <a href="https://tbice123123.github.io/langchain-dev-utils/">English</a> •
9
+ <a href="https://tbice123123.github.io/langchain-dev-utils/zh/">中文</a>
10
+ </p>
11
+
12
+ [![PyPI](https://img.shields.io/pypi/v/langchain-dev-utils.svg?color=%2334D058&label=pypi%20package)](https://pypi.org/project/langchain-dev-utils/)
13
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
14
+ [![Python](https://img.shields.io/badge/python-3.11|3.12|3.13|3.14-%2334D058)](https://www.python.org/downloads)
15
+ [![Downloads](https://static.pepy.tech/badge/langchain-dev-utils/month)](https://pepy.tech/project/langchain-dev-utils)
16
+ [![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://tbice123123.github.io/langchain-dev-utils)
17
+
18
+ > This is the English version. For the Chinese version, please visit [中文版本](https://github.com/TBice123123/langchain-dev-utils/blob/master/README_cn.md)
19
+
20
+ ## ✨ Why choose langchain-dev-utils?
21
+
22
+ 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:
23
+
24
+ - ⚡ **Boost development efficiency** - Reduce boilerplate code, allowing you to focus on core functionality
25
+ - 🧩 **Simplify complex workflows** - Easily manage multi-model, multi-tool, and multi-agent applications
26
+ - 🔧 **Enhance code quality** - Improve consistency and readability, reducing maintenance costs
27
+ - 🎯 **Accelerate prototype development** - Quickly implement ideas, iterate and validate faster
28
+
29
+
30
+ ## 🎯 Core Features
31
+
32
+ - **🔌 Unified model management** - Specify model providers through strings, easily switch and combine different models
33
+ - **💬 Flexible message handling** - Support for chain-of-thought concatenation, streaming processing, and message formatting
34
+ - **🛠️ Powerful tool calling** - Built-in tool call detection, parameter parsing, and human review functionality
35
+ - **🤖 Efficient Agent development** - Simplify agent creation process, expand more common middleware
36
+ - **📊 Flexible state graph composition** - Support for serial and parallel composition of multiple StateGraphs
37
+
38
+ ## ⚡ Quick Start
39
+
40
+ **1. Install `langchain-dev-utils`**
41
+
42
+ ```bash
43
+ pip install -U "langchain-dev-utils[standard]"
44
+ ```
45
+
46
+ **2. Start using**
47
+
48
+ ```python
49
+ from langchain.tools import tool
50
+ from langchain_core.messages import HumanMessage
51
+ from langchain_dev_utils.chat_models import register_model_provider, load_chat_model
52
+ from langchain_dev_utils.agents import create_agent
53
+
54
+ # Register model provider
55
+ register_model_provider("vllm", "openai-compatible", base_url="http://localhost:8000/v1")
56
+
57
+ @tool
58
+ def get_current_weather(location: str) -> str:
59
+ """Get the current weather for the specified location"""
60
+ return f"25 degrees, {location}"
61
+
62
+ # Dynamically load model using string
63
+ model = load_chat_model("vllm:qwen3-4b")
64
+ response = model.invoke("Hello")
65
+ print(response)
66
+
67
+ # Create agent
68
+ agent = create_agent("vllm:qwen3-4b", tools=[get_current_weather])
69
+ response = agent.invoke({"messages": [HumanMessage(content="What's the weather like in New York today?")]})
70
+ print(response)
71
+ ```
72
+
73
+ **For more features of this library, please visit the [full documentation](https://tbice123123.github.io/langchain-dev-utils/)**
74
+
75
+
76
+ ## 🛠️ GitHub Repository
77
+
78
+ Visit the [GitHub repository](https://github.com/TBice123123/langchain-dev-utils) to view the source code and report issues.
79
+
80
+ ---
81
+
82
+ <div align="center">
83
+ <p>Developed with ❤️ and ☕</p>
84
+ <p>If this project helps you, please give us a ⭐️</p>
85
+ </div>
@@ -0,0 +1,86 @@
1
+ # 🦜️🧰 langchain-dev-utils
2
+
3
+ <p align="center">
4
+ <em>🚀 专为 LangChain 和 LangGraph 开发者打造的高效工具库</em>
5
+ </p>
6
+
7
+ <p align="center">
8
+ 📚 <a href="https://tbice123123.github.io/langchain-dev-utils/">English</a> •
9
+ <a href="https://tbice123123.github.io/langchain-dev-utils/zh/">中文</a>
10
+ </p>
11
+
12
+ [![PyPI](https://img.shields.io/pypi/v/langchain-dev-utils.svg?color=%2334D058&label=pypi%20package)](https://pypi.org/project/langchain-dev-utils/)
13
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
14
+ [![Python](https://img.shields.io/badge/python-3.11|3.12|3.13|3.14-%2334D058)](https://www.python.org/downloads)
15
+ [![Downloads](https://static.pepy.tech/badge/langchain-dev-utils/month)](https://pepy.tech/project/langchain-dev-utils)
16
+ [![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://tbice123123.github.io/langchain-dev-utils/zh/)
17
+
18
+ > 当前为中文版,英文版请访问[English Version](https://github.com/TBice123123/langchain-dev-utils/blob/master/README.md)
19
+
20
+ ## ✨ 为什么选择 langchain-dev-utils?
21
+
22
+ 厌倦了在 LangChain 开发中编写重复代码?`langchain-dev-utils` 正是您需要的解决方案!这个轻量但功能强大的工具库专为提升 LangChain 和 LangGraph 开发体验而设计,帮助您:
23
+
24
+ - ⚡ **提升开发效率** - 减少样板代码,让您专注于核心功能
25
+ - 🧩 **简化复杂流程** - 轻松管理多模型、多工具和多智能体应用
26
+ - 🔧 **增强代码质量** - 提高一致性和可读性,减少维护成本
27
+ - 🎯 **加速原型开发** - 快速实现想法,更快迭代验证
28
+
29
+
30
+ ## 🎯 核心功能
31
+
32
+ - **🔌 统一的模型管理** - 通过字符串指定模型提供商,轻松切换和组合不同模型
33
+ - **💬 灵活的消息处理** - 支持思维链拼接、流式处理和消息格式化
34
+ - **🛠️ 强大的工具调用** - 内置工具调用检测、参数解析和人工审核功能
35
+ - **🤖 高效的 Agent 开发** - 简化智能体创建流程,扩充更多的常用中间件
36
+ - **📊 灵活的状态图组合** - 支持串行和并行方式组合多个 StateGraph
37
+
38
+ ## ⚡ 快速开始
39
+
40
+ **1. 安装 `langchain-dev-utils`**
41
+
42
+ ```bash
43
+ pip install -U "langchain-dev-utils[standard]"
44
+ ```
45
+
46
+ **2. 开始使用**
47
+
48
+ ```python
49
+ from langchain.tools import tool
50
+ from langchain_core.messages import HumanMessage
51
+ from langchain_dev_utils.chat_models import register_model_provider, load_chat_model
52
+ from langchain_dev_utils.agents import create_agent
53
+
54
+ # 注册模型提供商
55
+ register_model_provider("vllm", "openai-compatible", base_url="http://localhost:8000/v1")
56
+
57
+ @tool
58
+ def get_current_weather(location: str) -> str:
59
+ """获取指定地点的当前天气"""
60
+ return f"25度,{location}"
61
+
62
+ # 使用字符串动态加载模型
63
+ model = load_chat_model("vllm:qwen3-4b")
64
+ response = model.invoke("你好")
65
+ print(response)
66
+
67
+ # 创建智能体
68
+ agent = create_agent("vllm:qwen3-4b", tools=[get_current_weather])
69
+ response = agent.invoke({"messages": [HumanMessage(content="今天纽约的天气如何?")]})
70
+ print(response)
71
+ ```
72
+
73
+ **获取更多的本库功能,请访问[完整文档](https://tbice123123.github.io/langchain-dev-utils/zh/)**
74
+
75
+
76
+ ## 🛠️ GitHub 仓库
77
+
78
+ 访问 [GitHub 仓库](https://github.com/TBice123123/langchain-dev-utils) 查看源代码和问题。
79
+
80
+
81
+ ---
82
+
83
+ <div align="center">
84
+ <p>由 ❤️ 和 ☕ 驱动开发</p>
85
+ <p>如果这个项目对您有帮助,请给我们一个 ⭐️</p>
86
+ </div>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "langchain-dev-utils"
3
- version = "1.2.13"
3
+ version = "1.2.15"
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.15"
@@ -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
 
@@ -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["kwargs"] is not None:
167
- model = load_chat_model(select_model_name, **model_values["kwargs"])
168
+ if model_values["model_instance"] is not None:
169
+ model = model_values["model_instance"]
168
170
  else:
169
- model = load_chat_model(select_model_name)
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"]