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.

Files changed (154) hide show
  1. agentrun/__init__.py +358 -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 +13 -0
  24. agentrun/integration/agentscope/adapter.py +17 -0
  25. agentrun/integration/agentscope/builtin.py +88 -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 +18 -0
  30. agentrun/integration/builtin/knowledgebase.py +137 -0
  31. agentrun/integration/builtin/model.py +93 -0
  32. agentrun/integration/builtin/sandbox.py +1234 -0
  33. agentrun/integration/builtin/toolset.py +47 -0
  34. agentrun/integration/crewai/__init__.py +13 -0
  35. agentrun/integration/crewai/adapter.py +9 -0
  36. agentrun/integration/crewai/builtin.py +88 -0
  37. agentrun/integration/crewai/model_adapter.py +31 -0
  38. agentrun/integration/crewai/tool_adapter.py +26 -0
  39. agentrun/integration/google_adk/__init__.py +13 -0
  40. agentrun/integration/google_adk/adapter.py +15 -0
  41. agentrun/integration/google_adk/builtin.py +88 -0
  42. agentrun/integration/google_adk/message_adapter.py +144 -0
  43. agentrun/integration/google_adk/model_adapter.py +46 -0
  44. agentrun/integration/google_adk/tool_adapter.py +235 -0
  45. agentrun/integration/langchain/__init__.py +31 -0
  46. agentrun/integration/langchain/adapter.py +15 -0
  47. agentrun/integration/langchain/builtin.py +94 -0
  48. agentrun/integration/langchain/message_adapter.py +141 -0
  49. agentrun/integration/langchain/model_adapter.py +37 -0
  50. agentrun/integration/langchain/tool_adapter.py +50 -0
  51. agentrun/integration/langgraph/__init__.py +36 -0
  52. agentrun/integration/langgraph/adapter.py +20 -0
  53. agentrun/integration/langgraph/agent_converter.py +1073 -0
  54. agentrun/integration/langgraph/builtin.py +88 -0
  55. agentrun/integration/pydantic_ai/__init__.py +13 -0
  56. agentrun/integration/pydantic_ai/adapter.py +13 -0
  57. agentrun/integration/pydantic_ai/builtin.py +88 -0
  58. agentrun/integration/pydantic_ai/model_adapter.py +44 -0
  59. agentrun/integration/pydantic_ai/tool_adapter.py +19 -0
  60. agentrun/integration/utils/__init__.py +112 -0
  61. agentrun/integration/utils/adapter.py +560 -0
  62. agentrun/integration/utils/canonical.py +164 -0
  63. agentrun/integration/utils/converter.py +134 -0
  64. agentrun/integration/utils/model.py +110 -0
  65. agentrun/integration/utils/tool.py +1759 -0
  66. agentrun/knowledgebase/__client_async_template.py +173 -0
  67. agentrun/knowledgebase/__init__.py +53 -0
  68. agentrun/knowledgebase/__knowledgebase_async_template.py +438 -0
  69. agentrun/knowledgebase/api/__data_async_template.py +414 -0
  70. agentrun/knowledgebase/api/__init__.py +19 -0
  71. agentrun/knowledgebase/api/control.py +606 -0
  72. agentrun/knowledgebase/api/data.py +624 -0
  73. agentrun/knowledgebase/client.py +311 -0
  74. agentrun/knowledgebase/knowledgebase.py +748 -0
  75. agentrun/knowledgebase/model.py +270 -0
  76. agentrun/memory_collection/__client_async_template.py +178 -0
  77. agentrun/memory_collection/__init__.py +37 -0
  78. agentrun/memory_collection/__memory_collection_async_template.py +457 -0
  79. agentrun/memory_collection/api/__init__.py +5 -0
  80. agentrun/memory_collection/api/control.py +610 -0
  81. agentrun/memory_collection/client.py +323 -0
  82. agentrun/memory_collection/memory_collection.py +844 -0
  83. agentrun/memory_collection/model.py +162 -0
  84. agentrun/model/__client_async_template.py +357 -0
  85. agentrun/model/__init__.py +57 -0
  86. agentrun/model/__model_proxy_async_template.py +270 -0
  87. agentrun/model/__model_service_async_template.py +267 -0
  88. agentrun/model/api/__init__.py +6 -0
  89. agentrun/model/api/control.py +1173 -0
  90. agentrun/model/api/data.py +196 -0
  91. agentrun/model/client.py +674 -0
  92. agentrun/model/model.py +235 -0
  93. agentrun/model/model_proxy.py +439 -0
  94. agentrun/model/model_service.py +438 -0
  95. agentrun/sandbox/__aio_sandbox_async_template.py +523 -0
  96. agentrun/sandbox/__browser_sandbox_async_template.py +110 -0
  97. agentrun/sandbox/__client_async_template.py +491 -0
  98. agentrun/sandbox/__code_interpreter_sandbox_async_template.py +463 -0
  99. agentrun/sandbox/__init__.py +69 -0
  100. agentrun/sandbox/__sandbox_async_template.py +463 -0
  101. agentrun/sandbox/__template_async_template.py +152 -0
  102. agentrun/sandbox/aio_sandbox.py +912 -0
  103. agentrun/sandbox/api/__aio_data_async_template.py +335 -0
  104. agentrun/sandbox/api/__browser_data_async_template.py +140 -0
  105. agentrun/sandbox/api/__code_interpreter_data_async_template.py +206 -0
  106. agentrun/sandbox/api/__init__.py +19 -0
  107. agentrun/sandbox/api/__sandbox_data_async_template.py +107 -0
  108. agentrun/sandbox/api/aio_data.py +551 -0
  109. agentrun/sandbox/api/browser_data.py +172 -0
  110. agentrun/sandbox/api/code_interpreter_data.py +396 -0
  111. agentrun/sandbox/api/control.py +1051 -0
  112. agentrun/sandbox/api/playwright_async.py +492 -0
  113. agentrun/sandbox/api/playwright_sync.py +492 -0
  114. agentrun/sandbox/api/sandbox_data.py +154 -0
  115. agentrun/sandbox/browser_sandbox.py +185 -0
  116. agentrun/sandbox/client.py +925 -0
  117. agentrun/sandbox/code_interpreter_sandbox.py +823 -0
  118. agentrun/sandbox/model.py +384 -0
  119. agentrun/sandbox/sandbox.py +848 -0
  120. agentrun/sandbox/template.py +217 -0
  121. agentrun/server/__init__.py +191 -0
  122. agentrun/server/agui_normalizer.py +180 -0
  123. agentrun/server/agui_protocol.py +797 -0
  124. agentrun/server/invoker.py +309 -0
  125. agentrun/server/model.py +427 -0
  126. agentrun/server/openai_protocol.py +535 -0
  127. agentrun/server/protocol.py +140 -0
  128. agentrun/server/server.py +208 -0
  129. agentrun/toolset/__client_async_template.py +62 -0
  130. agentrun/toolset/__init__.py +51 -0
  131. agentrun/toolset/__toolset_async_template.py +204 -0
  132. agentrun/toolset/api/__init__.py +17 -0
  133. agentrun/toolset/api/control.py +262 -0
  134. agentrun/toolset/api/mcp.py +100 -0
  135. agentrun/toolset/api/openapi.py +1251 -0
  136. agentrun/toolset/client.py +102 -0
  137. agentrun/toolset/model.py +321 -0
  138. agentrun/toolset/toolset.py +271 -0
  139. agentrun/utils/__data_api_async_template.py +721 -0
  140. agentrun/utils/__init__.py +5 -0
  141. agentrun/utils/__resource_async_template.py +158 -0
  142. agentrun/utils/config.py +270 -0
  143. agentrun/utils/control_api.py +105 -0
  144. agentrun/utils/data_api.py +1121 -0
  145. agentrun/utils/exception.py +151 -0
  146. agentrun/utils/helper.py +108 -0
  147. agentrun/utils/log.py +77 -0
  148. agentrun/utils/model.py +168 -0
  149. agentrun/utils/resource.py +291 -0
  150. agentrun_inner_test-0.0.62.dist-info/METADATA +265 -0
  151. agentrun_inner_test-0.0.62.dist-info/RECORD +154 -0
  152. agentrun_inner_test-0.0.62.dist-info/WHEEL +5 -0
  153. agentrun_inner_test-0.0.62.dist-info/licenses/LICENSE +201 -0
  154. agentrun_inner_test-0.0.62.dist-info/top_level.txt +1 -0
@@ -0,0 +1,291 @@
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/utils/__resource_async_template.py
10
+
11
+ 资源基类模板 / Resource Base Template
12
+
13
+ 此模板用于生成资源对象的基类代码。
14
+ This template is used to generate base class code for resource objects.
15
+ """
16
+
17
+ from abc import abstractmethod
18
+ import asyncio
19
+ import time
20
+ from typing import Awaitable, Callable, List, Optional
21
+
22
+ from typing_extensions import Self
23
+
24
+ from agentrun.utils.config import Config
25
+ from agentrun.utils.exception import DeleteResourceError, ResourceNotExistError
26
+ from agentrun.utils.log import logger
27
+
28
+ from .model import BaseModel, PageableInput, Status
29
+
30
+
31
+ class ResourceBase(BaseModel):
32
+ status: Optional[Status] = None
33
+ _config: Optional[Config] = None
34
+
35
+ @classmethod
36
+ @abstractmethod
37
+ async def _list_page_async(
38
+ cls,
39
+ page_input: PageableInput,
40
+ config: Optional[Config] = None,
41
+ **kwargs,
42
+ ) -> list:
43
+ ...
44
+
45
+ @classmethod
46
+ @abstractmethod
47
+ def _list_page(
48
+ cls,
49
+ page_input: PageableInput,
50
+ config: Optional[Config] = None,
51
+ **kwargs,
52
+ ) -> list:
53
+ ...
54
+
55
+ @classmethod
56
+ async def _list_all_async(
57
+ cls,
58
+ uniq_id_callback: Callable[[Self], str],
59
+ config: Optional[Config] = None,
60
+ **kwargs,
61
+ ) -> list:
62
+ all_results: List[Self] = []
63
+ page = 1
64
+ page_size = 50
65
+ while True:
66
+ page_results = await cls._list_page_async(
67
+ PageableInput(
68
+ page_number=page,
69
+ page_size=page_size,
70
+ ),
71
+ config=config,
72
+ **kwargs,
73
+ )
74
+ page += 1
75
+ all_results.extend(page_results) # type: ignore
76
+ if len(page_results) < page_size:
77
+ break
78
+
79
+ result_set = set()
80
+ results: list = []
81
+ for item in all_results:
82
+ uniq_id = uniq_id_callback(item)
83
+ if uniq_id not in result_set:
84
+ result_set.add(uniq_id)
85
+ results.append(item)
86
+
87
+ return results
88
+
89
+ @classmethod
90
+ def _list_all(
91
+ cls,
92
+ uniq_id_callback: Callable[[Self], str],
93
+ config: Optional[Config] = None,
94
+ **kwargs,
95
+ ) -> list:
96
+ all_results: List[Self] = []
97
+ page = 1
98
+ page_size = 50
99
+ while True:
100
+ page_results = cls._list_page(
101
+ PageableInput(
102
+ page_number=page,
103
+ page_size=page_size,
104
+ ),
105
+ config=config,
106
+ **kwargs,
107
+ )
108
+ page += 1
109
+ all_results.extend(page_results) # type: ignore
110
+ if len(page_results) < page_size:
111
+ break
112
+
113
+ result_set = set()
114
+ results: list = []
115
+ for item in all_results:
116
+ uniq_id = uniq_id_callback(item)
117
+ if uniq_id not in result_set:
118
+ result_set.add(uniq_id)
119
+ results.append(item)
120
+
121
+ return results
122
+
123
+ @abstractmethod
124
+ async def refresh_async(self, config: Optional[Config] = None) -> Self:
125
+ ...
126
+
127
+ @abstractmethod
128
+ def refresh(self, config: Optional[Config] = None) -> Self:
129
+ ...
130
+
131
+ @abstractmethod
132
+ async def delete_async(self, config: Optional[Config] = None) -> Self:
133
+ ...
134
+
135
+ @abstractmethod
136
+ def delete(self, config: Optional[Config] = None) -> Self:
137
+ ...
138
+
139
+ async def __wait_until_async(
140
+ self,
141
+ check_finished_callback_async: Callable[[Self], Awaitable[bool]],
142
+ interval_seconds: int = 5,
143
+ timeout_seconds: int = 300,
144
+ ) -> Self:
145
+ """等待智能体运行时进入就绪状态"""
146
+
147
+ start_time = time.time()
148
+ while True:
149
+ if await check_finished_callback_async(self):
150
+ return self
151
+
152
+ if time.time() - start_time > timeout_seconds:
153
+ raise TimeoutError("等待就绪超时")
154
+
155
+ await asyncio.sleep(interval_seconds)
156
+
157
+ def __wait_until(
158
+ self,
159
+ check_finished_callback: Callable[[Self], bool],
160
+ interval_seconds: int = 5,
161
+ timeout_seconds: int = 300,
162
+ ) -> Self:
163
+ """等待智能体运行时进入就绪状态"""
164
+
165
+ start_time = time.time()
166
+ while True:
167
+ if check_finished_callback(self):
168
+ return self
169
+
170
+ if time.time() - start_time > timeout_seconds:
171
+ raise TimeoutError("等待就绪超时")
172
+
173
+ time.sleep(interval_seconds)
174
+
175
+ async def wait_until_ready_or_failed_async(
176
+ self,
177
+ callback: Optional[Callable[[Self], None]] = None,
178
+ interval_seconds: int = 5,
179
+ timeout_seconds: int = 300,
180
+ ):
181
+ """等待智能体运行时进入就绪状态"""
182
+
183
+ async def check_ready_callback(resource: Self) -> bool:
184
+ await resource.refresh_async()
185
+ if callback:
186
+ callback(resource)
187
+ logger.debug("当前状态:%s", resource.status)
188
+
189
+ return Status.is_final_status(resource.status)
190
+
191
+ await self.__wait_until_async(
192
+ check_ready_callback,
193
+ interval_seconds=interval_seconds,
194
+ timeout_seconds=timeout_seconds,
195
+ )
196
+
197
+ def wait_until_ready_or_failed(
198
+ self,
199
+ callback: Optional[Callable[[Self], None]] = None,
200
+ interval_seconds: int = 5,
201
+ timeout_seconds: int = 300,
202
+ ):
203
+ """等待智能体运行时进入就绪状态"""
204
+
205
+ def check_ready_callback(resource: Self) -> bool:
206
+ resource.refresh()
207
+ if callback:
208
+ callback(resource)
209
+ logger.debug("当前状态:%s", resource.status)
210
+
211
+ return Status.is_final_status(resource.status)
212
+
213
+ self.__wait_until(
214
+ check_ready_callback,
215
+ interval_seconds=interval_seconds,
216
+ timeout_seconds=timeout_seconds,
217
+ )
218
+
219
+ async def delete_and_wait_until_finished_async(
220
+ self,
221
+ callback: Optional[Callable[[Self], None]] = None,
222
+ interval_seconds: int = 5,
223
+ timeout_seconds: int = 300,
224
+ ):
225
+ """等待智能体运行时被删除"""
226
+ try:
227
+ await self.delete_async()
228
+ except ResourceNotExistError:
229
+ return
230
+
231
+ async def check_deleted_callback(resource: Self) -> bool:
232
+ try:
233
+ await resource.refresh_async()
234
+ if callback:
235
+ callback(resource)
236
+ except ResourceNotExistError:
237
+ return True
238
+
239
+ if resource.status == Status.DELETING:
240
+ return False
241
+
242
+ raise DeleteResourceError(f"Resource status is {resource.status}")
243
+
244
+ await self.__wait_until_async(
245
+ check_deleted_callback,
246
+ interval_seconds=interval_seconds,
247
+ timeout_seconds=timeout_seconds,
248
+ )
249
+
250
+ def delete_and_wait_until_finished(
251
+ self,
252
+ callback: Optional[Callable[[Self], None]] = None,
253
+ interval_seconds: int = 5,
254
+ timeout_seconds: int = 300,
255
+ ):
256
+ """等待智能体运行时被删除"""
257
+ try:
258
+ self.delete()
259
+ except ResourceNotExistError:
260
+ return
261
+
262
+ def check_deleted_callback(resource: Self) -> bool:
263
+ try:
264
+ resource.refresh()
265
+ if callback:
266
+ callback(resource)
267
+ except ResourceNotExistError:
268
+ return True
269
+
270
+ if resource.status == Status.DELETING:
271
+ return False
272
+
273
+ raise DeleteResourceError(f"Resource status is {resource.status}")
274
+
275
+ self.__wait_until(
276
+ check_deleted_callback,
277
+ interval_seconds=interval_seconds,
278
+ timeout_seconds=timeout_seconds,
279
+ )
280
+
281
+ def set_config(self, config: Config) -> Self:
282
+ """设置配置
283
+
284
+ Args:
285
+ config: 配置
286
+
287
+ Returns:
288
+ Self: 当前对象
289
+ """
290
+ self._config = config
291
+ return self
@@ -0,0 +1,265 @@
1
+ Metadata-Version: 2.4
2
+ Name: agentrun-inner-test
3
+ Version: 0.0.62
4
+ Summary: Alibaba Cloud Agent Run SDK
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: crcmod>=1.7
9
+ Requires-Dist: pydantic>=2.12.4
10
+ Requires-Dist: httpx>=0.23.0
11
+ Requires-Dist: python-dotenv>=1.2.1
12
+ Requires-Dist: typing-extensions>=4.15.0
13
+ Requires-Dist: litellm>=1.79.3
14
+ Requires-Dist: alibabacloud-devs20230714>=2.4.1
15
+ Requires-Dist: pydash>=8.0.5
16
+ Requires-Dist: alibabacloud-agentrun20250910>=5.2.0
17
+ Requires-Dist: alibabacloud_tea_openapi>=0.4.2
18
+ Requires-Dist: alibabacloud_bailian20231229>=2.6.2
19
+ Requires-Dist: agentrun-mem0ai>=0.0.6
20
+ Provides-Extra: server
21
+ Requires-Dist: fastapi>=0.104.0; extra == "server"
22
+ Requires-Dist: uvicorn>=0.24.0; extra == "server"
23
+ Requires-Dist: ag-ui-protocol>=0.1.10; extra == "server"
24
+ Provides-Extra: langchain
25
+ Requires-Dist: langchain>=1.0.0; python_version >= "3.10" and extra == "langchain"
26
+ Requires-Dist: langchain-openai>=1.0.0; python_version >= "3.10" and extra == "langchain"
27
+ Provides-Extra: google-adk
28
+ Requires-Dist: google-adk>=1.18.0; extra == "google-adk"
29
+ Provides-Extra: agentscope
30
+ Requires-Dist: agentscope>=0.1.6; extra == "agentscope"
31
+ Provides-Extra: crewai
32
+ Requires-Dist: crewai>=1.6.0; extra == "crewai"
33
+ Provides-Extra: pydantic-ai
34
+ Requires-Dist: pydantic-ai>=1.22.0; python_version >= "3.10" and extra == "pydantic-ai"
35
+ Provides-Extra: playwright
36
+ Requires-Dist: playwright>=1.40.0; extra == "playwright"
37
+ Provides-Extra: mcp
38
+ Requires-Dist: mcp>=1.21.2; python_version >= "3.10" and extra == "mcp"
39
+ Dynamic: license-file
40
+
41
+ # AgentRun Python SDK
42
+
43
+ <div align="center">
44
+
45
+ [![PyPI version](https://img.shields.io/pypi/v/agentrun-sdk.svg)](https://pypi.org/project/agentrun-sdk/)
46
+ [![License](https://img.shields.io/github/license/Serverless-Devs/agentrun-sdk-python.svg)](https://github.com/Serverless-Devs/agentrun-sdk-python/blob/main/LICENSE)
47
+ [![Documentation](https://img.shields.io/badge/docs-agent.run-blue.svg)](https://docs.agent.run)
48
+ [![GitHub stars](https://img.shields.io/github/stars/Serverless-Devs/agentrun-sdk-python.svg?style=social)](https://github.com/Serverless-Devs/agentrun-sdk-python)
49
+ [![GitHub issues](https://img.shields.io/github/issues/Serverless-Devs/agentrun-sdk-python.svg)](https://github.com/Serverless-Devs/agentrun-sdk-python/issues)
50
+
51
+ </div>
52
+
53
+ AgentRun Python SDK 是阿里云 AgentRun 服务的 Python 客户端库,提供简洁易用的 API 来管理 AI Agent 运行时环境。
54
+
55
+ ## ✨ 特性
56
+
57
+ - 🎯 **简洁 API** - 面向对象的设计,直观易用
58
+ - ⚡ **异步支持** - 同时提供同步和异步接口
59
+ - 🔧 **类型提示** - 完整的类型注解,IDE 友好
60
+ - 🔐 **多种认证** - 支持 Access Key、STS Token 等
61
+ - 🌐 **多区域** - 支持阿里云所有可用区域
62
+ - 📝 **详细文档** - 完善的代码注释和示例
63
+
64
+ ## 📦 安装
65
+
66
+ ### 使用 pip 安装
67
+
68
+ ```bash
69
+ pip install agentrun-sdk
70
+ ```
71
+
72
+ 可选依赖项
73
+ - `server`: 使用 AgentRunServer 集成 HTTP 服务
74
+ - `playwright:使用` Browser Sandbox 并集成 playwright
75
+ - `mcp:使用` MCP ToolSet
76
+ - `agentscope:集成` AgentScope
77
+ - `langchain:集成` LangChain
78
+ - `google`-adk:集成 Google ADK
79
+ - `crewai:集成` CrewAI
80
+ - `pydantic`-ai:集成 PydanticAI
81
+
82
+ 假设您需要使用 agentscope,并且需要用到 Browser Sandbox,AgentRun 上的 MCP 服务,那么您应该通过如下方式安装
83
+ ```bash
84
+ pip install agentrun-sdk[playwright,mcp,agentscope]
85
+ ```
86
+
87
+
88
+ ### 依赖要求
89
+
90
+ - Python 3.10 或更高版本
91
+
92
+ ## 🚀 快速开始
93
+
94
+ 你可以使用任意您喜欢的框架进行 Agent 开发,这里以 langchain 为例
95
+
96
+ ### 1. 安装 Serverless Devs
97
+
98
+ 运行脚手架,您需要使用 Serverless Devs 工具,请参考对应 [安装教程](https://serverless-devs.com/docs/user-guide/install)
99
+ > 如果您拥有 NodeJS 开发环境,可以使用 `npm i -g @serverless-devs/s` 快速安装 Serverless Devs
100
+ > 您也可以直接下载 [Serverless Devs 二进制程序](https://github.com/Serverless-Devs/Serverless-Devs/releases) 使用 Serverless Devs
101
+
102
+
103
+ ### 2. 创建模板
104
+
105
+ 使用快速创建脚手架创建您的 Agent
106
+
107
+ **注意!** 您需要确保您的 python 环境在 3.10 以上
108
+
109
+ ```bash
110
+ # 初始化模板
111
+ s init agentrun-quick-start-langchain
112
+
113
+ # 按照实际情况进入代码目录
114
+ cd agentrun-quick-start-langchain/code
115
+
116
+ # 初始化虚拟环境并安装依赖
117
+ uv venv && uv pip install -r requirements.txt
118
+ ```
119
+
120
+ ### 3. 配置认证信息
121
+
122
+ 设置环境变量(建议通过 `.env` 配置您的环境变量)
123
+
124
+ ```bash
125
+ export AGENTRUN_ACCESS_KEY_ID="your-access-key-id"
126
+ export AGENTRUN_ACCESS_KEY_SECRET="your-access-key-secret"
127
+ export AGENTRUN_ACCOUNT_ID="your-account-id"
128
+ export AGENTRUN_REGION="cn-hangzhou"
129
+ ```
130
+
131
+ ### 4. 了解 Agent 如何与 LangChain 集成
132
+
133
+
134
+ 使用 `from agentrun.integration.langchain import model, sandbox_toolset` 导入 langchain 的集成能力,这里默认提供了 `model`、`sandbox_toolset`、`toolset`,可以快速创建 langchain 可识别的大模型、工具
135
+ 同时,通过 AgentRunServer 可以快速开放 HTTP Server 供其他业务集成
136
+
137
+ ```python
138
+ from agentrun.integration.langchain import model, sandbox_toolset
139
+ from agentrun.sandbox import TemplateType
140
+ from agentrun.server import AgentRequest, AgentRunServer
141
+ from agentrun.utils.log import logger
142
+
143
+ # 请替换为您已经创建的 模型 和 沙箱 名称
144
+ MODEL_NAME = "<your-model-name>"
145
+ SANDBOX_NAME = "<your-sandbox-name>"
146
+
147
+ if MODEL_NAME.startswith("<"):
148
+ raise ValueError("请将 MODEL_NAME 替换为您已经创建的模型名称")
149
+
150
+ code_interpreter_tools = []
151
+ if SANDBOX_NAME and not SANDBOX_NAME.startswith("<"):
152
+ code_interpreter_tools = sandbox_toolset(
153
+ template_name=SANDBOX_NAME,
154
+ template_type=TemplateType.CODE_INTERPRETER,
155
+ sandbox_idle_timeout_seconds=300,
156
+ )
157
+ else:
158
+ logger.warning("SANDBOX_NAME 未设置或未替换,跳过加载沙箱工具。")
159
+
160
+ # ...
161
+
162
+ # 自动启动 http server,提供 OpenAI 协议
163
+ AgentRunServer(invoke_agent=invoke_agent).start()
164
+ ```
165
+
166
+ ### 5. 调用 Agent
167
+
168
+ ```bash
169
+ curl 127.0.0.1:9000/openai/v1/chat/completions \
170
+ -XPOST \
171
+ -H "content-type: application/json" \
172
+ -d '{"messages": [{"role": "user", "content": "通过代码查询现在是几点?"}], "stream":true}'
173
+ ```
174
+
175
+ ### 6. 部署项目
176
+
177
+ 项目中已经存在 `s.yaml` 文件,这是 Serverless Devs 的部署配置文件,通过这个文件,您可以配置当前 Agent 在 Agent Run 上的名称、CPU/内存规格、日志投递信息
178
+
179
+ 在示例情况下,您只需要简单修改该文件即可。修改 `role` 字段为授信给阿里云函数计算(FC)服务,需要拥有AliyunAgentRunFullAccess权限的角色(如果您拥有精细化权限控制的需求,可以根据实际使用的 API 收敛权限)
180
+
181
+ > 您可以点击此[快速授权链接](https://ram.console.aliyun.com/authorize?request=%7B%22template%22%3A%22OldRoleCommonAuthorize%22%2C%22referrer%22%3A%22https%3A%2F%2Ffunctionai.console.aliyun.com%2Fcn-hangzhou%2Fexplore%22%2C%22payloads%22%3A%5B%7B%22missionId%22%3A%22OldRoleCommonAuthorize.FC%22%2C%22roleName%22%3A%22agentRunRole%22%2C%22roleDescription%22%3A%22AgentRun%20auto%20created%20role.%22%2C%22rolePolicies%22%3A%5B%7B%22policyName%22%3A%22AliyunAgentRunFullAccess%22%7D%2C%7B%22policyName%22%3A%22AliyunDevsFullAccess%22%7D%5D%7D%5D%2C%22callback%22%3A%22https%3A%2F%2Ffunctionai.console.aliyun.com%22%7D),创建一个符合相关权限的角色agentRunRole。
182
+ >
183
+ > 此快速创建角色的RoleArn为:acs:ram::{您的阿里云主账号 ID}:role/agentRunRole
184
+
185
+ ```yaml
186
+ role: acs:ram::{您的阿里云主账号 ID}:role/{您的阿里云角色名称}
187
+ ```
188
+
189
+ > 如果在未来的使用中遇到了任何 Serverless Devs 相关问题,都可以参考 [Serverless Devs 相关文档](https://serverless-devs.com/docs/overview)
190
+
191
+ 在部署前,您需要配置您的部署密钥,使用 `s config add` 进入交互式密钥管理,并按照引导录入您在阿里云的 Access Key ID 与 Access Key Secret。在录入过程中,您需要短期记忆一下您输入的密钥对名称(假设为 `agentrun-deploy`)
192
+
193
+ 配置完成后,需要首先执行`s build`构建,该步骤依赖本地的`docker`服务,对代码目录下的`requirements.txt`进行构建,以便部署在云端。
194
+
195
+ 随后即可执行`s deploy`进行部署操作。
196
+
197
+ ```bash
198
+ s build
199
+ s deploy -a agentrun-deploy
200
+ # agentrun-deploy 是您使用的密钥对名称,也可以将该名称写入到 s.yaml 开头的 access: 字段中
201
+ ```
202
+
203
+ ### 7. 在线上进行调用
204
+
205
+ 部署完成后,您可以看到如下格式的输出
206
+ ```
207
+ endpoints:
208
+ -
209
+ id: ...
210
+ arn: ...
211
+ name: ...
212
+ url: https://12345.agentrun-data.cn-hangzhou.aliyuncs.com/agent-runtimes/abcd/endpoints/prod/invocations
213
+ ```
214
+
215
+ 此处的 url 为您的 Agent 调用地址,将实际的请求 path 拼接到该 base url 后,即可调用云上的 Agent 资源
216
+
217
+ ```bash
218
+ curl https://12345.agentrun-data.cn-hangzhou.aliyuncs.com/agent-runtimes/abcd/endpoints/prod/invocations/openai/v1/chat/completions \
219
+ -XPOST \
220
+ -H "content-type: application/json" \
221
+ -d '{"messages": [{"role": "user", "content": "通过代码查询现在是几点?"}], "stream":true}'
222
+ ```
223
+
224
+ ## ⚙️ 配置说明
225
+
226
+ ### Config 类
227
+
228
+ 用于配置认证信息和客户端参数。
229
+
230
+ ```python
231
+ from agentrun.utils.config import Config
232
+
233
+ config = Config(
234
+ access_key_id="your-key-id", # Access Key ID
235
+ access_key_secret="your-secret", # Access Key Secret
236
+ security_token="your-sts-token", # 可选:STS Token
237
+ token="token", # 数据链路 token(可以在无 AK 情况下调用数据链路)
238
+ headers={}, # 附加的请求头
239
+ account_id="your-account-id", # 账号 ID
240
+ region_id="cn-hangzhou", # 区域
241
+ timeout=30, # 可选:请求超时(秒)
242
+ control_endpoint="", # 可选:自定义控制端点
243
+ data_endpoint="", # 可选:自定义数据端点
244
+ )
245
+
246
+ # 使用配置创建客户端
247
+ client = agent_runtime.AgentRuntimeClient()
248
+ agent = client.create(input_config, config=config)
249
+ ```
250
+
251
+ ### 环境变量
252
+
253
+ SDK 会自动读取以下环境变量:
254
+
255
+ | 环境变量 | 说明 | 备用变量 |
256
+ |---------|------|---------|
257
+ | `AGENTRUN_ACCESS_KEY_ID` | Access Key ID | `ALIBABA_CLOUD_ACCESS_KEY_ID` |
258
+ | `AGENTRUN_ACCESS_KEY_SECRET` | Access Key Secret | `ALIBABA_CLOUD_ACCESS_KEY_SECRET` |
259
+ | `AGENTRUN_SECURITY_TOKEN` | STS Token | `ALIBABA_CLOUD_SECURITY_TOKEN` |
260
+ | `AGENTRUN_ACCOUNT_ID` | 账号 ID | `FC_ACCOUNT_ID` |
261
+ | `AGENTRUN_REGION` | 区域 | `FC_REGION` |
262
+ | `AGENTRUN_CONTROL_ENDPOINT` | 控制端点 | - |
263
+ | `AGENTRUN_DATA_ENDPOINT` | 数据端点 | - |
264
+ | `AGENTRUN_SDK_DEBUG` | 开启 DEBUG 日志 | - |
265
+