agentrun-inner-test 0.0.62__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.
Potentially problematic release.
This version of agentrun-inner-test might be problematic. Click here for more details.
- agentrun/__init__.py +358 -0
- agentrun/agent_runtime/__client_async_template.py +466 -0
- agentrun/agent_runtime/__endpoint_async_template.py +345 -0
- agentrun/agent_runtime/__init__.py +53 -0
- agentrun/agent_runtime/__runtime_async_template.py +477 -0
- agentrun/agent_runtime/api/__data_async_template.py +58 -0
- agentrun/agent_runtime/api/__init__.py +6 -0
- agentrun/agent_runtime/api/control.py +1362 -0
- agentrun/agent_runtime/api/data.py +98 -0
- agentrun/agent_runtime/client.py +868 -0
- agentrun/agent_runtime/endpoint.py +649 -0
- agentrun/agent_runtime/model.py +362 -0
- agentrun/agent_runtime/runtime.py +904 -0
- agentrun/credential/__client_async_template.py +177 -0
- agentrun/credential/__credential_async_template.py +216 -0
- agentrun/credential/__init__.py +28 -0
- agentrun/credential/api/__init__.py +5 -0
- agentrun/credential/api/control.py +606 -0
- agentrun/credential/client.py +319 -0
- agentrun/credential/credential.py +381 -0
- agentrun/credential/model.py +248 -0
- agentrun/integration/__init__.py +21 -0
- agentrun/integration/agentscope/__init__.py +13 -0
- agentrun/integration/agentscope/adapter.py +17 -0
- agentrun/integration/agentscope/builtin.py +88 -0
- agentrun/integration/agentscope/message_adapter.py +185 -0
- agentrun/integration/agentscope/model_adapter.py +60 -0
- agentrun/integration/agentscope/tool_adapter.py +59 -0
- agentrun/integration/builtin/__init__.py +18 -0
- agentrun/integration/builtin/knowledgebase.py +137 -0
- agentrun/integration/builtin/model.py +93 -0
- agentrun/integration/builtin/sandbox.py +1234 -0
- agentrun/integration/builtin/toolset.py +47 -0
- agentrun/integration/crewai/__init__.py +13 -0
- agentrun/integration/crewai/adapter.py +9 -0
- agentrun/integration/crewai/builtin.py +88 -0
- agentrun/integration/crewai/model_adapter.py +31 -0
- agentrun/integration/crewai/tool_adapter.py +26 -0
- agentrun/integration/google_adk/__init__.py +13 -0
- agentrun/integration/google_adk/adapter.py +15 -0
- agentrun/integration/google_adk/builtin.py +88 -0
- agentrun/integration/google_adk/message_adapter.py +144 -0
- agentrun/integration/google_adk/model_adapter.py +46 -0
- agentrun/integration/google_adk/tool_adapter.py +235 -0
- agentrun/integration/langchain/__init__.py +31 -0
- agentrun/integration/langchain/adapter.py +15 -0
- agentrun/integration/langchain/builtin.py +94 -0
- agentrun/integration/langchain/message_adapter.py +141 -0
- agentrun/integration/langchain/model_adapter.py +37 -0
- agentrun/integration/langchain/tool_adapter.py +50 -0
- agentrun/integration/langgraph/__init__.py +36 -0
- agentrun/integration/langgraph/adapter.py +20 -0
- agentrun/integration/langgraph/agent_converter.py +1073 -0
- agentrun/integration/langgraph/builtin.py +88 -0
- agentrun/integration/pydantic_ai/__init__.py +13 -0
- agentrun/integration/pydantic_ai/adapter.py +13 -0
- agentrun/integration/pydantic_ai/builtin.py +88 -0
- agentrun/integration/pydantic_ai/model_adapter.py +44 -0
- agentrun/integration/pydantic_ai/tool_adapter.py +19 -0
- agentrun/integration/utils/__init__.py +112 -0
- agentrun/integration/utils/adapter.py +560 -0
- agentrun/integration/utils/canonical.py +164 -0
- agentrun/integration/utils/converter.py +134 -0
- agentrun/integration/utils/model.py +110 -0
- agentrun/integration/utils/tool.py +1759 -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/__client_async_template.py +357 -0
- agentrun/model/__init__.py +57 -0
- agentrun/model/__model_proxy_async_template.py +270 -0
- agentrun/model/__model_service_async_template.py +267 -0
- agentrun/model/api/__init__.py +6 -0
- agentrun/model/api/control.py +1173 -0
- agentrun/model/api/data.py +196 -0
- agentrun/model/client.py +674 -0
- agentrun/model/model.py +235 -0
- agentrun/model/model_proxy.py +439 -0
- agentrun/model/model_service.py +438 -0
- agentrun/sandbox/__aio_sandbox_async_template.py +523 -0
- agentrun/sandbox/__browser_sandbox_async_template.py +110 -0
- agentrun/sandbox/__client_async_template.py +491 -0
- agentrun/sandbox/__code_interpreter_sandbox_async_template.py +463 -0
- agentrun/sandbox/__init__.py +69 -0
- agentrun/sandbox/__sandbox_async_template.py +463 -0
- agentrun/sandbox/__template_async_template.py +152 -0
- agentrun/sandbox/aio_sandbox.py +912 -0
- agentrun/sandbox/api/__aio_data_async_template.py +335 -0
- agentrun/sandbox/api/__browser_data_async_template.py +140 -0
- agentrun/sandbox/api/__code_interpreter_data_async_template.py +206 -0
- agentrun/sandbox/api/__init__.py +19 -0
- agentrun/sandbox/api/__sandbox_data_async_template.py +107 -0
- agentrun/sandbox/api/aio_data.py +551 -0
- agentrun/sandbox/api/browser_data.py +172 -0
- agentrun/sandbox/api/code_interpreter_data.py +396 -0
- agentrun/sandbox/api/control.py +1051 -0
- agentrun/sandbox/api/playwright_async.py +492 -0
- agentrun/sandbox/api/playwright_sync.py +492 -0
- agentrun/sandbox/api/sandbox_data.py +154 -0
- agentrun/sandbox/browser_sandbox.py +185 -0
- agentrun/sandbox/client.py +925 -0
- agentrun/sandbox/code_interpreter_sandbox.py +823 -0
- agentrun/sandbox/model.py +384 -0
- agentrun/sandbox/sandbox.py +848 -0
- agentrun/sandbox/template.py +217 -0
- agentrun/server/__init__.py +191 -0
- agentrun/server/agui_normalizer.py +180 -0
- agentrun/server/agui_protocol.py +797 -0
- agentrun/server/invoker.py +309 -0
- agentrun/server/model.py +427 -0
- agentrun/server/openai_protocol.py +535 -0
- agentrun/server/protocol.py +140 -0
- agentrun/server/server.py +208 -0
- agentrun/toolset/__client_async_template.py +62 -0
- agentrun/toolset/__init__.py +51 -0
- agentrun/toolset/__toolset_async_template.py +204 -0
- agentrun/toolset/api/__init__.py +17 -0
- agentrun/toolset/api/control.py +262 -0
- agentrun/toolset/api/mcp.py +100 -0
- agentrun/toolset/api/openapi.py +1251 -0
- agentrun/toolset/client.py +102 -0
- agentrun/toolset/model.py +321 -0
- agentrun/toolset/toolset.py +271 -0
- agentrun/utils/__data_api_async_template.py +721 -0
- agentrun/utils/__init__.py +5 -0
- agentrun/utils/__resource_async_template.py +158 -0
- agentrun/utils/config.py +270 -0
- agentrun/utils/control_api.py +105 -0
- agentrun/utils/data_api.py +1121 -0
- agentrun/utils/exception.py +151 -0
- agentrun/utils/helper.py +108 -0
- agentrun/utils/log.py +77 -0
- agentrun/utils/model.py +168 -0
- agentrun/utils/resource.py +291 -0
- agentrun_inner_test-0.0.62.dist-info/METADATA +265 -0
- agentrun_inner_test-0.0.62.dist-info/RECORD +154 -0
- agentrun_inner_test-0.0.62.dist-info/WHEEL +5 -0
- agentrun_inner_test-0.0.62.dist-info/licenses/LICENSE +201 -0
- agentrun_inner_test-0.0.62.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This file is auto generated by the code generation script.
|
|
3
|
+
Do not modify this file manually.
|
|
4
|
+
Use the `make codegen` command to regenerate.
|
|
5
|
+
|
|
6
|
+
当前文件为自动生成的控制 API 客户端代码。请勿手动修改此文件。
|
|
7
|
+
使用 `make codegen` 命令重新生成。
|
|
8
|
+
|
|
9
|
+
source: agentrun/toolset/__client_async_template.py
|
|
10
|
+
|
|
11
|
+
ToolSet 客户端 / ToolSet Client
|
|
12
|
+
|
|
13
|
+
此模块提供工具集的客户端API。
|
|
14
|
+
This module provides the client API for toolsets.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from typing import Optional
|
|
18
|
+
|
|
19
|
+
from alibabacloud_devs20230714.models import ListToolsetsRequest
|
|
20
|
+
|
|
21
|
+
from agentrun.toolset.api.control import ToolControlAPI
|
|
22
|
+
from agentrun.toolset.model import ToolSetListInput
|
|
23
|
+
from agentrun.utils.config import Config
|
|
24
|
+
from agentrun.utils.exception import HTTPError
|
|
25
|
+
|
|
26
|
+
from .toolset import ToolSet
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ToolSetClient:
|
|
30
|
+
"""ToolSet 客户端 / ToolSet Client
|
|
31
|
+
|
|
32
|
+
提供工具集的获取和列表功能。
|
|
33
|
+
Provides get and list functions for toolsets.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __init__(self, config: Optional[Config] = None):
|
|
37
|
+
"""初始化客户端 / Initialize client
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
config: 配置对象,可选 / Configuration object, optional
|
|
41
|
+
"""
|
|
42
|
+
self.__control_api = ToolControlAPI(config)
|
|
43
|
+
|
|
44
|
+
async def get_async(
|
|
45
|
+
self,
|
|
46
|
+
name: str,
|
|
47
|
+
config: Optional[Config] = None,
|
|
48
|
+
):
|
|
49
|
+
try:
|
|
50
|
+
result = await self.__control_api.get_toolset_async(
|
|
51
|
+
name=name,
|
|
52
|
+
config=config,
|
|
53
|
+
)
|
|
54
|
+
except HTTPError as e:
|
|
55
|
+
raise e.to_resource_error("ToolSet", name) from e
|
|
56
|
+
|
|
57
|
+
return ToolSet.from_inner_object(result)
|
|
58
|
+
|
|
59
|
+
def get(
|
|
60
|
+
self,
|
|
61
|
+
name: str,
|
|
62
|
+
config: Optional[Config] = None,
|
|
63
|
+
):
|
|
64
|
+
try:
|
|
65
|
+
result = self.__control_api.get_toolset(
|
|
66
|
+
name=name,
|
|
67
|
+
config=config,
|
|
68
|
+
)
|
|
69
|
+
except HTTPError as e:
|
|
70
|
+
raise e.to_resource_error("ToolSet", name) from e
|
|
71
|
+
|
|
72
|
+
return ToolSet.from_inner_object(result)
|
|
73
|
+
|
|
74
|
+
async def list_async(
|
|
75
|
+
self,
|
|
76
|
+
input: Optional[ToolSetListInput] = None,
|
|
77
|
+
config: Optional[Config] = None,
|
|
78
|
+
):
|
|
79
|
+
if input is None:
|
|
80
|
+
input = ToolSetListInput()
|
|
81
|
+
|
|
82
|
+
result = await self.__control_api.list_toolsets_async(
|
|
83
|
+
input=ListToolsetsRequest().from_map(input.model_dump()),
|
|
84
|
+
config=config,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
return [ToolSet.from_inner_object(item) for item in result.data]
|
|
88
|
+
|
|
89
|
+
def list(
|
|
90
|
+
self,
|
|
91
|
+
input: Optional[ToolSetListInput] = None,
|
|
92
|
+
config: Optional[Config] = None,
|
|
93
|
+
):
|
|
94
|
+
if input is None:
|
|
95
|
+
input = ToolSetListInput()
|
|
96
|
+
|
|
97
|
+
result = self.__control_api.list_toolsets(
|
|
98
|
+
input=ListToolsetsRequest().from_map(input.model_dump()),
|
|
99
|
+
config=config,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
return [ToolSet.from_inner_object(item) for item in result.data]
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"""ToolSet 模型定义 / ToolSet Model Definitions
|
|
2
|
+
|
|
3
|
+
定义工具集相关的数据模型和枚举。
|
|
4
|
+
Defines data models and enumerations related to toolsets.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from typing import Any, Dict, List, Optional
|
|
9
|
+
|
|
10
|
+
from agentrun.utils.model import BaseModel, Field, PageableInput
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class SchemaType(str, Enum):
|
|
14
|
+
"""Schema 类型 / Schema Type"""
|
|
15
|
+
|
|
16
|
+
MCP = "MCP"
|
|
17
|
+
"""MCP 协议 / MCP Protocol"""
|
|
18
|
+
OpenAPI = "OpenAPI"
|
|
19
|
+
"""OpenAPI 规范 / OpenAPI Specification"""
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ToolSetStatusOutputsUrls(BaseModel):
|
|
23
|
+
internet_url: Optional[str] = None
|
|
24
|
+
intranet_url: Optional[str] = None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class MCPServerConfig(BaseModel):
|
|
28
|
+
headers: Optional[Dict[str, str]] = None
|
|
29
|
+
transport_type: Optional[str] = None
|
|
30
|
+
url: Optional[str] = None
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class ToolMeta(BaseModel):
|
|
34
|
+
description: Optional[str] = None
|
|
35
|
+
input_schema: Optional[Dict[str, Any]] = None
|
|
36
|
+
name: Optional[str] = None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class OpenAPIToolMeta(BaseModel):
|
|
40
|
+
method: Optional[str] = None
|
|
41
|
+
path: Optional[str] = None
|
|
42
|
+
tool_id: Optional[str] = None
|
|
43
|
+
tool_name: Optional[str] = None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class ToolSetStatusOutputs(BaseModel):
|
|
47
|
+
function_arn: Optional[str] = None
|
|
48
|
+
mcp_server_config: Optional[MCPServerConfig] = None
|
|
49
|
+
open_api_tools: Optional[List[OpenAPIToolMeta]] = None
|
|
50
|
+
tools: Optional[List[ToolMeta]] = None
|
|
51
|
+
urls: Optional[ToolSetStatusOutputsUrls] = None
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class APIKeyAuthParameter(BaseModel):
|
|
55
|
+
encrypted: Optional[bool] = None
|
|
56
|
+
in_: Optional[str] = None
|
|
57
|
+
key: Optional[str] = None
|
|
58
|
+
value: Optional[str] = None
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class AuthorizationParameters(BaseModel):
|
|
62
|
+
api_key_parameter: Optional[APIKeyAuthParameter] = None
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class Authorization(BaseModel):
|
|
66
|
+
parameters: Optional[AuthorizationParameters] = None
|
|
67
|
+
type: Optional[str] = None
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class ToolSetSchema(BaseModel):
|
|
71
|
+
detail: Optional[str] = None
|
|
72
|
+
type: Optional[SchemaType] = None
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class ToolSetSpec(BaseModel):
|
|
76
|
+
auth_config: Optional[Authorization] = None
|
|
77
|
+
tool_schema: Optional[ToolSetSchema] = Field(alias="schema", default=None)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class ToolSetStatus(BaseModel):
|
|
81
|
+
observed_generation: Optional[int] = None
|
|
82
|
+
observed_time: Optional[str] = None
|
|
83
|
+
outputs: Optional[ToolSetStatusOutputs] = None
|
|
84
|
+
phase: Optional[str] = None
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class ToolSetListInput(PageableInput):
|
|
88
|
+
keyword: Optional[str] = None
|
|
89
|
+
label_selector: Optional[List[str]] = None
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class ToolSchema(BaseModel):
|
|
93
|
+
"""JSON Schema 兼容的工具参数描述
|
|
94
|
+
|
|
95
|
+
支持完整的 JSON Schema 字段,能够描述复杂的嵌套数据结构。
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
# 基本字段
|
|
99
|
+
type: Optional[str] = None
|
|
100
|
+
description: Optional[str] = None
|
|
101
|
+
title: Optional[str] = None
|
|
102
|
+
|
|
103
|
+
# 对象类型字段
|
|
104
|
+
properties: Optional[Dict[str, "ToolSchema"]] = None
|
|
105
|
+
required: Optional[List[str]] = None
|
|
106
|
+
additional_properties: Optional[bool] = None
|
|
107
|
+
|
|
108
|
+
# 数组类型字段
|
|
109
|
+
items: Optional["ToolSchema"] = None
|
|
110
|
+
min_items: Optional[int] = None
|
|
111
|
+
max_items: Optional[int] = None
|
|
112
|
+
|
|
113
|
+
# 字符串类型字段
|
|
114
|
+
pattern: Optional[str] = None
|
|
115
|
+
min_length: Optional[int] = None
|
|
116
|
+
max_length: Optional[int] = None
|
|
117
|
+
format: Optional[str] = None # date, date-time, email, uri 等
|
|
118
|
+
enum: Optional[List[Any]] = None
|
|
119
|
+
|
|
120
|
+
# 数值类型字段
|
|
121
|
+
minimum: Optional[float] = None
|
|
122
|
+
maximum: Optional[float] = None
|
|
123
|
+
exclusive_minimum: Optional[float] = None
|
|
124
|
+
exclusive_maximum: Optional[float] = None
|
|
125
|
+
|
|
126
|
+
# 联合类型
|
|
127
|
+
any_of: Optional[List["ToolSchema"]] = None
|
|
128
|
+
one_of: Optional[List["ToolSchema"]] = None
|
|
129
|
+
all_of: Optional[List["ToolSchema"]] = None
|
|
130
|
+
|
|
131
|
+
# 默认值
|
|
132
|
+
default: Optional[Any] = None
|
|
133
|
+
|
|
134
|
+
@classmethod
|
|
135
|
+
def from_any_openapi_schema(cls, schema: Any) -> "ToolSchema":
|
|
136
|
+
"""从任意 OpenAPI/JSON Schema 创建 ToolSchema
|
|
137
|
+
|
|
138
|
+
递归解析所有嵌套结构,保留完整的 schema 信息。
|
|
139
|
+
"""
|
|
140
|
+
if not schema or not isinstance(schema, dict):
|
|
141
|
+
return cls(type="string")
|
|
142
|
+
|
|
143
|
+
from pydash import get as pg
|
|
144
|
+
|
|
145
|
+
# 解析 properties
|
|
146
|
+
properties_raw = pg(schema, "properties", {})
|
|
147
|
+
properties = (
|
|
148
|
+
{
|
|
149
|
+
key: cls.from_any_openapi_schema(value)
|
|
150
|
+
for key, value in properties_raw.items()
|
|
151
|
+
}
|
|
152
|
+
if properties_raw
|
|
153
|
+
else None
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
# 解析 items
|
|
157
|
+
items_raw = pg(schema, "items")
|
|
158
|
+
items = cls.from_any_openapi_schema(items_raw) if items_raw else None
|
|
159
|
+
|
|
160
|
+
# 解析联合类型
|
|
161
|
+
any_of_raw = pg(schema, "anyOf")
|
|
162
|
+
any_of = (
|
|
163
|
+
[cls.from_any_openapi_schema(s) for s in any_of_raw]
|
|
164
|
+
if any_of_raw
|
|
165
|
+
else None
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
one_of_raw = pg(schema, "oneOf")
|
|
169
|
+
one_of = (
|
|
170
|
+
[cls.from_any_openapi_schema(s) for s in one_of_raw]
|
|
171
|
+
if one_of_raw
|
|
172
|
+
else None
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
all_of_raw = pg(schema, "allOf")
|
|
176
|
+
all_of = (
|
|
177
|
+
[cls.from_any_openapi_schema(s) for s in all_of_raw]
|
|
178
|
+
if all_of_raw
|
|
179
|
+
else None
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
return cls(
|
|
183
|
+
# 基本字段
|
|
184
|
+
type=pg(schema, "type"),
|
|
185
|
+
description=pg(schema, "description"),
|
|
186
|
+
title=pg(schema, "title"),
|
|
187
|
+
# 对象类型
|
|
188
|
+
properties=properties,
|
|
189
|
+
required=pg(schema, "required"),
|
|
190
|
+
additional_properties=pg(schema, "additionalProperties"),
|
|
191
|
+
# 数组类型
|
|
192
|
+
items=items,
|
|
193
|
+
min_items=pg(schema, "minItems"),
|
|
194
|
+
max_items=pg(schema, "maxItems"),
|
|
195
|
+
# 字符串类型
|
|
196
|
+
pattern=pg(schema, "pattern"),
|
|
197
|
+
min_length=pg(schema, "minLength"),
|
|
198
|
+
max_length=pg(schema, "maxLength"),
|
|
199
|
+
format=pg(schema, "format"),
|
|
200
|
+
enum=pg(schema, "enum"),
|
|
201
|
+
# 数值类型
|
|
202
|
+
minimum=pg(schema, "minimum"),
|
|
203
|
+
maximum=pg(schema, "maximum"),
|
|
204
|
+
exclusive_minimum=pg(schema, "exclusiveMinimum"),
|
|
205
|
+
exclusive_maximum=pg(schema, "exclusiveMaximum"),
|
|
206
|
+
# 联合类型
|
|
207
|
+
any_of=any_of,
|
|
208
|
+
one_of=one_of,
|
|
209
|
+
all_of=all_of,
|
|
210
|
+
# 默认值
|
|
211
|
+
default=pg(schema, "default"),
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
def to_json_schema(self) -> Dict[str, Any]:
|
|
215
|
+
"""转换为标准 JSON Schema 格式"""
|
|
216
|
+
result: Dict[str, Any] = {}
|
|
217
|
+
|
|
218
|
+
# 基本字段
|
|
219
|
+
if self.type:
|
|
220
|
+
result["type"] = self.type
|
|
221
|
+
if self.description:
|
|
222
|
+
result["description"] = self.description
|
|
223
|
+
if self.title:
|
|
224
|
+
result["title"] = self.title
|
|
225
|
+
|
|
226
|
+
# 对象类型
|
|
227
|
+
if self.properties:
|
|
228
|
+
result["properties"] = {
|
|
229
|
+
k: v.to_json_schema() for k, v in self.properties.items()
|
|
230
|
+
}
|
|
231
|
+
if self.required:
|
|
232
|
+
result["required"] = self.required
|
|
233
|
+
if self.additional_properties is not None:
|
|
234
|
+
result["additionalProperties"] = self.additional_properties
|
|
235
|
+
|
|
236
|
+
# 数组类型
|
|
237
|
+
if self.items:
|
|
238
|
+
result["items"] = self.items.to_json_schema()
|
|
239
|
+
if self.min_items is not None:
|
|
240
|
+
result["minItems"] = self.min_items
|
|
241
|
+
if self.max_items is not None:
|
|
242
|
+
result["maxItems"] = self.max_items
|
|
243
|
+
|
|
244
|
+
# 字符串类型
|
|
245
|
+
if self.pattern:
|
|
246
|
+
result["pattern"] = self.pattern
|
|
247
|
+
if self.min_length is not None:
|
|
248
|
+
result["minLength"] = self.min_length
|
|
249
|
+
if self.max_length is not None:
|
|
250
|
+
result["maxLength"] = self.max_length
|
|
251
|
+
if self.format:
|
|
252
|
+
result["format"] = self.format
|
|
253
|
+
if self.enum:
|
|
254
|
+
result["enum"] = self.enum
|
|
255
|
+
|
|
256
|
+
# 数值类型
|
|
257
|
+
if self.minimum is not None:
|
|
258
|
+
result["minimum"] = self.minimum
|
|
259
|
+
if self.maximum is not None:
|
|
260
|
+
result["maximum"] = self.maximum
|
|
261
|
+
if self.exclusive_minimum is not None:
|
|
262
|
+
result["exclusiveMinimum"] = self.exclusive_minimum
|
|
263
|
+
if self.exclusive_maximum is not None:
|
|
264
|
+
result["exclusiveMaximum"] = self.exclusive_maximum
|
|
265
|
+
|
|
266
|
+
# 联合类型
|
|
267
|
+
if self.any_of:
|
|
268
|
+
result["anyOf"] = [s.to_json_schema() for s in self.any_of]
|
|
269
|
+
if self.one_of:
|
|
270
|
+
result["oneOf"] = [s.to_json_schema() for s in self.one_of]
|
|
271
|
+
if self.all_of:
|
|
272
|
+
result["allOf"] = [s.to_json_schema() for s in self.all_of]
|
|
273
|
+
|
|
274
|
+
# 默认值
|
|
275
|
+
if self.default is not None:
|
|
276
|
+
result["default"] = self.default
|
|
277
|
+
|
|
278
|
+
return result
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
class ToolInfo(BaseModel):
|
|
282
|
+
name: Optional[str] = None
|
|
283
|
+
description: Optional[str] = None
|
|
284
|
+
parameters: Optional[ToolSchema] = None
|
|
285
|
+
|
|
286
|
+
@classmethod
|
|
287
|
+
def from_mcp_tool(cls, tool: Any):
|
|
288
|
+
"""从 MCP tool 创建 ToolInfo"""
|
|
289
|
+
if hasattr(tool, "name"):
|
|
290
|
+
# MCP Tool 对象
|
|
291
|
+
tool_name = tool.name
|
|
292
|
+
tool_description = getattr(tool, "description", None)
|
|
293
|
+
input_schema = getattr(tool, "inputSchema", None) or getattr(
|
|
294
|
+
tool, "input_schema", None
|
|
295
|
+
)
|
|
296
|
+
elif isinstance(tool, dict):
|
|
297
|
+
# 字典格式
|
|
298
|
+
tool_name = tool.get("name")
|
|
299
|
+
tool_description = tool.get("description")
|
|
300
|
+
input_schema = tool.get("inputSchema") or tool.get("input_schema")
|
|
301
|
+
else:
|
|
302
|
+
raise ValueError(f"Unsupported MCP tool format: {type(tool)}")
|
|
303
|
+
|
|
304
|
+
if not tool_name:
|
|
305
|
+
raise ValueError("MCP tool must have a name")
|
|
306
|
+
|
|
307
|
+
# 构建 parameters schema
|
|
308
|
+
parameters = None
|
|
309
|
+
if input_schema:
|
|
310
|
+
if isinstance(input_schema, dict):
|
|
311
|
+
parameters = ToolSchema.from_any_openapi_schema(input_schema)
|
|
312
|
+
elif hasattr(input_schema, "model_dump"):
|
|
313
|
+
parameters = ToolSchema.from_any_openapi_schema(
|
|
314
|
+
input_schema.model_dump()
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
return cls(
|
|
318
|
+
name=tool_name,
|
|
319
|
+
description=tool_description,
|
|
320
|
+
parameters=parameters or ToolSchema(type="object", properties={}),
|
|
321
|
+
)
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This file is auto generated by the code generation script.
|
|
3
|
+
Do not modify this file manually.
|
|
4
|
+
Use the `make codegen` command to regenerate.
|
|
5
|
+
|
|
6
|
+
当前文件为自动生成的控制 API 客户端代码。请勿手动修改此文件。
|
|
7
|
+
使用 `make codegen` 命令重新生成。
|
|
8
|
+
|
|
9
|
+
source: agentrun/toolset/__toolset_async_template.py
|
|
10
|
+
|
|
11
|
+
ToolSet 资源类 / ToolSet Resource Class
|
|
12
|
+
|
|
13
|
+
提供工具集资源的面向对象封装和完整生命周期管理。
|
|
14
|
+
Provides object-oriented wrapper and complete lifecycle management for toolset resources.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from typing import Any, Dict, Optional, Tuple
|
|
18
|
+
|
|
19
|
+
import pydash
|
|
20
|
+
|
|
21
|
+
from agentrun.utils.config import Config
|
|
22
|
+
from agentrun.utils.log import logger
|
|
23
|
+
from agentrun.utils.model import BaseModel
|
|
24
|
+
|
|
25
|
+
from .api.openapi import OpenAPI
|
|
26
|
+
from .model import (
|
|
27
|
+
MCPServerConfig,
|
|
28
|
+
SchemaType,
|
|
29
|
+
ToolInfo,
|
|
30
|
+
ToolSetSpec,
|
|
31
|
+
ToolSetStatus,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ToolSet(BaseModel):
|
|
36
|
+
"""工具集资源 / ToolSet Resource
|
|
37
|
+
|
|
38
|
+
提供工具集的查询、调用等功能。
|
|
39
|
+
Provides query, invocation and other functionality for toolsets.
|
|
40
|
+
|
|
41
|
+
Attributes:
|
|
42
|
+
created_time: 创建时间 / Creation time
|
|
43
|
+
description: 描述 / Description
|
|
44
|
+
generation: 版本号 / Generation number
|
|
45
|
+
kind: 资源类型 / Resource kind
|
|
46
|
+
labels: 标签 / Labels
|
|
47
|
+
name: 工具集名称 / ToolSet name
|
|
48
|
+
spec: 规格配置 / Specification
|
|
49
|
+
status: 状态 / Status
|
|
50
|
+
uid: 唯一标识符 / Unique identifier
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
created_time: Optional[str] = None
|
|
54
|
+
description: Optional[str] = None
|
|
55
|
+
generation: Optional[int] = None
|
|
56
|
+
kind: Optional[str] = None
|
|
57
|
+
labels: Optional[Dict[str, str]] = None
|
|
58
|
+
name: Optional[str] = None
|
|
59
|
+
spec: Optional[ToolSetSpec] = None
|
|
60
|
+
status: Optional[ToolSetStatus] = None
|
|
61
|
+
uid: Optional[str] = None
|
|
62
|
+
|
|
63
|
+
@classmethod
|
|
64
|
+
def __get_client(cls, config: Optional[Config] = None):
|
|
65
|
+
from .client import ToolSetClient
|
|
66
|
+
|
|
67
|
+
return ToolSetClient(config)
|
|
68
|
+
|
|
69
|
+
@classmethod
|
|
70
|
+
async def get_by_name_async(
|
|
71
|
+
cls, name: str, config: Optional[Config] = None
|
|
72
|
+
):
|
|
73
|
+
cli = cls.__get_client(config)
|
|
74
|
+
return await cli.get_async(name=name)
|
|
75
|
+
|
|
76
|
+
@classmethod
|
|
77
|
+
def get_by_name(cls, name: str, config: Optional[Config] = None):
|
|
78
|
+
cli = cls.__get_client(config)
|
|
79
|
+
return cli.get(name=name)
|
|
80
|
+
|
|
81
|
+
def type(self):
|
|
82
|
+
return SchemaType(pydash.get(self, "spec.tool_schema.type", ""))
|
|
83
|
+
|
|
84
|
+
def _get_openapi_auth_defaults(
|
|
85
|
+
self,
|
|
86
|
+
) -> Tuple[Dict[str, Any], Dict[str, Any]]:
|
|
87
|
+
headers: Dict[str, Any] = {}
|
|
88
|
+
query: Dict[str, Any] = {}
|
|
89
|
+
|
|
90
|
+
auth_config = pydash.get(self, "spec.auth_config", None)
|
|
91
|
+
auth_type = getattr(auth_config, "type", None) if auth_config else None
|
|
92
|
+
|
|
93
|
+
if auth_type == "APIKey":
|
|
94
|
+
api_key_param = pydash.get(
|
|
95
|
+
auth_config,
|
|
96
|
+
"parameters.api_key_parameter",
|
|
97
|
+
None,
|
|
98
|
+
)
|
|
99
|
+
if api_key_param:
|
|
100
|
+
key = getattr(api_key_param, "key", None)
|
|
101
|
+
value = getattr(api_key_param, "value", None)
|
|
102
|
+
location = getattr(api_key_param, "in_", None)
|
|
103
|
+
if key and value is not None:
|
|
104
|
+
if location == "header":
|
|
105
|
+
headers[key] = value
|
|
106
|
+
elif location == "query":
|
|
107
|
+
query[key] = value
|
|
108
|
+
|
|
109
|
+
return headers, query
|
|
110
|
+
|
|
111
|
+
def _get_openapi_base_url(self) -> Optional[str]:
|
|
112
|
+
return pydash.get(
|
|
113
|
+
self,
|
|
114
|
+
"status.outputs.urls.intranet_url",
|
|
115
|
+
None,
|
|
116
|
+
) or pydash.get(self, "status.outputs.urls.internet_url", None)
|
|
117
|
+
|
|
118
|
+
async def get_async(self, config: Optional[Config] = None):
|
|
119
|
+
if self.name is None:
|
|
120
|
+
raise ValueError("ToolSet name is required to get the ToolSet.")
|
|
121
|
+
|
|
122
|
+
result = await self.get_by_name_async(name=self.name, config=config)
|
|
123
|
+
return self.update_self(result)
|
|
124
|
+
|
|
125
|
+
def get(self, config: Optional[Config] = None):
|
|
126
|
+
if self.name is None:
|
|
127
|
+
raise ValueError("ToolSet name is required to get the ToolSet.")
|
|
128
|
+
|
|
129
|
+
result = self.get_by_name(name=self.name, config=config)
|
|
130
|
+
return self.update_self(result)
|
|
131
|
+
|
|
132
|
+
async def list_tools_async(self, config: Optional[Config] = None):
|
|
133
|
+
"""异步获取工具列表,返回统一的 ToolInfo 列表"""
|
|
134
|
+
if self.type() == SchemaType.MCP:
|
|
135
|
+
mcp_tools = pydash.get(self, "status.outputs.tools", [])
|
|
136
|
+
return [ToolInfo.from_mcp_tool(tool) for tool in mcp_tools]
|
|
137
|
+
elif self.type() == SchemaType.OpenAPI:
|
|
138
|
+
# 直接使用 to_apiset 转换
|
|
139
|
+
apiset = self.to_apiset(config=config)
|
|
140
|
+
return apiset.tools()
|
|
141
|
+
return []
|
|
142
|
+
|
|
143
|
+
def list_tools(self, config: Optional[Config] = None):
|
|
144
|
+
"""同步获取工具列表,返回统一的 ToolInfo 列表"""
|
|
145
|
+
if self.type() == SchemaType.MCP:
|
|
146
|
+
mcp_tools = pydash.get(self, "status.outputs.tools", [])
|
|
147
|
+
return [ToolInfo.from_mcp_tool(tool) for tool in mcp_tools]
|
|
148
|
+
elif self.type() == SchemaType.OpenAPI:
|
|
149
|
+
# 直接使用 to_apiset 转换
|
|
150
|
+
apiset = self.to_apiset(config=config)
|
|
151
|
+
return apiset.tools()
|
|
152
|
+
return []
|
|
153
|
+
|
|
154
|
+
async def call_tool_async(
|
|
155
|
+
self,
|
|
156
|
+
name: str,
|
|
157
|
+
arguments: Optional[Dict[str, str]] = None,
|
|
158
|
+
config: Optional[Config] = None,
|
|
159
|
+
):
|
|
160
|
+
"""异步调用工具,统一使用 ApiSet 实现"""
|
|
161
|
+
apiset = self.to_apiset(config=config)
|
|
162
|
+
|
|
163
|
+
# 对于 OpenAPI,可能需要解析 operation name
|
|
164
|
+
if self.type() == SchemaType.OpenAPI:
|
|
165
|
+
# 尝试查找实际的 operation name
|
|
166
|
+
tool = apiset.get_tool(name)
|
|
167
|
+
if tool is None:
|
|
168
|
+
# 尝试通过 tool_id 映射查找
|
|
169
|
+
openapi_tools = (
|
|
170
|
+
pydash.get(self, "status.outputs.open_api_tools", []) or []
|
|
171
|
+
)
|
|
172
|
+
for tool_meta in openapi_tools:
|
|
173
|
+
if tool_meta is None:
|
|
174
|
+
continue
|
|
175
|
+
if hasattr(tool_meta, "model_dump"):
|
|
176
|
+
tool_meta = tool_meta.model_dump()
|
|
177
|
+
if not isinstance(tool_meta, dict):
|
|
178
|
+
continue
|
|
179
|
+
if tool_meta.get("tool_id") == name:
|
|
180
|
+
name = tool_meta.get("tool_name") or name
|
|
181
|
+
break
|
|
182
|
+
|
|
183
|
+
logger.debug("invoke tool %s with arguments %s", name, arguments)
|
|
184
|
+
result = await apiset.invoke_async(
|
|
185
|
+
name=name, arguments=arguments, config=config
|
|
186
|
+
)
|
|
187
|
+
logger.debug("invoke tool %s got result %s", name, result)
|
|
188
|
+
return result
|
|
189
|
+
|
|
190
|
+
def call_tool(
|
|
191
|
+
self,
|
|
192
|
+
name: str,
|
|
193
|
+
arguments: Optional[Dict[str, str]] = None,
|
|
194
|
+
config: Optional[Config] = None,
|
|
195
|
+
):
|
|
196
|
+
"""同步调用工具,统一使用 ApiSet 实现"""
|
|
197
|
+
apiset = self.to_apiset(config=config)
|
|
198
|
+
|
|
199
|
+
# 对于 OpenAPI,可能需要解析 operation name
|
|
200
|
+
if self.type() == SchemaType.OpenAPI:
|
|
201
|
+
# 尝试查找实际的 operation name
|
|
202
|
+
tool = apiset.get_tool(name)
|
|
203
|
+
if tool is None:
|
|
204
|
+
# 尝试通过 tool_id 映射查找
|
|
205
|
+
openapi_tools = (
|
|
206
|
+
pydash.get(self, "status.outputs.open_api_tools", []) or []
|
|
207
|
+
)
|
|
208
|
+
for tool_meta in openapi_tools:
|
|
209
|
+
if tool_meta is None:
|
|
210
|
+
continue
|
|
211
|
+
if hasattr(tool_meta, "model_dump"):
|
|
212
|
+
tool_meta = tool_meta.model_dump()
|
|
213
|
+
if not isinstance(tool_meta, dict):
|
|
214
|
+
continue
|
|
215
|
+
if tool_meta.get("tool_id") == name:
|
|
216
|
+
name = tool_meta.get("tool_name") or name
|
|
217
|
+
break
|
|
218
|
+
|
|
219
|
+
logger.debug("invoke tool %s with arguments %s", name, arguments)
|
|
220
|
+
result = apiset.invoke(name=name, arguments=arguments, config=config)
|
|
221
|
+
logger.debug("invoke tool %s got result %s", name, result)
|
|
222
|
+
return result
|
|
223
|
+
|
|
224
|
+
def to_apiset(self, config: Optional[Config] = None):
|
|
225
|
+
"""将 ToolSet 转换为统一的 ApiSet 对象
|
|
226
|
+
|
|
227
|
+
Returns:
|
|
228
|
+
ApiSet: 统一的工具集接口
|
|
229
|
+
"""
|
|
230
|
+
from .api.openapi import ApiSet
|
|
231
|
+
|
|
232
|
+
if self.type() == SchemaType.MCP:
|
|
233
|
+
from .api.mcp import MCPToolSet
|
|
234
|
+
|
|
235
|
+
mcp_server_config: MCPServerConfig = pydash.get(
|
|
236
|
+
self, "status.outputs.mcp_server_config", None
|
|
237
|
+
)
|
|
238
|
+
assert (
|
|
239
|
+
mcp_server_config.url is not None
|
|
240
|
+
), "MCP server URL is missing."
|
|
241
|
+
|
|
242
|
+
cfg = Config.with_configs(
|
|
243
|
+
config, Config(headers=mcp_server_config.headers)
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
mcp_client = MCPToolSet(
|
|
247
|
+
url=mcp_server_config.url,
|
|
248
|
+
config=cfg,
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
# 获取 MCP tools
|
|
252
|
+
mcp_tools = pydash.get(self, "status.outputs.tools", [])
|
|
253
|
+
|
|
254
|
+
return ApiSet.from_mcp_tools(
|
|
255
|
+
tools=mcp_tools,
|
|
256
|
+
mcp_client=mcp_client,
|
|
257
|
+
config=cfg,
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
elif self.type() == SchemaType.OpenAPI:
|
|
261
|
+
headers, query = self._get_openapi_auth_defaults()
|
|
262
|
+
|
|
263
|
+
return ApiSet.from_openapi_schema(
|
|
264
|
+
schema=pydash.get(self, "spec.tool_schema.detail", None),
|
|
265
|
+
base_url=self._get_openapi_base_url(),
|
|
266
|
+
headers=headers,
|
|
267
|
+
query_params=query,
|
|
268
|
+
config=config,
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
raise ValueError(f"Unsupported ToolSet type: {self.type()}")
|