agentrun-inner-test 0.0.46__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.
Files changed (135) hide show
  1. agentrun/__init__.py +325 -0
  2. agentrun/agent_runtime/__client_async_template.py +466 -0
  3. agentrun/agent_runtime/__endpoint_async_template.py +345 -0
  4. agentrun/agent_runtime/__init__.py +53 -0
  5. agentrun/agent_runtime/__runtime_async_template.py +477 -0
  6. agentrun/agent_runtime/api/__data_async_template.py +58 -0
  7. agentrun/agent_runtime/api/__init__.py +6 -0
  8. agentrun/agent_runtime/api/control.py +1362 -0
  9. agentrun/agent_runtime/api/data.py +98 -0
  10. agentrun/agent_runtime/client.py +868 -0
  11. agentrun/agent_runtime/endpoint.py +649 -0
  12. agentrun/agent_runtime/model.py +362 -0
  13. agentrun/agent_runtime/runtime.py +904 -0
  14. agentrun/credential/__client_async_template.py +177 -0
  15. agentrun/credential/__credential_async_template.py +216 -0
  16. agentrun/credential/__init__.py +28 -0
  17. agentrun/credential/api/__init__.py +5 -0
  18. agentrun/credential/api/control.py +606 -0
  19. agentrun/credential/client.py +319 -0
  20. agentrun/credential/credential.py +381 -0
  21. agentrun/credential/model.py +248 -0
  22. agentrun/integration/__init__.py +21 -0
  23. agentrun/integration/agentscope/__init__.py +12 -0
  24. agentrun/integration/agentscope/adapter.py +17 -0
  25. agentrun/integration/agentscope/builtin.py +65 -0
  26. agentrun/integration/agentscope/message_adapter.py +185 -0
  27. agentrun/integration/agentscope/model_adapter.py +60 -0
  28. agentrun/integration/agentscope/tool_adapter.py +59 -0
  29. agentrun/integration/builtin/__init__.py +16 -0
  30. agentrun/integration/builtin/model.py +93 -0
  31. agentrun/integration/builtin/sandbox.py +1234 -0
  32. agentrun/integration/builtin/toolset.py +47 -0
  33. agentrun/integration/crewai/__init__.py +12 -0
  34. agentrun/integration/crewai/adapter.py +9 -0
  35. agentrun/integration/crewai/builtin.py +65 -0
  36. agentrun/integration/crewai/model_adapter.py +31 -0
  37. agentrun/integration/crewai/tool_adapter.py +26 -0
  38. agentrun/integration/google_adk/__init__.py +12 -0
  39. agentrun/integration/google_adk/adapter.py +15 -0
  40. agentrun/integration/google_adk/builtin.py +65 -0
  41. agentrun/integration/google_adk/message_adapter.py +144 -0
  42. agentrun/integration/google_adk/model_adapter.py +46 -0
  43. agentrun/integration/google_adk/tool_adapter.py +235 -0
  44. agentrun/integration/langchain/__init__.py +30 -0
  45. agentrun/integration/langchain/adapter.py +15 -0
  46. agentrun/integration/langchain/builtin.py +71 -0
  47. agentrun/integration/langchain/message_adapter.py +141 -0
  48. agentrun/integration/langchain/model_adapter.py +37 -0
  49. agentrun/integration/langchain/tool_adapter.py +50 -0
  50. agentrun/integration/langgraph/__init__.py +35 -0
  51. agentrun/integration/langgraph/adapter.py +20 -0
  52. agentrun/integration/langgraph/agent_converter.py +1073 -0
  53. agentrun/integration/langgraph/builtin.py +65 -0
  54. agentrun/integration/pydantic_ai/__init__.py +12 -0
  55. agentrun/integration/pydantic_ai/adapter.py +13 -0
  56. agentrun/integration/pydantic_ai/builtin.py +65 -0
  57. agentrun/integration/pydantic_ai/model_adapter.py +44 -0
  58. agentrun/integration/pydantic_ai/tool_adapter.py +19 -0
  59. agentrun/integration/utils/__init__.py +112 -0
  60. agentrun/integration/utils/adapter.py +560 -0
  61. agentrun/integration/utils/canonical.py +164 -0
  62. agentrun/integration/utils/converter.py +134 -0
  63. agentrun/integration/utils/model.py +110 -0
  64. agentrun/integration/utils/tool.py +1759 -0
  65. agentrun/model/__client_async_template.py +357 -0
  66. agentrun/model/__init__.py +57 -0
  67. agentrun/model/__model_proxy_async_template.py +270 -0
  68. agentrun/model/__model_service_async_template.py +267 -0
  69. agentrun/model/api/__init__.py +6 -0
  70. agentrun/model/api/control.py +1173 -0
  71. agentrun/model/api/data.py +196 -0
  72. agentrun/model/client.py +674 -0
  73. agentrun/model/model.py +235 -0
  74. agentrun/model/model_proxy.py +439 -0
  75. agentrun/model/model_service.py +438 -0
  76. agentrun/sandbox/__aio_sandbox_async_template.py +523 -0
  77. agentrun/sandbox/__browser_sandbox_async_template.py +110 -0
  78. agentrun/sandbox/__client_async_template.py +491 -0
  79. agentrun/sandbox/__code_interpreter_sandbox_async_template.py +463 -0
  80. agentrun/sandbox/__init__.py +69 -0
  81. agentrun/sandbox/__sandbox_async_template.py +463 -0
  82. agentrun/sandbox/__template_async_template.py +152 -0
  83. agentrun/sandbox/aio_sandbox.py +905 -0
  84. agentrun/sandbox/api/__aio_data_async_template.py +335 -0
  85. agentrun/sandbox/api/__browser_data_async_template.py +140 -0
  86. agentrun/sandbox/api/__code_interpreter_data_async_template.py +206 -0
  87. agentrun/sandbox/api/__init__.py +19 -0
  88. agentrun/sandbox/api/__sandbox_data_async_template.py +107 -0
  89. agentrun/sandbox/api/aio_data.py +551 -0
  90. agentrun/sandbox/api/browser_data.py +172 -0
  91. agentrun/sandbox/api/code_interpreter_data.py +396 -0
  92. agentrun/sandbox/api/control.py +1051 -0
  93. agentrun/sandbox/api/playwright_async.py +492 -0
  94. agentrun/sandbox/api/playwright_sync.py +492 -0
  95. agentrun/sandbox/api/sandbox_data.py +154 -0
  96. agentrun/sandbox/browser_sandbox.py +185 -0
  97. agentrun/sandbox/client.py +925 -0
  98. agentrun/sandbox/code_interpreter_sandbox.py +823 -0
  99. agentrun/sandbox/model.py +397 -0
  100. agentrun/sandbox/sandbox.py +848 -0
  101. agentrun/sandbox/template.py +217 -0
  102. agentrun/server/__init__.py +191 -0
  103. agentrun/server/agui_normalizer.py +180 -0
  104. agentrun/server/agui_protocol.py +797 -0
  105. agentrun/server/invoker.py +309 -0
  106. agentrun/server/model.py +427 -0
  107. agentrun/server/openai_protocol.py +535 -0
  108. agentrun/server/protocol.py +140 -0
  109. agentrun/server/server.py +208 -0
  110. agentrun/toolset/__client_async_template.py +62 -0
  111. agentrun/toolset/__init__.py +51 -0
  112. agentrun/toolset/__toolset_async_template.py +204 -0
  113. agentrun/toolset/api/__init__.py +17 -0
  114. agentrun/toolset/api/control.py +262 -0
  115. agentrun/toolset/api/mcp.py +100 -0
  116. agentrun/toolset/api/openapi.py +1251 -0
  117. agentrun/toolset/client.py +102 -0
  118. agentrun/toolset/model.py +321 -0
  119. agentrun/toolset/toolset.py +270 -0
  120. agentrun/utils/__data_api_async_template.py +720 -0
  121. agentrun/utils/__init__.py +5 -0
  122. agentrun/utils/__resource_async_template.py +158 -0
  123. agentrun/utils/config.py +258 -0
  124. agentrun/utils/control_api.py +78 -0
  125. agentrun/utils/data_api.py +1120 -0
  126. agentrun/utils/exception.py +151 -0
  127. agentrun/utils/helper.py +108 -0
  128. agentrun/utils/log.py +77 -0
  129. agentrun/utils/model.py +168 -0
  130. agentrun/utils/resource.py +291 -0
  131. agentrun_inner_test-0.0.46.dist-info/METADATA +263 -0
  132. agentrun_inner_test-0.0.46.dist-info/RECORD +135 -0
  133. agentrun_inner_test-0.0.46.dist-info/WHEEL +5 -0
  134. agentrun_inner_test-0.0.46.dist-info/licenses/LICENSE +201 -0
  135. agentrun_inner_test-0.0.46.dist-info/top_level.txt +1 -0
@@ -0,0 +1,262 @@
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: codegen/configs/toolset_control_api.yaml
10
+
11
+
12
+ Tool 管控链路 API
13
+ """
14
+
15
+ from typing import Dict, Optional
16
+
17
+ from alibabacloud_devs20230714.models import (
18
+ ListToolsetsRequest,
19
+ ListToolsetsResponseBody,
20
+ Toolset,
21
+ )
22
+ from alibabacloud_tea_openapi.exceptions._client import ClientException
23
+ from alibabacloud_tea_openapi.exceptions._server import ServerException
24
+ from alibabacloud_tea_util.models import RuntimeOptions
25
+ import pydash
26
+
27
+ from agentrun.utils.config import Config
28
+ from agentrun.utils.control_api import ControlAPI
29
+ from agentrun.utils.exception import ClientError, ServerError
30
+ from agentrun.utils.log import logger
31
+
32
+
33
+ class ToolControlAPI(ControlAPI):
34
+ """Tool 管控链路 API"""
35
+
36
+ def __init__(self, config: Optional[Config] = None):
37
+ """初始化 API 客户端
38
+
39
+ Args:
40
+ config: 全局配置对象
41
+ """
42
+ super().__init__(config)
43
+
44
+ def get_toolset(
45
+ self,
46
+ name: str,
47
+ headers: Optional[Dict[str, str]] = None,
48
+ config: Optional[Config] = None,
49
+ ) -> Toolset:
50
+ """获取工具
51
+
52
+ Args:
53
+ name: Tool 名称
54
+
55
+ headers: 请求头
56
+ config: 配置
57
+
58
+ Returns:
59
+ Toolset: ToolSet 对象
60
+
61
+ Raises:
62
+ AgentRuntimeError: 调用失败时抛出
63
+ ClientError: 客户端错误
64
+ ServerError: 服务器错误
65
+ APIError: 运行时错误
66
+ """
67
+
68
+ try:
69
+ client = self._get_devs_client(config)
70
+ response = client.get_toolset_with_options(
71
+ name,
72
+ headers=headers or {},
73
+ runtime=RuntimeOptions(),
74
+ )
75
+
76
+ logger.debug(
77
+ "request api get_toolset, request Request ID:"
78
+ f" {response.headers['x-acs-request-id'] if response.headers else ''}\n"
79
+ f" request: {[name,]}\n response: {response.body}"
80
+ )
81
+
82
+ return response.body
83
+ except ClientException as e:
84
+ raise ClientError(
85
+ e.status_code,
86
+ pydash.get(e, "data.message", pydash.get(e, "message", "")),
87
+ request_id=e.request_id,
88
+ request=[
89
+ name,
90
+ ],
91
+ ) from e
92
+ except ServerException as e:
93
+ raise ServerError(
94
+ e.status_code,
95
+ pydash.get(e, "data.message", pydash.get(e, "message", "")),
96
+ request_id=e.request_id,
97
+ ) from e
98
+
99
+ async def get_toolset_async(
100
+ self,
101
+ name: str,
102
+ headers: Optional[Dict[str, str]] = None,
103
+ config: Optional[Config] = None,
104
+ ) -> Toolset:
105
+ """获取工具
106
+
107
+ Args:
108
+ name: Tool 名称
109
+
110
+ headers: 请求头
111
+ config: 配置
112
+
113
+ Returns:
114
+ Toolset: ToolSet 对象
115
+
116
+ Raises:
117
+ AgentRuntimeError: 调用失败时抛出
118
+ ClientError: 客户端错误
119
+ ServerError: 服务器错误
120
+ APIError: 运行时错误
121
+ """
122
+
123
+ try:
124
+ client = self._get_devs_client(config)
125
+ response = await client.get_toolset_with_options_async(
126
+ name,
127
+ headers=headers or {},
128
+ runtime=RuntimeOptions(),
129
+ )
130
+
131
+ logger.debug(
132
+ "request api get_toolset, request Request ID:"
133
+ f" {response.headers['x-acs-request-id'] if response.headers else ''}\n"
134
+ f" request: {[name,]}\n response: {response.body}"
135
+ )
136
+
137
+ return response.body
138
+ except ClientException as e:
139
+ raise ClientError(
140
+ e.status_code,
141
+ pydash.get(e, "data.message", pydash.get(e, "message", "")),
142
+ request_id=e.request_id,
143
+ request=[
144
+ name,
145
+ ],
146
+ ) from e
147
+ except ServerException as e:
148
+ raise ServerError(
149
+ e.status_code,
150
+ pydash.get(e, "data.message", pydash.get(e, "message", "")),
151
+ request_id=e.request_id,
152
+ ) from e
153
+
154
+ def list_toolsets(
155
+ self,
156
+ input: ListToolsetsRequest,
157
+ headers: Optional[Dict[str, str]] = None,
158
+ config: Optional[Config] = None,
159
+ ) -> ListToolsetsResponseBody:
160
+ """枚举 ToolSets
161
+
162
+ Args:
163
+ input: 枚举的配置
164
+
165
+ headers: 请求头
166
+ config: 配置
167
+
168
+ Returns:
169
+ ListToolsetsResponseBody: ToolSet 列表
170
+
171
+ Raises:
172
+ AgentRuntimeError: 调用失败时抛出
173
+ ClientError: 客户端错误
174
+ ServerError: 服务器错误
175
+ APIError: 运行时错误
176
+ """
177
+
178
+ try:
179
+ client = self._get_devs_client(config)
180
+ response = client.list_toolsets_with_options(
181
+ input,
182
+ headers=headers or {},
183
+ runtime=RuntimeOptions(),
184
+ )
185
+
186
+ logger.debug(
187
+ "request api list_toolsets, request Request ID:"
188
+ f" {response.headers['x-acs-request-id'] if response.headers else ''}\n"
189
+ f" request: {[input.to_map(),]}\n response: {response.body}"
190
+ )
191
+
192
+ return response.body
193
+ except ClientException as e:
194
+ raise ClientError(
195
+ e.status_code,
196
+ pydash.get(e, "data.message", pydash.get(e, "message", "")),
197
+ request_id=e.request_id,
198
+ request=[
199
+ input,
200
+ ],
201
+ ) from e
202
+ except ServerException as e:
203
+ raise ServerError(
204
+ e.status_code,
205
+ pydash.get(e, "data.message", pydash.get(e, "message", "")),
206
+ request_id=e.request_id,
207
+ ) from e
208
+
209
+ async def list_toolsets_async(
210
+ self,
211
+ input: ListToolsetsRequest,
212
+ headers: Optional[Dict[str, str]] = None,
213
+ config: Optional[Config] = None,
214
+ ) -> ListToolsetsResponseBody:
215
+ """枚举 ToolSets
216
+
217
+ Args:
218
+ input: 枚举的配置
219
+
220
+ headers: 请求头
221
+ config: 配置
222
+
223
+ Returns:
224
+ ListToolsetsResponseBody: ToolSet 列表
225
+
226
+ Raises:
227
+ AgentRuntimeError: 调用失败时抛出
228
+ ClientError: 客户端错误
229
+ ServerError: 服务器错误
230
+ APIError: 运行时错误
231
+ """
232
+
233
+ try:
234
+ client = self._get_devs_client(config)
235
+ response = await client.list_toolsets_with_options_async(
236
+ input,
237
+ headers=headers or {},
238
+ runtime=RuntimeOptions(),
239
+ )
240
+
241
+ logger.debug(
242
+ "request api list_toolsets, request Request ID:"
243
+ f" {response.headers['x-acs-request-id'] if response.headers else ''}\n"
244
+ f" request: {[input.to_map(),]}\n response: {response.body}"
245
+ )
246
+
247
+ return response.body
248
+ except ClientException as e:
249
+ raise ClientError(
250
+ e.status_code,
251
+ pydash.get(e, "data.message", pydash.get(e, "message", "")),
252
+ request_id=e.request_id,
253
+ request=[
254
+ input,
255
+ ],
256
+ ) from e
257
+ except ServerException as e:
258
+ raise ServerError(
259
+ e.status_code,
260
+ pydash.get(e, "data.message", pydash.get(e, "message", "")),
261
+ request_id=e.request_id,
262
+ ) from e
@@ -0,0 +1,100 @@
1
+ """MCP协议处理 / MCP Protocol Handler
2
+
3
+ 处理MCP(Model Context Protocol)协议的工具调用。
4
+ Handles tool invocations for MCP (Model Context Protocol).
5
+ """
6
+
7
+ from typing import Any, Dict, Optional
8
+
9
+ from agentrun.utils.config import Config
10
+ from agentrun.utils.log import logger
11
+
12
+
13
+ class MCPSession:
14
+
15
+ def __init__(self, url: str, config: Optional[Config] = None):
16
+ self.url = url
17
+ self.config = Config.with_configs(config)
18
+
19
+ async def __aenter__(self):
20
+ from mcp import ClientSession
21
+ from mcp.client.sse import sse_client
22
+
23
+ timeout = self.config.get_timeout()
24
+ self.client = sse_client(
25
+ url=self.url,
26
+ headers=self.config.get_headers(),
27
+ timeout=timeout if timeout else 60,
28
+ )
29
+ (read, write) = await self.client.__aenter__()
30
+
31
+ self.client_session = ClientSession(read, write)
32
+ session = await self.client_session.__aenter__()
33
+ await session.initialize()
34
+
35
+ return session
36
+
37
+ async def __aexit__(self, *args):
38
+ await self.client_session.__aexit__(*args)
39
+ await self.client.__aexit__(*args)
40
+
41
+ def toolsets(self, config: Optional[Config] = None):
42
+ return MCPToolSet(url=self.url + "/toolsets", config=config)
43
+
44
+
45
+ class MCPToolSet:
46
+
47
+ def __init__(self, url: str, config: Optional[Config] = None):
48
+ try:
49
+ __import__("mcp")
50
+ except ImportError:
51
+ logger.warning(
52
+ "MCPToolSet requires Python 3.10 or higher and install 'mcp'"
53
+ " package."
54
+ )
55
+
56
+ self.url = url
57
+ self.config = Config.with_configs(config)
58
+
59
+ def new_session(self, config: Optional[Config] = None):
60
+ cfg = Config.with_configs(self.config, config)
61
+ return MCPSession(url=self.url, config=cfg)
62
+
63
+ async def tools_async(self, config: Optional[Config] = None):
64
+ async with self.new_session(config=config) as session:
65
+ results = await session.list_tools()
66
+ return results.tools
67
+
68
+ def tools(self, config: Optional[Config] = None):
69
+ import asyncio
70
+
71
+ return asyncio.run(self.tools_async(config=config))
72
+
73
+ async def call_tool_async(
74
+ self,
75
+ name: str,
76
+ arguments: Optional[Dict[str, Any]] = None,
77
+ config: Optional[Config] = None,
78
+ ):
79
+ async with self.new_session(config=config) as session:
80
+ result = await session.call_tool(
81
+ name=name,
82
+ arguments=arguments,
83
+ )
84
+ return [item.model_dump() for item in result.content]
85
+
86
+ def call_tool(
87
+ self,
88
+ name: str,
89
+ arguments: Optional[Dict[str, Any]] = None,
90
+ config: Optional[Config] = None,
91
+ ):
92
+ import asyncio
93
+
94
+ return asyncio.run(
95
+ self.call_tool_async(
96
+ name=name,
97
+ arguments=arguments,
98
+ config=config,
99
+ )
100
+ )