langchain-dev-utils 1.3.7__tar.gz → 1.4.0__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 (73) hide show
  1. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/PKG-INFO +7 -6
  2. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/README.md +6 -5
  3. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/README_cn.md +6 -5
  4. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/pyproject.toml +51 -47
  5. langchain_dev_utils-1.4.0/src/langchain_dev_utils/__init__.py +1 -0
  6. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/_utils.py +19 -1
  7. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/agents/wrap.py +20 -7
  8. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/chat_models/adapters/openai_compatible.py +3 -2
  9. langchain_dev_utils-1.4.0/src/langchain_dev_utils/graph/__init__.py +7 -0
  10. langchain_dev_utils-1.4.0/src/langchain_dev_utils/graph/parallel.py +119 -0
  11. langchain_dev_utils-1.4.0/src/langchain_dev_utils/graph/sequential.py +78 -0
  12. langchain_dev_utils-1.4.0/src/langchain_dev_utils/graph/types.py +3 -0
  13. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/message_convert/format.py +34 -1
  14. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/pipeline/parallel.py +6 -0
  15. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/pipeline/sequential.py +6 -0
  16. langchain_dev_utils-1.4.0/tests/test_graph.py +64 -0
  17. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/tests/test_messages.py +16 -10
  18. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/tests/test_wrap_agent.py +37 -4
  19. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/uv.lock +4047 -2883
  20. langchain_dev_utils-1.3.7/src/langchain_dev_utils/__init__.py +0 -1
  21. langchain_dev_utils-1.3.7/src/langchain_dev_utils/agents/file_system.py +0 -252
  22. langchain_dev_utils-1.3.7/src/langchain_dev_utils/agents/plan.py +0 -188
  23. langchain_dev_utils-1.3.7/tests/test_pipline.py +0 -76
  24. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/.gitignore +0 -0
  25. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/.python-version +0 -0
  26. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/.vscode/settings.json +0 -0
  27. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/LICENSE +0 -0
  28. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/agents/__init__.py +0 -0
  29. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/agents/factory.py +0 -0
  30. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/agents/middleware/__init__.py +0 -0
  31. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/agents/middleware/format_prompt.py +0 -0
  32. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/agents/middleware/handoffs.py +0 -0
  33. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/agents/middleware/model_fallback.py +0 -0
  34. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/agents/middleware/model_router.py +0 -0
  35. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/agents/middleware/plan.py +0 -0
  36. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/agents/middleware/summarization.py +0 -0
  37. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/agents/middleware/tool_call_repair.py +0 -0
  38. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/agents/middleware/tool_emulator.py +0 -0
  39. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/agents/middleware/tool_selection.py +0 -0
  40. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/chat_models/__init__.py +0 -0
  41. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/chat_models/adapters/__init__.py +0 -0
  42. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/chat_models/adapters/create_utils.py +0 -0
  43. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/chat_models/adapters/register_profiles.py +0 -0
  44. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/chat_models/base.py +0 -0
  45. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/chat_models/types.py +0 -0
  46. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/embeddings/__init__.py +0 -0
  47. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/embeddings/adapters/__init__.py +0 -0
  48. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/embeddings/adapters/create_utils.py +0 -0
  49. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/embeddings/adapters/openai_compatible.py +0 -0
  50. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/embeddings/base.py +0 -0
  51. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/message_convert/__init__.py +0 -0
  52. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/message_convert/content.py +0 -0
  53. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/pipeline/__init__.py +0 -0
  54. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/pipeline/types.py +0 -0
  55. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/py.typed +0 -0
  56. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/tool_calling/__init__.py +0 -0
  57. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/tool_calling/human_in_the_loop.py +0 -0
  58. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/src/langchain_dev_utils/tool_calling/utils.py +0 -0
  59. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/tests/__init__.py +0 -0
  60. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/tests/test_agent.py +0 -0
  61. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/tests/test_chat_models.py +0 -0
  62. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/tests/test_embedding.py +0 -0
  63. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/tests/test_handoffs_middleware.py +0 -0
  64. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/tests/test_human_in_the_loop.py +0 -0
  65. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/tests/test_load_embbeding.py +0 -0
  66. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/tests/test_load_model.py +0 -0
  67. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/tests/test_model_tool_emulator.py +0 -0
  68. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/tests/test_plan_middleware.py +0 -0
  69. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/tests/test_router_model.py +0 -0
  70. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/tests/test_tool_call_repair.py +0 -0
  71. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/tests/test_tool_calling.py +0 -0
  72. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/tests/utils/__init__.py +0 -0
  73. {langchain_dev_utils-1.3.7 → langchain_dev_utils-1.4.0}/tests/utils/register.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langchain-dev-utils
3
- Version: 1.3.7
3
+ Version: 1.4.0
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
@@ -27,10 +27,11 @@ Description-Content-Type: text/markdown
27
27
  <a href="https://tbice123123.github.io/langchain-dev-utils/zh/">中文</a>
28
28
  </p>
29
29
 
30
- [![PyPI](https://img.shields.io/pypi/v/langchain-dev-utils.svg?color=%2334D058&label=pypi%20package)](https://pypi.org/project/langchain-dev-utils/)
31
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
32
- [![Python](https://img.shields.io/badge/python-3.11|3.12|3.13|3.14-%2334D058)](https://www.python.org/downloads)
33
- [![Downloads](https://static.pepy.tech/badge/langchain-dev-utils/month)](https://pepy.tech/project/langchain-dev-utils)
30
+ [![GitHub Repo](https://img.shields.io/badge/GitHub-Repo-black.svg?logo=github)](https://github.com/TBice123123/langchain-dev-utils)
31
+ [![PyPI](https://img.shields.io/pypi/v/langchain-dev-utils.svg?color=%2334D058&label=pypi%20package&logo=python)](https://pypi.org/project/langchain-dev-utils/)
32
+ [![Python Version](https://img.shields.io/badge/python-3.11%2B-blue.svg?logo=python&label=Python)](https://python.org)
33
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?label=License)](https://opensource.org/licenses/MIT)
34
+ [![Last Commit](https://img.shields.io/github/last-commit/TBice123123/langchain-dev-utils)](https://github.com/TBice123123/langchain-dev-utils)
34
35
  [![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://tbice123123.github.io/langchain-dev-utils)
35
36
 
36
37
  > This is the English version. For the Chinese version, please visit [中文版本](https://github.com/TBice123123/langchain-dev-utils/blob/master/README_cn.md)
@@ -51,7 +52,7 @@ Tired of writing repetitive code in LangChain development? `langchain-dev-utils`
51
52
  - **💬 Flexible message handling** - Support for chain-of-thought concatenation, streaming processing, and message formatting
52
53
  - **🛠️ Powerful tool calling** - Built-in tool call detection, parameter parsing, and human review functionality
53
54
  - **🤖 Efficient Agent development** - Simplify agent creation process, expand more common middleware
54
- - **📊 Flexible state graph composition** - Support for serial and parallel composition of multiple StateGraphs
55
+ - **📊 Convenient State Graph Construction** - Provides pre-built functions to easily create sequential or parallel state graphs
55
56
 
56
57
  ## ⚡ Quick Start
57
58
 
@@ -9,10 +9,11 @@
9
9
  <a href="https://tbice123123.github.io/langchain-dev-utils/zh/">中文</a>
10
10
  </p>
11
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)
12
+ [![GitHub Repo](https://img.shields.io/badge/GitHub-Repo-black.svg?logo=github)](https://github.com/TBice123123/langchain-dev-utils)
13
+ [![PyPI](https://img.shields.io/pypi/v/langchain-dev-utils.svg?color=%2334D058&label=pypi%20package&logo=python)](https://pypi.org/project/langchain-dev-utils/)
14
+ [![Python Version](https://img.shields.io/badge/python-3.11%2B-blue.svg?logo=python&label=Python)](https://python.org)
15
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?label=License)](https://opensource.org/licenses/MIT)
16
+ [![Last Commit](https://img.shields.io/github/last-commit/TBice123123/langchain-dev-utils)](https://github.com/TBice123123/langchain-dev-utils)
16
17
  [![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://tbice123123.github.io/langchain-dev-utils)
17
18
 
18
19
  > This is the English version. For the Chinese version, please visit [中文版本](https://github.com/TBice123123/langchain-dev-utils/blob/master/README_cn.md)
@@ -33,7 +34,7 @@ Tired of writing repetitive code in LangChain development? `langchain-dev-utils`
33
34
  - **💬 Flexible message handling** - Support for chain-of-thought concatenation, streaming processing, and message formatting
34
35
  - **🛠️ Powerful tool calling** - Built-in tool call detection, parameter parsing, and human review functionality
35
36
  - **🤖 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
+ - **📊 Convenient State Graph Construction** - Provides pre-built functions to easily create sequential or parallel state graphs
37
38
 
38
39
  ## ⚡ Quick Start
39
40
 
@@ -9,10 +9,11 @@
9
9
  <a href="https://tbice123123.github.io/langchain-dev-utils/zh/">中文</a>
10
10
  </p>
11
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)
12
+ [![GitHub Repo](https://img.shields.io/badge/GitHub-Repo-black.svg?logo=github)](https://github.com/TBice123123/langchain-dev-utils)
13
+ [![PyPI](https://img.shields.io/pypi/v/langchain-dev-utils.svg?color=%2334D058&label=pypi%20package&logo=python)](https://pypi.org/project/langchain-dev-utils/)
14
+ [![Python Version](https://img.shields.io/badge/python-3.11%2B-blue.svg?logo=python&label=Python)](https://python.org)
15
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?label=License)](https://opensource.org/licenses/MIT)
16
+ [![Last Commit](https://img.shields.io/github/last-commit/TBice123123/langchain-dev-utils)](https://github.com/TBice123123/langchain-dev-utils)
16
17
  [![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://tbice123123.github.io/langchain-dev-utils/zh/)
17
18
 
18
19
  > 当前为中文版,英文版请访问[English Version](https://github.com/TBice123123/langchain-dev-utils/blob/master/README.md)
@@ -33,7 +34,7 @@
33
34
  - **💬 灵活的消息处理** - 支持思维链拼接、流式处理和消息格式化
34
35
  - **🛠️ 强大的工具调用** - 内置工具调用检测、参数解析和人工审核功能
35
36
  - **🤖 高效的 Agent 开发** - 简化智能体创建流程,扩充更多的常用中间件
36
- - **📊 灵活的状态图组合** - 支持串行和并行方式组合多个 StateGraph
37
+ - **📊 便捷的状态图构建** - 提供预构建函数方便构建顺序或者并行的状态图
37
38
 
38
39
  ## ⚡ 快速开始
39
40
 
@@ -1,47 +1,51 @@
1
- [project]
2
- name = "langchain-dev-utils"
3
- version = "1.3.7"
4
- description = "A practical utility library for LangChain and LangGraph development"
5
- readme = "README.md"
6
- authors = [{ name = "tiebingice", email = "tiebingice123@outlook.com" }]
7
- requires-python = ">=3.11"
8
- dependencies = ["langchain>=1.2.0", "langchain-core>=1.2.5", "langgraph>=1.0.0"]
9
-
10
- [project.urls]
11
- "Source Code" = "https://github.com/TBice123123/langchain-dev-utils"
12
- repository = "https://github.com/TBice123123/langchain-dev-utils"
13
- documentation = "https://tbice123123.github.io/langchain-dev-utils"
14
-
15
-
16
- [project.optional-dependencies]
17
- standard = ["json-repair>=0.53.1", "langchain-openai"]
18
-
19
- [build-system]
20
- requires = ["hatchling"]
21
- build-backend = "hatchling.build"
22
-
23
- [tool.hatch.build]
24
- exclude = ["/data", "/docs", "mkdocs.yml"]
25
-
26
- [tool.pytest.ini_options]
27
- asyncio_mode = "auto"
28
- testpaths = ["tests"]
29
- python_files = ["test_*.py"]
30
- python_functions = ["test_*"]
31
-
32
- [dependency-groups]
33
- dev = ["langchain-model-profiles>=0.0.5", "ruff>=0.14.5"]
34
- docs = ["mkdocs-material>=9.7.0", "mkdocs-static-i18n>=1.3.0"]
35
- tests = [
36
- "python-dotenv>=1.1.1",
37
- "langchain-tests>=1.0.0",
38
- "langchain-deepseek>=1.0.0",
39
- "langchain-qwq>=0.3.0",
40
- "langchain-ollama>=1.0.0",
41
- "langchain-community>=0.4.1",
42
- ]
43
-
44
-
45
- [tool.ruff.lint]
46
- select = ["E", "F", "I", "PGH003", "T201"]
47
- ignore = ["E501"]
1
+ [project]
2
+ name = "langchain-dev-utils"
3
+ version = "1.4.0"
4
+ description = "A practical utility library for LangChain and LangGraph development"
5
+ readme = "README.md"
6
+ authors = [{ name = "tiebingice", email = "tiebingice123@outlook.com" }]
7
+ requires-python = ">=3.11"
8
+ dependencies = ["langchain>=1.2.0", "langchain-core>=1.2.5", "langgraph>=1.0.0"]
9
+
10
+ [project.urls]
11
+ "Source Code" = "https://github.com/TBice123123/langchain-dev-utils"
12
+ repository = "https://github.com/TBice123123/langchain-dev-utils"
13
+ documentation = "https://tbice123123.github.io/langchain-dev-utils"
14
+
15
+
16
+ [project.optional-dependencies]
17
+ standard = ["json-repair>=0.53.1", "langchain-openai"]
18
+
19
+ [build-system]
20
+ requires = ["hatchling"]
21
+ build-backend = "hatchling.build"
22
+
23
+ [tool.hatch.build]
24
+ exclude = ["/data", "/docs", "mkdocs.yml"]
25
+
26
+ [tool.pytest.ini_options]
27
+ asyncio_mode = "auto"
28
+ testpaths = ["tests"]
29
+ python_files = ["test_*.py"]
30
+ python_functions = ["test_*"]
31
+
32
+ [dependency-groups]
33
+ dev = ["langchain-model-profiles>=0.0.5", "ruff>=0.14.5"]
34
+ docs = [
35
+ "jupyter>=1.1.1",
36
+ "mkdocs-material>=9.7.0",
37
+ "mkdocs-static-i18n>=1.3.0",
38
+ ]
39
+ tests = [
40
+ "python-dotenv>=1.1.1",
41
+ "langchain-tests>=1.0.0",
42
+ "langchain-deepseek>=1.0.0",
43
+ "langchain-qwq>=0.3.0",
44
+ "langchain-ollama>=1.0.0",
45
+ "langchain-community>=0.4.1",
46
+ ]
47
+
48
+
49
+ [tool.ruff.lint]
50
+ select = ["E", "F", "I", "PGH003", "T201"]
51
+ ignore = ["E501"]
@@ -0,0 +1 @@
1
+ __version__ = "1.4.0"
@@ -1,9 +1,27 @@
1
1
  from importlib import util
2
- from typing import Literal, Optional
2
+ from typing import Literal, Optional, cast
3
3
 
4
+ from langgraph.graph import StateGraph
5
+ from langgraph.graph.state import StateNode
4
6
  from pydantic import BaseModel
5
7
 
6
8
 
9
+ def _transform_node_to_tuple(
10
+ node: StateNode | tuple[str, StateNode],
11
+ ) -> tuple[str, StateNode]:
12
+ if not isinstance(node, tuple):
13
+ if isinstance(node, StateGraph):
14
+ node = node.compile()
15
+ name = node.name
16
+ return name, node
17
+ name = cast(str, getattr(node, "name", getattr(node, "__name__", None)))
18
+ if name is None:
19
+ raise ValueError("Node name must be provided if action is not a function")
20
+ return name, node
21
+ else:
22
+ return node
23
+
24
+
7
25
  def _check_pkg_install(
8
26
  pkg: Literal["langchain_openai", "json_repair"],
9
27
  ) -> None:
@@ -1,12 +1,13 @@
1
- import asyncio
2
- from typing import Any, Awaitable, Callable, Optional
1
+ import inspect
2
+ from typing import Any, Awaitable, Callable, Optional, cast
3
3
 
4
4
  from langchain.tools import ToolRuntime
5
- from langchain_core.messages import HumanMessage
5
+ from langchain_core.messages import AIMessage, HumanMessage
6
6
  from langchain_core.tools import BaseTool, StructuredTool
7
7
  from langgraph.graph.state import CompiledStateGraph
8
8
 
9
9
  from langchain_dev_utils.message_convert import format_sequence
10
+ from langchain_dev_utils.tool_calling import parse_tool_calling
10
11
 
11
12
 
12
13
  def _process_input(request: str, runtime: ToolRuntime) -> str:
@@ -19,6 +20,18 @@ def _process_output(
19
20
  return response["messages"][-1].content
20
21
 
21
22
 
23
+ def get_subagent_name(runtime: ToolRuntime) -> str:
24
+ messages = runtime.state.get("messages", [])
25
+ last_ai_msg = cast(
26
+ AIMessage,
27
+ next((msg for msg in reversed(messages) if isinstance(msg, AIMessage)), None),
28
+ )
29
+
30
+ _, args = parse_tool_calling(last_ai_msg, first_tool_call_only=True)
31
+ args = cast(dict[str, Any], args)
32
+ return args["agent_name"]
33
+
34
+
22
35
  def wrap_agent_as_tool(
23
36
  agent: CompiledStateGraph,
24
37
  tool_name: Optional[str] = None,
@@ -115,7 +128,7 @@ def wrap_agent_as_tool(
115
128
  request: str,
116
129
  runtime: ToolRuntime,
117
130
  ):
118
- if asyncio.iscoroutinefunction(process_input_async):
131
+ if inspect.iscoroutinefunction(process_input_async):
119
132
  _processed_input = await process_input_async(request, runtime)
120
133
  else:
121
134
  _processed_input = (
@@ -135,7 +148,7 @@ def wrap_agent_as_tool(
135
148
 
136
149
  response = await agent.ainvoke(agent_input)
137
150
 
138
- if asyncio.iscoroutinefunction(process_output_async):
151
+ if inspect.iscoroutinefunction(process_output_async):
139
152
  response = await process_output_async(request, response, runtime)
140
153
  else:
141
154
  response = (
@@ -277,7 +290,7 @@ def wrap_all_agents_as_tool(
277
290
  if agent_name not in agents_map:
278
291
  raise ValueError(f"Agent {agent_name} not found")
279
292
 
280
- if asyncio.iscoroutinefunction(process_input_async):
293
+ if inspect.iscoroutinefunction(process_input_async):
281
294
  _processed_input = await process_input_async(description, runtime)
282
295
  else:
283
296
  _processed_input = (
@@ -297,7 +310,7 @@ def wrap_all_agents_as_tool(
297
310
 
298
311
  response = await agents_map[agent_name].ainvoke(agent_input)
299
312
 
300
- if asyncio.iscoroutinefunction(process_output_async):
313
+ if inspect.iscoroutinefunction(process_output_async):
301
314
  response = await process_output_async(description, response, runtime)
302
315
  else:
303
316
  response = (
@@ -218,14 +218,15 @@ class _BaseChatOpenAICompatible(BaseChatOpenAI):
218
218
  stop: list[str] | None = None,
219
219
  **kwargs: Any,
220
220
  ) -> dict:
221
+ if stop is not None:
222
+ kwargs["stop"] = stop
223
+
221
224
  payload = {**self._default_params, **kwargs}
222
225
 
223
226
  if self._use_responses_api(payload):
224
227
  return super()._get_request_payload(input_, stop=stop, **kwargs)
225
228
 
226
229
  messages = self._convert_input(input_).to_messages()
227
- if stop is not None:
228
- kwargs["stop"] = stop
229
230
 
230
231
  payload_messages = []
231
232
  last_human_index = -1
@@ -0,0 +1,7 @@
1
+ from .parallel import create_parallel_graph
2
+ from .sequential import create_sequential_graph
3
+
4
+ __all__ = [
5
+ "create_parallel_graph",
6
+ "create_sequential_graph",
7
+ ]
@@ -0,0 +1,119 @@
1
+ from typing import Awaitable, Callable, Optional, Union, cast
2
+
3
+ from langgraph.cache.base import BaseCache
4
+ from langgraph.graph import StateGraph
5
+ from langgraph.graph.state import CompiledStateGraph, StateNode
6
+ from langgraph.store.base import BaseStore
7
+ from langgraph.types import Checkpointer, Send
8
+ from langgraph.typing import ContextT, InputT, OutputT, StateT
9
+
10
+ from langchain_dev_utils._utils import _transform_node_to_tuple
11
+
12
+ from .types import Node
13
+
14
+
15
+ def create_parallel_graph(
16
+ nodes: list[Node],
17
+ state_schema: type[StateT],
18
+ graph_name: Optional[str] = None,
19
+ branches_fn: Optional[
20
+ Union[
21
+ Callable[..., list[Send]],
22
+ Callable[..., Awaitable[list[Send]]],
23
+ ]
24
+ ] = None,
25
+ context_schema: type[ContextT] | None = None,
26
+ input_schema: type[InputT] | None = None,
27
+ output_schema: type[OutputT] | None = None,
28
+ checkpointer: Checkpointer | None = None,
29
+ store: BaseStore | None = None,
30
+ cache: BaseCache | None = None,
31
+ ) -> CompiledStateGraph[StateT, ContextT, InputT, OutputT]:
32
+ """
33
+ Create a parallel graph from a list of nodes.
34
+
35
+ This function lets you build a parallel StateGraph simply by writing the corresponding Nodes.
36
+
37
+ Args:
38
+ nodes: List of nodes to execute in parallel
39
+ state_schema: state schema of the final state graph
40
+ graph_name: Name of the final state graph
41
+ branches_fn: Optional function to determine which nodes to execute
42
+ in parallel
43
+ context_schema: context schema of the final state graph
44
+ input_schema: input schema of the final state graph
45
+ output_schema: output schema of the final state graph
46
+ checkpointer: Optional LangGraph checkpointer for the final state graph
47
+ store: Optional LangGraph store for the final state graph
48
+ cache: Optional LangGraph cache for the final state graph
49
+
50
+ Returns:
51
+ CompiledStateGraph[StateT, ContextT, InputT, OutputT]: Compiled state graph
52
+
53
+ Example:
54
+ # Basic parallel pipeline: multiple specialized agents run concurrently
55
+ >>> from langchain_dev_utils.graph import create_parallel_graph
56
+ >>>
57
+ >>> graph = create_parallel_graph(
58
+ ... nodes=[
59
+ ... node1, node2, node3
60
+ ... ],
61
+ ... state_schema=StateT,
62
+ ... graph_name="parallel_graph",
63
+ ... )
64
+ >>>
65
+ >>> response = graph.invoke({"messages": [HumanMessage("Hello")]})
66
+
67
+ # Dynamic parallel pipeline: decide which nodes to run based on conditional branches
68
+ >>> graph = create_parallel_graph(
69
+ ... nodes=[
70
+ ... node1, node2, node3
71
+ ... ],
72
+ ... state_schema=StateT,
73
+ ... branches_fn=lambda state: [
74
+ ... Send("node1", arg={"messages": [HumanMessage("Hello")]}),
75
+ ... Send("node2", arg={"messages": [HumanMessage("Hello")]}),
76
+ ... ],
77
+ ... graph_name="parallel_graph",
78
+ ... )
79
+ >>>
80
+ >>> response = graph.invoke({"messages": [HumanMessage("Hello")]})
81
+ """
82
+ graph = StateGraph(
83
+ state_schema=state_schema,
84
+ context_schema=context_schema,
85
+ input_schema=input_schema,
86
+ output_schema=output_schema,
87
+ )
88
+
89
+ node_list: list[tuple[str, StateNode]] = []
90
+
91
+ for node in nodes:
92
+ node_list.append(_transform_node_to_tuple(node))
93
+
94
+ if branches_fn:
95
+ for name, node in node_list:
96
+ node = cast(StateNode[StateT, ContextT], node)
97
+ graph.add_node(name, node)
98
+ graph.add_conditional_edges(
99
+ "__start__",
100
+ branches_fn,
101
+ [node_name for node_name, _ in node_list],
102
+ )
103
+ return graph.compile(
104
+ name=graph_name or "parallel graph",
105
+ checkpointer=checkpointer,
106
+ store=store,
107
+ cache=cache,
108
+ )
109
+ else:
110
+ for node_name, node in node_list:
111
+ node = cast(StateNode[StateT, ContextT], node)
112
+ graph.add_node(node_name, node)
113
+ graph.add_edge("__start__", node_name)
114
+ return graph.compile(
115
+ name=graph_name or "parallel graph",
116
+ checkpointer=checkpointer,
117
+ store=store,
118
+ cache=cache,
119
+ )
@@ -0,0 +1,78 @@
1
+ from typing import Optional
2
+
3
+ from langgraph.cache.base import BaseCache
4
+ from langgraph.graph import StateGraph
5
+ from langgraph.graph.state import CompiledStateGraph
6
+ from langgraph.store.base import BaseStore
7
+ from langgraph.types import Checkpointer
8
+ from langgraph.typing import ContextT, InputT, OutputT, StateT
9
+
10
+ from langchain_dev_utils._utils import _transform_node_to_tuple
11
+
12
+ from .types import Node
13
+
14
+
15
+ def create_sequential_graph(
16
+ nodes: list[Node],
17
+ state_schema: type[StateT],
18
+ graph_name: Optional[str] = None,
19
+ context_schema: type[ContextT] | None = None,
20
+ input_schema: type[InputT] | None = None,
21
+ output_schema: type[OutputT] | None = None,
22
+ checkpointer: Checkpointer | None = None,
23
+ store: BaseStore | None = None,
24
+ cache: BaseCache | None = None,
25
+ ) -> CompiledStateGraph[StateT, ContextT, InputT, OutputT]:
26
+ """
27
+ Create a sequential graph from a list of nodes.
28
+
29
+ This function lets you build a sequential StateGraph simply by writing the corresponding Nodes.
30
+
31
+ Args:
32
+ nodes: List of nodes to execute sequentially
33
+ state_schema: state schema of the final state graph
34
+ graph_name: Name of the final state graph
35
+ context_schema: context schema of the final state graph
36
+ input_schema: input schema of the final state graph
37
+ output_schema: output schema of the final state graph
38
+ checkpointer: Optional LangGraph checkpointer for the final state graph
39
+ store: Optional LangGraph store for the final state graph
40
+ cache: Optional LangGraph cache for the final state graph
41
+ Returns:
42
+ CompiledStateGraph[StateT, ContextT, InputT, OutputT]: Compiled state graph.
43
+
44
+ Example:
45
+ # Basic sequential graph with multiple specialized agents:
46
+ >>> from langchain_dev_utils.graph.sequential import create_sequential_graph
47
+ >>>
48
+ >>> graph = create_sequential_graph(
49
+ ... nodes=[
50
+ ... node1, node2, node3
51
+ ... ],
52
+ ... state_schema=State,
53
+ ... graph_name="sequential_graph",
54
+ ... )
55
+ >>>
56
+ >>> response = graph.invoke({"messages": [HumanMessage("Hello")]})
57
+ """
58
+ graph = StateGraph(
59
+ state_schema=state_schema,
60
+ context_schema=context_schema,
61
+ input_schema=input_schema,
62
+ output_schema=output_schema,
63
+ )
64
+
65
+ node_list = []
66
+ for node in nodes:
67
+ node = _transform_node_to_tuple(node)
68
+ node_list.append(node)
69
+
70
+ graph.add_sequence(node_list)
71
+ first_node_name, _ = node_list[0]
72
+ graph.add_edge("__start__", first_node_name)
73
+ return graph.compile(
74
+ name=graph_name or "sequential graph",
75
+ checkpointer=checkpointer,
76
+ store=store,
77
+ cache=cache,
78
+ )
@@ -0,0 +1,3 @@
1
+ from langgraph.graph.state import StateNode
2
+
3
+ Node = StateNode | tuple[str, StateNode]
@@ -10,6 +10,39 @@ from langchain_core.messages import (
10
10
  )
11
11
 
12
12
 
13
+ def _format_message(item: BaseMessage) -> str:
14
+ if (
15
+ isinstance(item, HumanMessage)
16
+ or isinstance(item, SystemMessage)
17
+ or isinstance(item, ToolMessage)
18
+ ):
19
+ text = "\n".join(
20
+ [block["text"] for block in item.content_blocks if block["type"] == "text"]
21
+ )
22
+
23
+ role = item.type.title()
24
+ return f"{role}: {text}"
25
+ elif isinstance(item, AIMessage):
26
+ content = (
27
+ "\n".join(
28
+ [
29
+ block["text"]
30
+ for block in item.content_blocks
31
+ if block["type"] == "text"
32
+ ]
33
+ )
34
+ or ""
35
+ )
36
+
37
+ for tool_call in item.tool_calls:
38
+ content += f"\n<tool_call>{tool_call['name']}</tool_call>"
39
+ return f"AI: {content}"
40
+ else:
41
+ raise ValueError(
42
+ f"Unsupported message type: {type(item)},expected HumanMessage, AIMessage, SystemMessage, ToolMessage"
43
+ )
44
+
45
+
13
46
  def format_sequence(
14
47
  inputs: Union[Sequence[Document], Sequence[BaseMessage], Sequence[str]],
15
48
  separator: str = "-",
@@ -57,7 +90,7 @@ def format_sequence(
57
90
  if isinstance(
58
91
  input_item, (HumanMessage, AIMessage, SystemMessage, ToolMessage)
59
92
  ):
60
- outputs.append(input_item.content)
93
+ outputs.append(_format_message(input_item))
61
94
  elif isinstance(input_item, Document):
62
95
  outputs.append(input_item.page_content)
63
96
  elif isinstance(input_item, str):
@@ -6,10 +6,16 @@ from langgraph.graph.state import CompiledStateGraph
6
6
  from langgraph.store.base import BaseStore
7
7
  from langgraph.types import Checkpointer, Send
8
8
  from langgraph.typing import ContextT, InputT, OutputT, StateT
9
+ from typing_extensions import deprecated
9
10
 
10
11
  from .types import SubGraph
11
12
 
12
13
 
14
+ @deprecated(
15
+ """The function create_parallel_pipeline is deprecated since v1.4.0. And it will be remove in v1.5.0.
16
+ Please use create_parallel_graph instead(from graph module).
17
+ """
18
+ )
13
19
  def create_parallel_pipeline(
14
20
  sub_graphs: list[SubGraph],
15
21
  state_schema: type[StateT],
@@ -6,10 +6,16 @@ from langgraph.graph.state import CompiledStateGraph
6
6
  from langgraph.store.base import BaseStore
7
7
  from langgraph.types import Checkpointer
8
8
  from langgraph.typing import ContextT, InputT, OutputT, StateT
9
+ from typing_extensions import deprecated
9
10
 
10
11
  from .types import SubGraph
11
12
 
12
13
 
14
+ @deprecated(
15
+ """The function create_sequential_pipeline is deprecated since v1.4.0. And it will be remove in v1.5.0.
16
+ Please use create_sequential_graph instead(from graph module).
17
+ """
18
+ )
13
19
  def create_sequential_pipeline(
14
20
  sub_graphs: list[SubGraph],
15
21
  state_schema: type[StateT],