agentrun-inner-test 0.0.46__py3-none-any.whl → 0.0.64__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 +34 -1
- agentrun/agent_runtime/__endpoint_async_template.py +40 -0
- agentrun/agent_runtime/api/control.py +1 -1
- agentrun/agent_runtime/endpoint.py +79 -0
- 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/memory_collection/__client_async_template.py +178 -0
- agentrun/memory_collection/__init__.py +37 -0
- agentrun/memory_collection/__memory_collection_async_template.py +457 -0
- agentrun/memory_collection/api/__init__.py +5 -0
- agentrun/memory_collection/api/control.py +610 -0
- agentrun/memory_collection/client.py +323 -0
- agentrun/memory_collection/memory_collection.py +844 -0
- agentrun/memory_collection/model.py +162 -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.64.dist-info}/METADATA +4 -2
- {agentrun_inner_test-0.0.46.dist-info → agentrun_inner_test-0.0.64.dist-info}/RECORD +53 -34
- {agentrun_inner_test-0.0.46.dist-info → agentrun_inner_test-0.0.64.dist-info}/WHEEL +0 -0
- {agentrun_inner_test-0.0.46.dist-info → agentrun_inner_test-0.0.64.dist-info}/licenses/LICENSE +0 -0
- {agentrun_inner_test-0.0.46.dist-info → agentrun_inner_test-0.0.64.dist-info}/top_level.txt +0 -0
agentrun/__init__.py
CHANGED
|
@@ -18,7 +18,7 @@ Provides simple and easy-to-use APIs for managing AI Agent runtime environments,
|
|
|
18
18
|
|
|
19
19
|
from typing import TYPE_CHECKING
|
|
20
20
|
|
|
21
|
-
__version__ = "0.0.
|
|
21
|
+
__version__ = "0.0.64"
|
|
22
22
|
|
|
23
23
|
# Agent Runtime
|
|
24
24
|
from agentrun.agent_runtime import (
|
|
@@ -55,6 +55,22 @@ from agentrun.credential import (
|
|
|
55
55
|
CredentialUpdateInput,
|
|
56
56
|
RelatedResource,
|
|
57
57
|
)
|
|
58
|
+
# Memory Collection
|
|
59
|
+
from agentrun.memory_collection import (
|
|
60
|
+
EmbedderConfig,
|
|
61
|
+
EmbedderConfigConfig,
|
|
62
|
+
LLMConfig,
|
|
63
|
+
LLMConfigConfig,
|
|
64
|
+
MemoryCollection,
|
|
65
|
+
MemoryCollectionClient,
|
|
66
|
+
MemoryCollectionCreateInput,
|
|
67
|
+
MemoryCollectionListInput,
|
|
68
|
+
MemoryCollectionListOutput,
|
|
69
|
+
MemoryCollectionUpdateInput,
|
|
70
|
+
NetworkConfiguration,
|
|
71
|
+
VectorStoreConfig,
|
|
72
|
+
VectorStoreConfigConfig,
|
|
73
|
+
)
|
|
58
74
|
# Model Service
|
|
59
75
|
from agentrun.model import (
|
|
60
76
|
BackendType,
|
|
@@ -173,6 +189,23 @@ __all__ = [
|
|
|
173
189
|
"CredentialCreateInput",
|
|
174
190
|
"CredentialUpdateInput",
|
|
175
191
|
"CredentialListInput",
|
|
192
|
+
######## Memory Collection ########
|
|
193
|
+
# base
|
|
194
|
+
"MemoryCollection",
|
|
195
|
+
"MemoryCollectionClient",
|
|
196
|
+
# inner model
|
|
197
|
+
"EmbedderConfig",
|
|
198
|
+
"EmbedderConfigConfig",
|
|
199
|
+
"LLMConfig",
|
|
200
|
+
"LLMConfigConfig",
|
|
201
|
+
"NetworkConfiguration",
|
|
202
|
+
"VectorStoreConfig",
|
|
203
|
+
"VectorStoreConfigConfig",
|
|
204
|
+
# api model
|
|
205
|
+
"MemoryCollectionCreateInput",
|
|
206
|
+
"MemoryCollectionUpdateInput",
|
|
207
|
+
"MemoryCollectionListInput",
|
|
208
|
+
"MemoryCollectionListOutput",
|
|
176
209
|
######## Model ########
|
|
177
210
|
# base
|
|
178
211
|
"ModelClient",
|
|
@@ -18,6 +18,7 @@ from agentrun.agent_runtime.model import (
|
|
|
18
18
|
AgentRuntimeEndpointUpdateInput,
|
|
19
19
|
)
|
|
20
20
|
from agentrun.utils.config import Config
|
|
21
|
+
from agentrun.utils.model import PageableInput
|
|
21
22
|
from agentrun.utils.resource import ResourceBase
|
|
22
23
|
|
|
23
24
|
|
|
@@ -160,6 +161,45 @@ class AgentRuntimeEndpoint(
|
|
|
160
161
|
config=config,
|
|
161
162
|
)
|
|
162
163
|
|
|
164
|
+
@classmethod
|
|
165
|
+
async def _list_page_async(
|
|
166
|
+
cls,
|
|
167
|
+
page_input: PageableInput,
|
|
168
|
+
config: Optional[Config] = None,
|
|
169
|
+
**kwargs,
|
|
170
|
+
) -> List["AgentRuntimeEndpoint"]:
|
|
171
|
+
"""分页列出端点 / List endpoints by page
|
|
172
|
+
|
|
173
|
+
此方法是 ResourceBase 要求实现的抽象方法,用于支持分页查询。
|
|
174
|
+
This method is an abstract method required by ResourceBase to support pagination.
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
page_input: 分页参数 / Pagination parameters
|
|
178
|
+
config: 配置对象,可选 / Configuration object, optional
|
|
179
|
+
**kwargs: 其他参数,必须包含 agent_runtime_id / Other parameters, must include agent_runtime_id
|
|
180
|
+
|
|
181
|
+
Returns:
|
|
182
|
+
List[AgentRuntimeEndpoint]: 端点对象列表 / List of endpoint objects
|
|
183
|
+
|
|
184
|
+
Raises:
|
|
185
|
+
ValueError: 当 agent_runtime_id 未提供时 / When agent_runtime_id is not provided
|
|
186
|
+
HTTPError: HTTP 请求错误 / HTTP request error
|
|
187
|
+
"""
|
|
188
|
+
agent_runtime_id = kwargs.get("agent_runtime_id")
|
|
189
|
+
if not agent_runtime_id:
|
|
190
|
+
raise ValueError(
|
|
191
|
+
"agent_runtime_id is required for listing endpoints"
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
return await cls.__get_client().list_endpoints_async(
|
|
195
|
+
agent_runtime_id,
|
|
196
|
+
AgentRuntimeEndpointListInput(
|
|
197
|
+
page_number=page_input.page_number,
|
|
198
|
+
page_size=page_input.page_size,
|
|
199
|
+
),
|
|
200
|
+
config=config,
|
|
201
|
+
)
|
|
202
|
+
|
|
163
203
|
@classmethod
|
|
164
204
|
async def list_by_id_async(
|
|
165
205
|
cls, agent_runtime_id: str, config: Optional[Config] = None
|
|
@@ -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
|
|
@@ -28,6 +28,7 @@ from agentrun.agent_runtime.model import (
|
|
|
28
28
|
AgentRuntimeEndpointUpdateInput,
|
|
29
29
|
)
|
|
30
30
|
from agentrun.utils.config import Config
|
|
31
|
+
from agentrun.utils.model import PageableInput
|
|
31
32
|
from agentrun.utils.resource import ResourceBase
|
|
32
33
|
|
|
33
34
|
|
|
@@ -286,6 +287,84 @@ class AgentRuntimeEndpoint(
|
|
|
286
287
|
config=config,
|
|
287
288
|
)
|
|
288
289
|
|
|
290
|
+
@classmethod
|
|
291
|
+
async def _list_page_async(
|
|
292
|
+
cls,
|
|
293
|
+
page_input: PageableInput,
|
|
294
|
+
config: Optional[Config] = None,
|
|
295
|
+
**kwargs,
|
|
296
|
+
) -> List["AgentRuntimeEndpoint"]:
|
|
297
|
+
"""分页列出端点 / List endpoints by page
|
|
298
|
+
|
|
299
|
+
此方法是 ResourceBase 要求实现的抽象方法,用于支持分页查询。
|
|
300
|
+
This method is an abstract method required by ResourceBase to support pagination.
|
|
301
|
+
|
|
302
|
+
Args:
|
|
303
|
+
page_input: 分页参数 / Pagination parameters
|
|
304
|
+
config: 配置对象,可选 / Configuration object, optional
|
|
305
|
+
**kwargs: 其他参数,必须包含 agent_runtime_id / Other parameters, must include agent_runtime_id
|
|
306
|
+
|
|
307
|
+
Returns:
|
|
308
|
+
List[AgentRuntimeEndpoint]: 端点对象列表 / List of endpoint objects
|
|
309
|
+
|
|
310
|
+
Raises:
|
|
311
|
+
ValueError: 当 agent_runtime_id 未提供时 / When agent_runtime_id is not provided
|
|
312
|
+
HTTPError: HTTP 请求错误 / HTTP request error
|
|
313
|
+
"""
|
|
314
|
+
agent_runtime_id = kwargs.get("agent_runtime_id")
|
|
315
|
+
if not agent_runtime_id:
|
|
316
|
+
raise ValueError(
|
|
317
|
+
"agent_runtime_id is required for listing endpoints"
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
return await cls.__get_client().list_endpoints_async(
|
|
321
|
+
agent_runtime_id,
|
|
322
|
+
AgentRuntimeEndpointListInput(
|
|
323
|
+
page_number=page_input.page_number,
|
|
324
|
+
page_size=page_input.page_size,
|
|
325
|
+
),
|
|
326
|
+
config=config,
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
@classmethod
|
|
330
|
+
def _list_page(
|
|
331
|
+
cls,
|
|
332
|
+
page_input: PageableInput,
|
|
333
|
+
config: Optional[Config] = None,
|
|
334
|
+
**kwargs,
|
|
335
|
+
) -> List["AgentRuntimeEndpoint"]:
|
|
336
|
+
"""分页列出端点 / List endpoints by page
|
|
337
|
+
|
|
338
|
+
此方法是 ResourceBase 要求实现的抽象方法,用于支持分页查询。
|
|
339
|
+
This method is an abstract method required by ResourceBase to support pagination.
|
|
340
|
+
|
|
341
|
+
Args:
|
|
342
|
+
page_input: 分页参数 / Pagination parameters
|
|
343
|
+
config: 配置对象,可选 / Configuration object, optional
|
|
344
|
+
**kwargs: 其他参数,必须包含 agent_runtime_id / Other parameters, must include agent_runtime_id
|
|
345
|
+
|
|
346
|
+
Returns:
|
|
347
|
+
List[AgentRuntimeEndpoint]: 端点对象列表 / List of endpoint objects
|
|
348
|
+
|
|
349
|
+
Raises:
|
|
350
|
+
ValueError: 当 agent_runtime_id 未提供时 / When agent_runtime_id is not provided
|
|
351
|
+
HTTPError: HTTP 请求错误 / HTTP request error
|
|
352
|
+
"""
|
|
353
|
+
agent_runtime_id = kwargs.get("agent_runtime_id")
|
|
354
|
+
if not agent_runtime_id:
|
|
355
|
+
raise ValueError(
|
|
356
|
+
"agent_runtime_id is required for listing endpoints"
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
return cls.__get_client().list_endpoints(
|
|
360
|
+
agent_runtime_id,
|
|
361
|
+
AgentRuntimeEndpointListInput(
|
|
362
|
+
page_number=page_input.page_number,
|
|
363
|
+
page_size=page_input.page_size,
|
|
364
|
+
),
|
|
365
|
+
config=config,
|
|
366
|
+
)
|
|
367
|
+
|
|
289
368
|
@classmethod
|
|
290
369
|
async def list_by_id_async(
|
|
291
370
|
cls, agent_runtime_id: str, config: Optional[Config] = None
|
|
@@ -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
|
+
)
|