agentrun-inner-test 0.0.46__py3-none-any.whl → 0.0.56__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.
- agentrun/__init__.py +1 -1
- agentrun/agent_runtime/api/control.py +1 -1
- agentrun/credential/api/control.py +1 -1
- agentrun/integration/agentscope/__init__.py +2 -1
- agentrun/integration/agentscope/builtin.py +23 -0
- agentrun/integration/builtin/__init__.py +2 -0
- agentrun/integration/builtin/knowledgebase.py +137 -0
- agentrun/integration/crewai/__init__.py +2 -1
- agentrun/integration/crewai/builtin.py +23 -0
- agentrun/integration/google_adk/__init__.py +2 -1
- agentrun/integration/google_adk/builtin.py +23 -0
- agentrun/integration/langchain/__init__.py +2 -1
- agentrun/integration/langchain/builtin.py +23 -0
- agentrun/integration/langgraph/__init__.py +2 -1
- agentrun/integration/langgraph/builtin.py +23 -0
- agentrun/integration/pydantic_ai/__init__.py +2 -1
- agentrun/integration/pydantic_ai/builtin.py +23 -0
- agentrun/knowledgebase/__client_async_template.py +173 -0
- agentrun/knowledgebase/__init__.py +53 -0
- agentrun/knowledgebase/__knowledgebase_async_template.py +438 -0
- agentrun/knowledgebase/api/__data_async_template.py +414 -0
- agentrun/knowledgebase/api/__init__.py +19 -0
- agentrun/knowledgebase/api/control.py +606 -0
- agentrun/knowledgebase/api/data.py +624 -0
- agentrun/knowledgebase/client.py +311 -0
- agentrun/knowledgebase/knowledgebase.py +748 -0
- agentrun/knowledgebase/model.py +270 -0
- agentrun/model/api/control.py +1 -1
- agentrun/sandbox/aio_sandbox.py +11 -4
- agentrun/sandbox/api/control.py +1 -1
- agentrun/sandbox/browser_sandbox.py +2 -2
- agentrun/sandbox/model.py +0 -13
- agentrun/toolset/api/control.py +1 -1
- agentrun/toolset/toolset.py +1 -0
- agentrun/utils/__data_api_async_template.py +1 -0
- agentrun/utils/config.py +12 -0
- agentrun/utils/control_api.py +27 -0
- agentrun/utils/data_api.py +1 -0
- {agentrun_inner_test-0.0.46.dist-info → agentrun_inner_test-0.0.56.dist-info}/METADATA +4 -2
- {agentrun_inner_test-0.0.46.dist-info → agentrun_inner_test-0.0.56.dist-info}/RECORD +43 -32
- {agentrun_inner_test-0.0.46.dist-info → agentrun_inner_test-0.0.56.dist-info}/WHEEL +0 -0
- {agentrun_inner_test-0.0.46.dist-info → agentrun_inner_test-0.0.56.dist-info}/licenses/LICENSE +0 -0
- {agentrun_inner_test-0.0.46.dist-info → agentrun_inner_test-0.0.56.dist-info}/top_level.txt +0 -0
agentrun/__init__.py
CHANGED
|
@@ -35,7 +35,7 @@ from alibabacloud_agentrun20250910.models import (
|
|
|
35
35
|
)
|
|
36
36
|
from alibabacloud_tea_openapi.exceptions._client import ClientException
|
|
37
37
|
from alibabacloud_tea_openapi.exceptions._server import ServerException
|
|
38
|
-
from
|
|
38
|
+
from darabonba.runtime import RuntimeOptions
|
|
39
39
|
import pydash
|
|
40
40
|
|
|
41
41
|
from agentrun.utils.config import Config
|
|
@@ -25,7 +25,7 @@ from alibabacloud_agentrun20250910.models import (
|
|
|
25
25
|
)
|
|
26
26
|
from alibabacloud_tea_openapi.exceptions._client import ClientException
|
|
27
27
|
from alibabacloud_tea_openapi.exceptions._server import ServerException
|
|
28
|
-
from
|
|
28
|
+
from darabonba.runtime import RuntimeOptions
|
|
29
29
|
import pydash
|
|
30
30
|
|
|
31
31
|
from agentrun.utils.config import Config
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
提供 AgentRun 模型与沙箱工具的 AgentScope 适配入口。 / 提供 AgentRun 模型with沙箱工具的 AgentScope 适配入口。
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
|
-
from .builtin import model, sandbox_toolset, toolset
|
|
6
|
+
from .builtin import knowledgebase_toolset, model, sandbox_toolset, toolset
|
|
7
7
|
|
|
8
8
|
__all__ = [
|
|
9
9
|
"model",
|
|
10
10
|
"toolset",
|
|
11
11
|
"sandbox_toolset",
|
|
12
|
+
"knowledgebase_toolset",
|
|
12
13
|
]
|
|
@@ -8,6 +8,9 @@ from typing import Any, Callable, List, Optional, Union
|
|
|
8
8
|
|
|
9
9
|
from typing_extensions import Unpack
|
|
10
10
|
|
|
11
|
+
from agentrun.integration.builtin import (
|
|
12
|
+
knowledgebase_toolset as _knowledgebase_toolset,
|
|
13
|
+
)
|
|
11
14
|
from agentrun.integration.builtin import model as _model
|
|
12
15
|
from agentrun.integration.builtin import ModelArgs
|
|
13
16
|
from agentrun.integration.builtin import sandbox_toolset as _sandbox_toolset
|
|
@@ -63,3 +66,23 @@ def sandbox_toolset(
|
|
|
63
66
|
config=config,
|
|
64
67
|
sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds,
|
|
65
68
|
).to_agentscope(prefix=prefix)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def knowledgebase_toolset(
|
|
72
|
+
knowledge_base_names: List[str],
|
|
73
|
+
*,
|
|
74
|
+
prefix: Optional[str] = None,
|
|
75
|
+
modify_tool_name: Optional[Callable[[Tool], Tool]] = None,
|
|
76
|
+
filter_tools_by_name: Optional[Callable[[str], bool]] = None,
|
|
77
|
+
config: Optional[Config] = None,
|
|
78
|
+
) -> List[Any]:
|
|
79
|
+
"""将知识库检索封装为 AgentScope 工具列表。 / AgentScope Built-in Integration Functions"""
|
|
80
|
+
|
|
81
|
+
return _knowledgebase_toolset(
|
|
82
|
+
knowledge_base_names=knowledge_base_names,
|
|
83
|
+
config=config,
|
|
84
|
+
).to_agentscope(
|
|
85
|
+
prefix=prefix,
|
|
86
|
+
modify_tool_name=modify_tool_name,
|
|
87
|
+
filter_tools_by_name=filter_tools_by_name,
|
|
88
|
+
)
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
This module provides built-in integration functions for quickly creating models and tools.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
+
from .knowledgebase import knowledgebase_toolset
|
|
7
8
|
from .model import model, ModelArgs
|
|
8
9
|
from .sandbox import sandbox_toolset
|
|
9
10
|
from .toolset import toolset
|
|
@@ -13,4 +14,5 @@ __all__ = [
|
|
|
13
14
|
"ModelArgs",
|
|
14
15
|
"toolset",
|
|
15
16
|
"sandbox_toolset",
|
|
17
|
+
"knowledgebase_toolset",
|
|
16
18
|
]
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"""知识库工具集 / KnowledgeBase ToolSet
|
|
2
|
+
|
|
3
|
+
提供知识库检索功能的工具集,支持多知识库联合检索。
|
|
4
|
+
Provides toolset for knowledge base retrieval, supporting multi-knowledge-base search.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import Any, Dict, List, Optional
|
|
10
|
+
|
|
11
|
+
from agentrun.integration.utils.tool import CommonToolSet, tool
|
|
12
|
+
from agentrun.knowledgebase import KnowledgeBase
|
|
13
|
+
from agentrun.utils.config import Config
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class KnowledgeBaseToolSet(CommonToolSet):
|
|
17
|
+
"""知识库工具集 / KnowledgeBase ToolSet
|
|
18
|
+
|
|
19
|
+
提供知识库检索功能,支持对多个知识库进行联合检索。
|
|
20
|
+
Provides knowledge base retrieval capabilities, supporting joint retrieval
|
|
21
|
+
across multiple knowledge bases.
|
|
22
|
+
|
|
23
|
+
使用指南 / Usage Guide:
|
|
24
|
+
============================================================
|
|
25
|
+
|
|
26
|
+
## 基本用法 / Basic Usage
|
|
27
|
+
|
|
28
|
+
1. **创建工具集 / Create ToolSet**:
|
|
29
|
+
- 使用 `knowledgebase_toolset` 函数创建工具集实例
|
|
30
|
+
- Use `knowledgebase_toolset` function to create a toolset instance
|
|
31
|
+
- 指定要检索的知识库名称列表
|
|
32
|
+
- Specify the list of knowledge base names to search
|
|
33
|
+
|
|
34
|
+
2. **执行检索 / Execute Search**:
|
|
35
|
+
- 调用 `search_document` 工具进行检索
|
|
36
|
+
- Call `search_document` tool to perform retrieval
|
|
37
|
+
- 返回所有指定知识库的检索结果
|
|
38
|
+
- Returns retrieval results from all specified knowledge bases
|
|
39
|
+
|
|
40
|
+
## 示例 / Examples
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from agentrun.integration.langchain import knowledgebase_toolset
|
|
44
|
+
|
|
45
|
+
# 创建工具集 / Create toolset
|
|
46
|
+
tools = knowledgebase_toolset(
|
|
47
|
+
knowledge_base_names=["kb-product-docs", "kb-faq"],
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# 在 Agent 中使用 / Use in Agent
|
|
51
|
+
agent = create_react_agent(llm, tools)
|
|
52
|
+
```
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
def __init__(
|
|
56
|
+
self,
|
|
57
|
+
knowledge_base_names: List[str],
|
|
58
|
+
config: Optional[Config] = None,
|
|
59
|
+
) -> None:
|
|
60
|
+
"""初始化知识库工具集 / Initialize KnowledgeBase ToolSet
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
knowledge_base_names: 知识库名称列表 / List of knowledge base names
|
|
64
|
+
config: 配置 / Configuration
|
|
65
|
+
"""
|
|
66
|
+
super().__init__()
|
|
67
|
+
|
|
68
|
+
self.knowledge_base_names = knowledge_base_names
|
|
69
|
+
self.config = config
|
|
70
|
+
|
|
71
|
+
@tool(
|
|
72
|
+
name="search_document",
|
|
73
|
+
description=(
|
|
74
|
+
"Search and retrieve relevant documents from configured knowledge"
|
|
75
|
+
" bases. Use this tool when you need to find information from the"
|
|
76
|
+
" knowledge base to answer user questions. Returns relevant"
|
|
77
|
+
" document chunks with their content and metadata. The search is"
|
|
78
|
+
" performed across all configured knowledge bases and results are"
|
|
79
|
+
" grouped by knowledge base name."
|
|
80
|
+
),
|
|
81
|
+
)
|
|
82
|
+
def search_document(self, query: str) -> Dict[str, Any]:
|
|
83
|
+
"""检索文档 / Search documents
|
|
84
|
+
|
|
85
|
+
根据查询文本从配置的知识库中检索相关文档。
|
|
86
|
+
Retrieves relevant documents from configured knowledge bases based on query text.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
query: 查询文本 / Query text
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
Dict[str, Any]: 检索结果,包含各知识库的检索结果 /
|
|
93
|
+
Retrieval results containing results from each knowledge base
|
|
94
|
+
"""
|
|
95
|
+
return KnowledgeBase.multi_retrieve(
|
|
96
|
+
query=query,
|
|
97
|
+
knowledge_base_names=self.knowledge_base_names,
|
|
98
|
+
config=self.config,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def knowledgebase_toolset(
|
|
103
|
+
knowledge_base_names: List[str],
|
|
104
|
+
*,
|
|
105
|
+
config: Optional[Config] = None,
|
|
106
|
+
) -> KnowledgeBaseToolSet:
|
|
107
|
+
"""创建知识库工具集 / Create KnowledgeBase ToolSet
|
|
108
|
+
|
|
109
|
+
将知识库检索功能封装为通用工具集,可转换为各框架支持的格式。
|
|
110
|
+
Wraps knowledge base retrieval functionality into a common toolset that can be
|
|
111
|
+
converted to formats supported by various frameworks.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
knowledge_base_names: 知识库名称列表 / List of knowledge base names
|
|
115
|
+
config: 配置 / Configuration
|
|
116
|
+
|
|
117
|
+
Returns:
|
|
118
|
+
KnowledgeBaseToolSet: 知识库工具集实例 / KnowledgeBase toolset instance
|
|
119
|
+
|
|
120
|
+
Example:
|
|
121
|
+
>>> from agentrun.integration.builtin import knowledgebase_toolset
|
|
122
|
+
>>>
|
|
123
|
+
>>> # 创建工具集 / Create toolset
|
|
124
|
+
>>> kb_tools = knowledgebase_toolset(
|
|
125
|
+
... knowledge_base_names=["kb-docs", "kb-faq"],
|
|
126
|
+
... )
|
|
127
|
+
>>>
|
|
128
|
+
>>> # 转换为 LangChain 格式 / Convert to LangChain format
|
|
129
|
+
>>> langchain_tools = kb_tools.to_langchain()
|
|
130
|
+
>>>
|
|
131
|
+
>>> # 转换为 Google ADK 格式 / Convert to Google ADK format
|
|
132
|
+
>>> adk_tools = kb_tools.to_google_adk()
|
|
133
|
+
"""
|
|
134
|
+
return KnowledgeBaseToolSet(
|
|
135
|
+
knowledge_base_names=knowledge_base_names,
|
|
136
|
+
config=config,
|
|
137
|
+
)
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
CrewAI 与 LangChain 兼容,因此直接复用 LangChain 的转换逻辑。 / CrewAI with LangChain 兼容,因此直接复用 LangChain 的转换逻辑。
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
-
from .builtin import model, sandbox_toolset
|
|
7
|
+
from .builtin import knowledgebase_toolset, model, sandbox_toolset
|
|
8
8
|
|
|
9
9
|
__all__ = [
|
|
10
10
|
"model",
|
|
11
11
|
"sandbox_toolset",
|
|
12
|
+
"knowledgebase_toolset",
|
|
12
13
|
]
|
|
@@ -8,6 +8,9 @@ from typing import Any, Callable, List, Optional, Union
|
|
|
8
8
|
|
|
9
9
|
from typing_extensions import Unpack
|
|
10
10
|
|
|
11
|
+
from agentrun.integration.builtin import (
|
|
12
|
+
knowledgebase_toolset as _knowledgebase_toolset,
|
|
13
|
+
)
|
|
11
14
|
from agentrun.integration.builtin import model as _model
|
|
12
15
|
from agentrun.integration.builtin import ModelArgs
|
|
13
16
|
from agentrun.integration.builtin import sandbox_toolset as _sandbox_toolset
|
|
@@ -63,3 +66,23 @@ def sandbox_toolset(
|
|
|
63
66
|
config=config,
|
|
64
67
|
sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds,
|
|
65
68
|
).to_crewai(prefix=prefix)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def knowledgebase_toolset(
|
|
72
|
+
knowledge_base_names: List[str],
|
|
73
|
+
*,
|
|
74
|
+
prefix: Optional[str] = None,
|
|
75
|
+
modify_tool_name: Optional[Callable[[Tool], Tool]] = None,
|
|
76
|
+
filter_tools_by_name: Optional[Callable[[str], bool]] = None,
|
|
77
|
+
config: Optional[Config] = None,
|
|
78
|
+
) -> List[Any]:
|
|
79
|
+
"""将知识库检索封装为 CrewAI 工具列表。 / CrewAI Built-in Integration Functions"""
|
|
80
|
+
|
|
81
|
+
return _knowledgebase_toolset(
|
|
82
|
+
knowledge_base_names=knowledge_base_names,
|
|
83
|
+
config=config,
|
|
84
|
+
).to_crewai(
|
|
85
|
+
prefix=prefix,
|
|
86
|
+
modify_tool_name=modify_tool_name,
|
|
87
|
+
filter_tools_by_name=filter_tools_by_name,
|
|
88
|
+
)
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
提供与 Google Agent Development Kit 的模型与沙箱工具集成。 / 提供with Google Agent Development Kit 的模型with沙箱工具集成。
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
|
-
from .builtin import model, sandbox_toolset, toolset
|
|
6
|
+
from .builtin import knowledgebase_toolset, model, sandbox_toolset, toolset
|
|
7
7
|
|
|
8
8
|
__all__ = [
|
|
9
9
|
"model",
|
|
10
10
|
"toolset",
|
|
11
11
|
"sandbox_toolset",
|
|
12
|
+
"knowledgebase_toolset",
|
|
12
13
|
]
|
|
@@ -8,6 +8,9 @@ from typing import Any, Callable, List, Optional, Union
|
|
|
8
8
|
|
|
9
9
|
from typing_extensions import Unpack
|
|
10
10
|
|
|
11
|
+
from agentrun.integration.builtin import (
|
|
12
|
+
knowledgebase_toolset as _knowledgebase_toolset,
|
|
13
|
+
)
|
|
11
14
|
from agentrun.integration.builtin import model as _model
|
|
12
15
|
from agentrun.integration.builtin import ModelArgs
|
|
13
16
|
from agentrun.integration.builtin import sandbox_toolset as _sandbox_toolset
|
|
@@ -63,3 +66,23 @@ def sandbox_toolset(
|
|
|
63
66
|
config=config,
|
|
64
67
|
sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds,
|
|
65
68
|
).to_google_adk(prefix=prefix)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def knowledgebase_toolset(
|
|
72
|
+
knowledge_base_names: List[str],
|
|
73
|
+
*,
|
|
74
|
+
prefix: Optional[str] = None,
|
|
75
|
+
modify_tool_name: Optional[Callable[[Tool], Tool]] = None,
|
|
76
|
+
filter_tools_by_name: Optional[Callable[[str], bool]] = None,
|
|
77
|
+
config: Optional[Config] = None,
|
|
78
|
+
) -> List[Any]:
|
|
79
|
+
"""将知识库检索封装为 Google ADK 工具列表。 / Google ADK Built-in Integration Functions"""
|
|
80
|
+
|
|
81
|
+
return _knowledgebase_toolset(
|
|
82
|
+
knowledge_base_names=knowledge_base_names,
|
|
83
|
+
config=config,
|
|
84
|
+
).to_google_adk(
|
|
85
|
+
prefix=prefix,
|
|
86
|
+
modify_tool_name=modify_tool_name,
|
|
87
|
+
filter_tools_by_name=filter_tools_by_name,
|
|
88
|
+
)
|
|
@@ -20,11 +20,12 @@ from agentrun.integration.langgraph.agent_converter import (
|
|
|
20
20
|
AgentRunConverter,
|
|
21
21
|
) # 向后兼容
|
|
22
22
|
|
|
23
|
-
from .builtin import model, sandbox_toolset, toolset
|
|
23
|
+
from .builtin import knowledgebase_toolset, model, sandbox_toolset, toolset
|
|
24
24
|
|
|
25
25
|
__all__ = [
|
|
26
26
|
"AgentRunConverter",
|
|
27
27
|
"model",
|
|
28
28
|
"toolset",
|
|
29
29
|
"sandbox_toolset",
|
|
30
|
+
"knowledgebase_toolset",
|
|
30
31
|
]
|
|
@@ -8,6 +8,9 @@ from typing import Any, Callable, List, Optional, Union
|
|
|
8
8
|
|
|
9
9
|
from typing_extensions import Unpack
|
|
10
10
|
|
|
11
|
+
from agentrun.integration.builtin import (
|
|
12
|
+
knowledgebase_toolset as _knowledgebase_toolset,
|
|
13
|
+
)
|
|
11
14
|
from agentrun.integration.builtin import model as _model
|
|
12
15
|
from agentrun.integration.builtin import ModelArgs
|
|
13
16
|
from agentrun.integration.builtin import sandbox_toolset as _sandbox_toolset
|
|
@@ -69,3 +72,23 @@ def sandbox_toolset(
|
|
|
69
72
|
modify_tool_name=modify_tool_name,
|
|
70
73
|
filter_tools_by_name=filter_tools_by_name,
|
|
71
74
|
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def knowledgebase_toolset(
|
|
78
|
+
knowledge_base_names: List[str],
|
|
79
|
+
*,
|
|
80
|
+
prefix: Optional[str] = None,
|
|
81
|
+
modify_tool_name: Optional[Callable[[Tool], Tool]] = None,
|
|
82
|
+
filter_tools_by_name: Optional[Callable[[str], bool]] = None,
|
|
83
|
+
config: Optional[Config] = None,
|
|
84
|
+
) -> List[Any]:
|
|
85
|
+
"""将知识库检索封装为 LangChain ``StructuredTool`` 列表。 / LangChain Built-in Integration Functions"""
|
|
86
|
+
|
|
87
|
+
return _knowledgebase_toolset(
|
|
88
|
+
knowledge_base_names=knowledge_base_names,
|
|
89
|
+
config=config,
|
|
90
|
+
).to_langchain(
|
|
91
|
+
prefix=prefix,
|
|
92
|
+
modify_tool_name=modify_tool_name,
|
|
93
|
+
filter_tools_by_name=filter_tools_by_name,
|
|
94
|
+
)
|
|
@@ -25,11 +25,12 @@
|
|
|
25
25
|
"""
|
|
26
26
|
|
|
27
27
|
from .agent_converter import AgentRunConverter
|
|
28
|
-
from .builtin import model, sandbox_toolset, toolset
|
|
28
|
+
from .builtin import knowledgebase_toolset, model, sandbox_toolset, toolset
|
|
29
29
|
|
|
30
30
|
__all__ = [
|
|
31
31
|
"AgentRunConverter",
|
|
32
32
|
"model",
|
|
33
33
|
"toolset",
|
|
34
34
|
"sandbox_toolset",
|
|
35
|
+
"knowledgebase_toolset",
|
|
35
36
|
]
|
|
@@ -8,6 +8,9 @@ from typing import Any, Callable, List, Optional, Union
|
|
|
8
8
|
|
|
9
9
|
from typing_extensions import Unpack
|
|
10
10
|
|
|
11
|
+
from agentrun.integration.builtin import (
|
|
12
|
+
knowledgebase_toolset as _knowledgebase_toolset,
|
|
13
|
+
)
|
|
11
14
|
from agentrun.integration.builtin import model as _model
|
|
12
15
|
from agentrun.integration.builtin import ModelArgs
|
|
13
16
|
from agentrun.integration.builtin import sandbox_toolset as _sandbox_toolset
|
|
@@ -63,3 +66,23 @@ def sandbox_toolset(
|
|
|
63
66
|
config=config,
|
|
64
67
|
sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds,
|
|
65
68
|
).to_langgraph(prefix=prefix)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def knowledgebase_toolset(
|
|
72
|
+
knowledge_base_names: List[str],
|
|
73
|
+
*,
|
|
74
|
+
prefix: Optional[str] = None,
|
|
75
|
+
modify_tool_name: Optional[Callable[[Tool], Tool]] = None,
|
|
76
|
+
filter_tools_by_name: Optional[Callable[[str], bool]] = None,
|
|
77
|
+
config: Optional[Config] = None,
|
|
78
|
+
) -> List[Any]:
|
|
79
|
+
"""将知识库检索封装为 LangGraph ``StructuredTool`` 列表。 / LangGraph Built-in Integration Functions"""
|
|
80
|
+
|
|
81
|
+
return _knowledgebase_toolset(
|
|
82
|
+
knowledge_base_names=knowledge_base_names,
|
|
83
|
+
config=config,
|
|
84
|
+
).to_langgraph(
|
|
85
|
+
prefix=prefix,
|
|
86
|
+
modify_tool_name=modify_tool_name,
|
|
87
|
+
filter_tools_by_name=filter_tools_by_name,
|
|
88
|
+
)
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
提供 AgentRun 模型与沙箱工具的 PydanticAI 适配入口。 / 提供 AgentRun 模型with沙箱工具的 PydanticAI 适配入口。
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
|
-
from .builtin import model, sandbox_toolset, toolset
|
|
6
|
+
from .builtin import knowledgebase_toolset, model, sandbox_toolset, toolset
|
|
7
7
|
|
|
8
8
|
__all__ = [
|
|
9
9
|
"model",
|
|
10
10
|
"toolset",
|
|
11
11
|
"sandbox_toolset",
|
|
12
|
+
"knowledgebase_toolset",
|
|
12
13
|
]
|
|
@@ -8,6 +8,9 @@ from typing import Any, Callable, List, Optional, Union
|
|
|
8
8
|
|
|
9
9
|
from typing_extensions import Unpack
|
|
10
10
|
|
|
11
|
+
from agentrun.integration.builtin import (
|
|
12
|
+
knowledgebase_toolset as _knowledgebase_toolset,
|
|
13
|
+
)
|
|
11
14
|
from agentrun.integration.builtin import model as _model
|
|
12
15
|
from agentrun.integration.builtin import ModelArgs
|
|
13
16
|
from agentrun.integration.builtin import sandbox_toolset as _sandbox_toolset
|
|
@@ -63,3 +66,23 @@ def sandbox_toolset(
|
|
|
63
66
|
config=config,
|
|
64
67
|
sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds,
|
|
65
68
|
).to_pydantic_ai(prefix=prefix)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def knowledgebase_toolset(
|
|
72
|
+
knowledge_base_names: List[str],
|
|
73
|
+
*,
|
|
74
|
+
prefix: Optional[str] = None,
|
|
75
|
+
modify_tool_name: Optional[Callable[[Tool], Tool]] = None,
|
|
76
|
+
filter_tools_by_name: Optional[Callable[[str], bool]] = None,
|
|
77
|
+
config: Optional[Config] = None,
|
|
78
|
+
) -> List[Any]:
|
|
79
|
+
"""将知识库检索封装为 PydanticAI 工具列表。 / PydanticAI Built-in Integration Functions"""
|
|
80
|
+
|
|
81
|
+
return _knowledgebase_toolset(
|
|
82
|
+
knowledge_base_names=knowledge_base_names,
|
|
83
|
+
config=config,
|
|
84
|
+
).to_pydantic_ai(
|
|
85
|
+
prefix=prefix,
|
|
86
|
+
modify_tool_name=modify_tool_name,
|
|
87
|
+
filter_tools_by_name=filter_tools_by_name,
|
|
88
|
+
)
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"""KnowledgeBase 客户端 / KnowledgeBase Client
|
|
2
|
+
|
|
3
|
+
此模块提供知识库管理的客户端API。
|
|
4
|
+
This module provides the client API for knowledge base management.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
from alibabacloud_agentrun20250910.models import (
|
|
10
|
+
CreateKnowledgeBaseInput,
|
|
11
|
+
ListKnowledgeBasesRequest,
|
|
12
|
+
UpdateKnowledgeBaseInput,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
from agentrun.utils.config import Config
|
|
16
|
+
from agentrun.utils.exception import HTTPError
|
|
17
|
+
|
|
18
|
+
from .api.control import KnowledgeBaseControlAPI
|
|
19
|
+
from .knowledgebase import KnowledgeBase
|
|
20
|
+
from .model import (
|
|
21
|
+
KnowledgeBaseCreateInput,
|
|
22
|
+
KnowledgeBaseListInput,
|
|
23
|
+
KnowledgeBaseListOutput,
|
|
24
|
+
KnowledgeBaseUpdateInput,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class KnowledgeBaseClient:
|
|
29
|
+
"""KnowledgeBase 客户端 / KnowledgeBase Client
|
|
30
|
+
|
|
31
|
+
提供知识库的创建、删除、更新和查询功能。
|
|
32
|
+
Provides create, delete, update and query functions for knowledge bases.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
def __init__(self, config: Optional[Config] = None):
|
|
36
|
+
"""初始化客户端 / Initialize client
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
config: 配置对象,可选 / Configuration object, optional
|
|
40
|
+
"""
|
|
41
|
+
self.__control_api = KnowledgeBaseControlAPI(config)
|
|
42
|
+
|
|
43
|
+
async def create_async(
|
|
44
|
+
self, input: KnowledgeBaseCreateInput, config: Optional[Config] = None
|
|
45
|
+
):
|
|
46
|
+
"""创建知识库(异步) / Create knowledge base asynchronously
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
input: 知识库输入参数 / KnowledgeBase input parameters
|
|
50
|
+
config: 配置对象,可选 / Configuration object, optional
|
|
51
|
+
|
|
52
|
+
Returns:
|
|
53
|
+
KnowledgeBase: 创建的知识库对象 / Created knowledge base object
|
|
54
|
+
|
|
55
|
+
Raises:
|
|
56
|
+
ResourceAlreadyExistError: 资源已存在 / Resource already exists
|
|
57
|
+
HTTPError: HTTP 请求错误 / HTTP request error
|
|
58
|
+
"""
|
|
59
|
+
try:
|
|
60
|
+
result = await self.__control_api.create_knowledge_base_async(
|
|
61
|
+
CreateKnowledgeBaseInput().from_map(input.model_dump()),
|
|
62
|
+
config=config,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
return KnowledgeBase.from_inner_object(result)
|
|
66
|
+
except HTTPError as e:
|
|
67
|
+
raise e.to_resource_error(
|
|
68
|
+
"KnowledgeBase", input.knowledge_base_name
|
|
69
|
+
) from e
|
|
70
|
+
|
|
71
|
+
async def delete_async(
|
|
72
|
+
self, knowledge_base_name: str, config: Optional[Config] = None
|
|
73
|
+
):
|
|
74
|
+
"""删除知识库(异步)/ Delete knowledge base asynchronously
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
knowledge_base_name: 知识库名称 / KnowledgeBase name
|
|
78
|
+
config: 配置 / Configuration
|
|
79
|
+
|
|
80
|
+
Raises:
|
|
81
|
+
ResourceNotExistError: 知识库不存在 / KnowledgeBase not found
|
|
82
|
+
"""
|
|
83
|
+
try:
|
|
84
|
+
result = await self.__control_api.delete_knowledge_base_async(
|
|
85
|
+
knowledge_base_name, config=config
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
return KnowledgeBase.from_inner_object(result)
|
|
89
|
+
|
|
90
|
+
except HTTPError as e:
|
|
91
|
+
raise e.to_resource_error(
|
|
92
|
+
"KnowledgeBase", knowledge_base_name
|
|
93
|
+
) from e
|
|
94
|
+
|
|
95
|
+
async def update_async(
|
|
96
|
+
self,
|
|
97
|
+
knowledge_base_name: str,
|
|
98
|
+
input: KnowledgeBaseUpdateInput,
|
|
99
|
+
config: Optional[Config] = None,
|
|
100
|
+
):
|
|
101
|
+
"""更新知识库(异步)/ Update knowledge base asynchronously
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
knowledge_base_name: 知识库名称 / KnowledgeBase name
|
|
105
|
+
input: 知识库更新输入参数 / KnowledgeBase update input parameters
|
|
106
|
+
config: 配置 / Configuration
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
KnowledgeBase: 更新后的知识库对象 / Updated knowledge base object
|
|
110
|
+
|
|
111
|
+
Raises:
|
|
112
|
+
ResourceNotExistError: 知识库不存在 / KnowledgeBase not found
|
|
113
|
+
"""
|
|
114
|
+
try:
|
|
115
|
+
result = await self.__control_api.update_knowledge_base_async(
|
|
116
|
+
knowledge_base_name,
|
|
117
|
+
UpdateKnowledgeBaseInput().from_map(input.model_dump()),
|
|
118
|
+
config=config,
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
return KnowledgeBase.from_inner_object(result)
|
|
122
|
+
except HTTPError as e:
|
|
123
|
+
raise e.to_resource_error(
|
|
124
|
+
"KnowledgeBase", knowledge_base_name
|
|
125
|
+
) from e
|
|
126
|
+
|
|
127
|
+
async def get_async(
|
|
128
|
+
self, knowledge_base_name: str, config: Optional[Config] = None
|
|
129
|
+
):
|
|
130
|
+
"""获取知识库(异步)/ Get knowledge base asynchronously
|
|
131
|
+
|
|
132
|
+
Args:
|
|
133
|
+
knowledge_base_name: 知识库名称 / KnowledgeBase name
|
|
134
|
+
config: 配置 / Configuration
|
|
135
|
+
|
|
136
|
+
Returns:
|
|
137
|
+
KnowledgeBase: 知识库对象 / KnowledgeBase object
|
|
138
|
+
|
|
139
|
+
Raises:
|
|
140
|
+
ResourceNotExistError: 知识库不存在 / KnowledgeBase not found
|
|
141
|
+
"""
|
|
142
|
+
try:
|
|
143
|
+
result = await self.__control_api.get_knowledge_base_async(
|
|
144
|
+
knowledge_base_name, config=config
|
|
145
|
+
)
|
|
146
|
+
return KnowledgeBase.from_inner_object(result)
|
|
147
|
+
except HTTPError as e:
|
|
148
|
+
raise e.to_resource_error(
|
|
149
|
+
"KnowledgeBase", knowledge_base_name
|
|
150
|
+
) from e
|
|
151
|
+
|
|
152
|
+
async def list_async(
|
|
153
|
+
self,
|
|
154
|
+
input: Optional[KnowledgeBaseListInput] = None,
|
|
155
|
+
config: Optional[Config] = None,
|
|
156
|
+
):
|
|
157
|
+
"""列出知识库(异步)/ List knowledge bases asynchronously
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
input: 分页查询参数 / Pagination query parameters
|
|
161
|
+
config: 配置 / Configuration
|
|
162
|
+
|
|
163
|
+
Returns:
|
|
164
|
+
List[KnowledgeBaseListOutput]: 知识库列表 / KnowledgeBase list
|
|
165
|
+
"""
|
|
166
|
+
if input is None:
|
|
167
|
+
input = KnowledgeBaseListInput()
|
|
168
|
+
|
|
169
|
+
results = await self.__control_api.list_knowledge_bases_async(
|
|
170
|
+
ListKnowledgeBasesRequest().from_map(input.model_dump()),
|
|
171
|
+
config=config,
|
|
172
|
+
)
|
|
173
|
+
return [KnowledgeBaseListOutput.from_inner_object(item) for item in results.items] # type: ignore
|