Skip to content

Commit 52cf6d1

Browse files
committed
refactor(super_agent): Replace tags with system_tags across multiple modules
This change updates the codebase to use `system_tags` instead of `tags`, aligning with changes in the underlying SDK where `systemTags` is now natively supported. The update affects both the control logic and related unit tests. Key changes include: - Replacing references to `tags` with `system_tags` throughout the super_agent module - Updating corresponding unit tests to reflect this change - Modifying docstrings that previously mentioned filtering by tag to mention systemTag instead - Bumping the required version of alibabacloud-agentrun20250910 to >=5.6.1 which includes native support for systemTags Co-developed-by: Aone Copilot <noreply@alibaba-inc.com> Signed-off-by: Sodawyx <sodawyx@126.com>
1 parent c61ead9 commit 52cf6d1

8 files changed

Lines changed: 63 additions & 227 deletions

File tree

agentrun/agent_runtime/api/control.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
CreateAgentRuntimeEndpointRequest,
2222
CreateAgentRuntimeInput,
2323
CreateAgentRuntimeRequest,
24+
DeleteAgentRuntimeEndpointRequest,
25+
DeleteAgentRuntimeRequest,
26+
GetAgentRuntimeEndpointRequest,
2427
GetAgentRuntimeRequest,
2528
ListAgentRuntimeEndpointsOutput,
2629
ListAgentRuntimeEndpointsRequest,
@@ -193,6 +196,7 @@ def delete_agent_runtime(
193196
client = self._get_client(config)
194197
response = client.delete_agent_runtime_with_options(
195198
agent_id,
199+
DeleteAgentRuntimeRequest(),
196200
headers=headers or {},
197201
runtime=RuntimeOptions(),
198202
)
@@ -248,6 +252,7 @@ async def delete_agent_runtime_async(
248252
client = self._get_client(config)
249253
response = await client.delete_agent_runtime_with_options_async(
250254
agent_id,
255+
DeleteAgentRuntimeRequest(),
251256
headers=headers or {},
252257
runtime=RuntimeOptions(),
253258
)
@@ -778,6 +783,7 @@ def delete_agent_runtime_endpoint(
778783
response = client.delete_agent_runtime_endpoint_with_options(
779784
agent_id,
780785
endpoint_id,
786+
DeleteAgentRuntimeEndpointRequest(),
781787
headers=headers or {},
782788
runtime=RuntimeOptions(),
783789
)
@@ -838,6 +844,7 @@ async def delete_agent_runtime_endpoint_async(
838844
await client.delete_agent_runtime_endpoint_with_options_async(
839845
agent_id,
840846
endpoint_id,
847+
DeleteAgentRuntimeEndpointRequest(),
841848
headers=headers or {},
842849
runtime=RuntimeOptions(),
843850
)
@@ -1028,6 +1035,7 @@ def get_agent_runtime_endpoint(
10281035
response = client.get_agent_runtime_endpoint_with_options(
10291036
agent_id,
10301037
endpoint_id,
1038+
GetAgentRuntimeEndpointRequest(),
10311039
headers=headers or {},
10321040
runtime=RuntimeOptions(),
10331041
)
@@ -1088,6 +1096,7 @@ async def get_agent_runtime_endpoint_async(
10881096
await client.get_agent_runtime_endpoint_with_options_async(
10891097
agent_id,
10901098
endpoint_id,
1099+
GetAgentRuntimeEndpointRequest(),
10911100
headers=headers or {},
10921101
runtime=RuntimeOptions(),
10931102
)

agentrun/agent_runtime/model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ class AgentRuntimeMutableProps(BaseModel):
252252
"""会话空闲超时时间,单位:秒"""
253253
tags: Optional[List[str]] = None
254254
"""标签列表"""
255+
system_tags: Optional[List[str]] = None
256+
"""系统标签列表 (由平台内部使用, 例如 SuperAgent 用来标识下游 AgentRuntime)"""
255257

256258

257259
class AgentRuntimeImmutableProps(BaseModel):
@@ -323,6 +325,8 @@ class AgentRuntimeListInput(PageableInput):
323325
"""Agent Runtime 名称"""
324326
tags: Optional[str] = None
325327
"""标签过滤,多个标签用逗号分隔"""
328+
system_tags: Optional[str] = None
329+
"""系统标签过滤, 多个标签用逗号分隔"""
326330
search_mode: Optional[str] = None
327331
"""搜索模式"""
328332

agentrun/super_agent/__client_async_template.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
内部持有一个 :class:`AgentRuntimeClient` 实例, 通过 ``api/control.py`` 的
55
转换函数把 ``SuperAgent`` 与 ``AgentRuntime`` 互相映射。
66
7-
list 固定按 tag ``x-agentrun-super`` 过滤, 不接受用户自定义 tag。
7+
list 固定按 systemTag ``x-agentrun-super`` 过滤, 不接受用户自定义 tag。
88
"""
99

1010
import asyncio
@@ -246,7 +246,7 @@ def _find_rt_by_name(self, name: str, config: Optional[Config]) -> Any:
246246
AgentRuntimeListInput(
247247
page_number=page_number,
248248
page_size=page_size,
249-
tags=SUPER_AGENT_TAG,
249+
system_tags=SUPER_AGENT_TAG,
250250
),
251251
config=cfg,
252252
)
@@ -268,7 +268,7 @@ async def _find_rt_by_name_async(
268268
AgentRuntimeListInput(
269269
page_number=page_number,
270270
page_size=page_size,
271-
tags=SUPER_AGENT_TAG,
271+
system_tags=SUPER_AGENT_TAG,
272272
),
273273
config=cfg,
274274
)
@@ -438,12 +438,12 @@ async def list_async(
438438
page_size: int = 20,
439439
config: Optional[Config] = None,
440440
) -> List[SuperAgent]:
441-
"""异步列出超级 Agent (固定 tag 过滤, 过滤非 SUPER_AGENT)."""
441+
"""异步列出超级 Agent (固定 systemTag 过滤, 过滤非 SUPER_AGENT)."""
442442
cfg = Config.with_configs(self.config, config)
443443
rt_input = AgentRuntimeListInput(
444444
page_number=page_number,
445445
page_size=page_size,
446-
tags=SUPER_AGENT_TAG,
446+
system_tags=SUPER_AGENT_TAG,
447447
)
448448
runtimes = await self._rt.list_async(rt_input, config=cfg)
449449
result: List[SuperAgent] = []
@@ -462,12 +462,12 @@ def list(
462462
page_size: int = 20,
463463
config: Optional[Config] = None,
464464
) -> List[SuperAgent]:
465-
"""同步列出超级 Agent (固定 tag 过滤, 过滤非 SUPER_AGENT)."""
465+
"""同步列出超级 Agent (固定 systemTag 过滤, 过滤非 SUPER_AGENT)."""
466466
cfg = Config.with_configs(self.config, config)
467467
rt_input = AgentRuntimeListInput(
468468
page_number=page_number,
469469
page_size=page_size,
470-
tags=SUPER_AGENT_TAG,
470+
system_tags=SUPER_AGENT_TAG,
471471
)
472472
runtimes = self._rt.list(rt_input, config=cfg)
473473
result: List[SuperAgent] = []

agentrun/super_agent/api/control.py

Lines changed: 15 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,9 @@
2020
if TYPE_CHECKING:
2121
from agentrun.super_agent.agent import SuperAgent
2222

23-
from alibabacloud_agentrun20250910.client import Client as _DaraClient
24-
from alibabacloud_agentrun20250910.models import (
25-
CreateAgentRuntimeInput as _DaraCreateAgentRuntimeInput,
26-
)
27-
from alibabacloud_agentrun20250910.models import (
28-
ListAgentRuntimesRequest as _DaraListAgentRuntimesRequest,
29-
)
3023
from alibabacloud_agentrun20250910.models import (
3124
ProtocolConfiguration as _DaraProtocolConfiguration,
3225
)
33-
from alibabacloud_agentrun20250910.models import (
34-
UpdateAgentRuntimeInput as _DaraUpdateAgentRuntimeInput,
35-
)
3626
from pydantic import Field
3727

3828
from agentrun.agent_runtime.model import (
@@ -50,11 +40,12 @@
5040
API_VERSION = "2025-09-10"
5141
SUPER_AGENT_PROTOCOL_TYPE = "SUPER_AGENT"
5242
# ``SUPER_AGENT_TAG`` 标识下游 AgentRuntime 是超级 Agent, 用于 list 过滤。
43+
# 写入 ``systemTags`` 字段 (由服务端原生支持), create/update/list 的 system_tags 参数统一使用。
5344
SUPER_AGENT_TAG = "x-agentrun-super"
5445
# ``EXTERNAL_TAG`` 标识下游 AgentRuntime 由外部 (SuperAgent) 托管调用, 不由 AgentRun 直接托管。
5546
# 保留常量以便外部消费者引用; 创建超级 Agent 时不再写入此 tag。
5647
EXTERNAL_TAG = "x-agentrun-external"
57-
# 创建下游 AgentRuntime 时固定写入的 tag 列表: ``[SUPER_AGENT_TAG]`` (仅一个)。
48+
# 创建下游 AgentRuntime 时固定写入的 systemTags 列表: ``[SUPER_AGENT_TAG]`` (仅一个)。
5849
SUPER_AGENT_CREATE_TAGS = [SUPER_AGENT_TAG]
5950
SUPER_AGENT_RESOURCE_PATH = "__SUPER_AGENT__"
6051
SUPER_AGENT_INVOKE_PATH = "/invoke"
@@ -153,16 +144,15 @@ def model_dump(self, **kwargs: Any) -> Dict[str, Any]:
153144
return super().model_dump(**kwargs)
154145

155146

156-
# ─── Dara 模型/客户端猴补丁 ──────────────────────────────────────
157-
# 当前版 Dara SDK 缺 ``ProtocolConfiguration.externalEndpoint`` 和
158-
# ``CreateAgentRuntimeInput/UpdateAgentRuntimeInput/ListAgentRuntimesRequest.tags``
159-
# 字段, 会在 Pydantic ↔ Dara ``from_map / to_map`` roundtrip 中静默丢失; 且
160-
# ``Client.list_agent_runtimes_with_options{,_async}`` 不会把 ``tags`` 写到 query。
147+
# ─── Dara 模型猴补丁 ──────────────────────────────────────
148+
# 当前版 Dara SDK 缺 ``ProtocolConfiguration.externalEndpoint`` 字段, 会在
149+
# Pydantic ↔ Dara ``from_map / to_map`` roundtrip 中静默丢失。补丁延迟到
150+
# ``SuperAgentClient`` 实例化时 (见 ``ensure_super_agent_patches_applied``) 才
151+
# 触发, 避免仅 import 本模块的调用方被动承担全局副作用。补丁用哨兵属性保证
152+
# 幂等, 重复调用安全。TODO: 等 Dara SDK 原生支持后删除。
161153
#
162-
# 所有补丁都延迟到 ``SuperAgentClient`` 实例化时 (见
163-
# ``ensure_super_agent_patches_applied``) 才触发, 避免仅 import 本模块的调用方
164-
# 被动承担全局副作用。补丁本身用哨兵属性保证幂等, 重复调用安全。
165-
# TODO: 等 Dara SDK 原生支持后删除。
154+
# ``tags`` (原 hack 写入) 已由 SDK 原生 ``systemTags`` 字段替代, 不再需要任何
155+
# 补丁; create/update/list 统一走 ``system_tags`` 参数。
166156

167157

168158
def _patch_dara_protocol_configuration() -> None:
@@ -193,120 +183,14 @@ def _patched_from_map(
193183
_DaraProtocolConfiguration._super_agent_patched = True # type: ignore[attr-defined]
194184

195185

196-
def _patch_dara_tags(cls: Any) -> None:
197-
"""给 Dara model 补齐 ``tags`` 字段的 from_map/to_map 读写."""
198-
if getattr(cls, "_super_agent_tags_patched", False):
199-
return
200-
_orig_to_map = cls.to_map
201-
_orig_from_map = cls.from_map
202-
203-
def _patched_to_map(self: Any) -> Dict[str, Any]:
204-
result = _orig_to_map(self)
205-
tags = getattr(self, "tags", None)
206-
if tags is not None:
207-
result["tags"] = tags
208-
return result
209-
210-
def _patched_from_map(self: Any, m: Optional[Dict[str, Any]] = None) -> Any:
211-
_orig_from_map(self, m)
212-
if m and m.get("tags") is not None:
213-
self.tags = m.get("tags")
214-
return self
215-
216-
cls.to_map = _patched_to_map # type: ignore[assignment]
217-
cls.from_map = _patched_from_map # type: ignore[assignment]
218-
cls._super_agent_tags_patched = True # type: ignore[attr-defined]
219-
220-
221-
def _tags_query_value(tags: Any) -> Optional[str]:
222-
if tags is None:
223-
return None
224-
if isinstance(tags, str):
225-
return tags
226-
if isinstance(tags, (list, tuple)):
227-
return ",".join(str(t) for t in tags)
228-
return str(tags)
229-
230-
231-
def _patch_dara_client_list_tags() -> None:
232-
"""包裹 ``Client.list_agent_runtimes_with_options{,_async}``: 若 request 带
233-
``tags`` 就在底层 ``call_api`` 调用前把 ``tags`` (列表 → 逗号分隔) 追加到
234-
``req.query``。
235-
236-
每次 API 调用由 ``_get_client()`` 新建 ``Client`` 实例, 实例属性级别的
237-
``self.call_api = _injecting`` 替换在并发下是安全的。
238-
"""
239-
if getattr(_DaraClient, "_super_agent_list_tags_patched", False):
240-
return
241-
242-
_orig_sync = _DaraClient.list_agent_runtimes_with_options
243-
_orig_async = _DaraClient.list_agent_runtimes_with_options_async
244-
245-
def _patched_sync(
246-
self: Any, request: Any, headers: Any, runtime: Any
247-
) -> Any:
248-
tags_value = _tags_query_value(getattr(request, "tags", None))
249-
if tags_value is None:
250-
return _orig_sync(self, request, headers, runtime)
251-
orig_call_api = self.call_api
252-
253-
def _injecting(params: Any, req: Any, rt: Any) -> Any:
254-
if req.query is None:
255-
req.query = {}
256-
req.query["tags"] = tags_value
257-
return orig_call_api(params, req, rt)
258-
259-
self.call_api = _injecting
260-
try:
261-
return _orig_sync(self, request, headers, runtime)
262-
finally:
263-
try:
264-
del self.call_api
265-
except AttributeError:
266-
pass
267-
268-
async def _patched_async(
269-
self: Any, request: Any, headers: Any, runtime: Any
270-
) -> Any:
271-
tags_value = _tags_query_value(getattr(request, "tags", None))
272-
if tags_value is None:
273-
return await _orig_async(self, request, headers, runtime)
274-
orig_call_api_async = self.call_api_async
275-
276-
async def _injecting(params: Any, req: Any, rt: Any) -> Any:
277-
if req.query is None:
278-
req.query = {}
279-
req.query["tags"] = tags_value
280-
return await orig_call_api_async(params, req, rt)
281-
282-
self.call_api_async = _injecting
283-
try:
284-
return await _orig_async(self, request, headers, runtime)
285-
finally:
286-
try:
287-
del self.call_api_async
288-
except AttributeError:
289-
pass
290-
291-
_DaraClient.list_agent_runtimes_with_options = _patched_sync # type: ignore[assignment]
292-
_DaraClient.list_agent_runtimes_with_options_async = _patched_async # type: ignore[assignment]
293-
_DaraClient._super_agent_list_tags_patched = True # type: ignore[attr-defined]
294-
295-
296186
def ensure_super_agent_patches_applied() -> None:
297-
"""按需应用全部 Dara SDK 兼容补丁 (幂等)。
187+
"""按需应用 Dara SDK 兼容补丁 (幂等)。
298188
299189
由 ``SuperAgentClient.__init__`` 调用。如果调用方直接使用
300-
``to_create_input`` / ``to_update_input`` 并自己构造 ``CreateAgentRuntimeInput``
301-
/ ``ListAgentRuntimesRequest``, 也应在 Pydantic → Dara 转换前调用一次本函数。
190+
``to_create_input`` / ``to_update_input`` 并自己构造 Dara 输入, 也应在
191+
Pydantic → Dara 转换前调用一次本函数。
302192
"""
303193
_patch_dara_protocol_configuration()
304-
_patch_dara_tags(_DaraCreateAgentRuntimeInput)
305-
_patch_dara_tags(_DaraUpdateAgentRuntimeInput)
306-
# ``ListAgentRuntimesRequest`` 补齐 from_map/to_map 保留属性; 真正让服务端
307-
# 生效的 query 注入由 ``_patch_dara_client_list_tags`` 完成。
308-
_patch_dara_tags(_DaraListAgentRuntimesRequest)
309-
_patch_dara_client_list_tags()
310194

311195

312196
# ─── AgentRuntime ↔ SuperAgent 转换 ────────────────────────
@@ -415,7 +299,7 @@ def to_create_input(
415299
agent_runtime_name=name,
416300
description=description,
417301
protocol_configuration=pc,
418-
tags=list(SUPER_AGENT_CREATE_TAGS),
302+
system_tags=list(SUPER_AGENT_CREATE_TAGS),
419303
# 超级 Agent 的数据面入口 (与 protocolConfiguration.externalEndpoint 同值)。
420304
external_agent_endpoint_url=build_super_agent_endpoint(cfg),
421305
# 占位 artifact: SUPER_AGENT 不跑用户 container/code, 但服务端要求非空。
@@ -446,7 +330,7 @@ def to_update_input(
446330
agent_runtime_name=name,
447331
description=merged.get("description"),
448332
protocol_configuration=pc,
449-
tags=list(SUPER_AGENT_CREATE_TAGS),
333+
system_tags=list(SUPER_AGENT_CREATE_TAGS),
450334
# 超级 Agent 的数据面入口 (与 protocolConfiguration.externalEndpoint 同值)。
451335
external_agent_endpoint_url=build_super_agent_endpoint(cfg),
452336
# 占位 artifact: SUPER_AGENT 不跑用户 container/code, 但服务端要求非空。

agentrun/super_agent/client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
内部持有一个 :class:`AgentRuntimeClient` 实例, 通过 ``api/control.py`` 的
1515
转换函数把 ``SuperAgent`` 与 ``AgentRuntime`` 互相映射。
1616
17-
list 固定按 tag ``x-agentrun-super`` 过滤, 不接受用户自定义 tag。
17+
list 固定按 systemTag ``x-agentrun-super`` 过滤, 不接受用户自定义 tag。
1818
"""
1919

2020
import asyncio
@@ -256,7 +256,7 @@ def _find_rt_by_name(self, name: str, config: Optional[Config]) -> Any:
256256
AgentRuntimeListInput(
257257
page_number=page_number,
258258
page_size=page_size,
259-
tags=SUPER_AGENT_TAG,
259+
system_tags=SUPER_AGENT_TAG,
260260
),
261261
config=cfg,
262262
)
@@ -278,7 +278,7 @@ async def _find_rt_by_name_async(
278278
AgentRuntimeListInput(
279279
page_number=page_number,
280280
page_size=page_size,
281-
tags=SUPER_AGENT_TAG,
281+
system_tags=SUPER_AGENT_TAG,
282282
),
283283
config=cfg,
284284
)
@@ -448,12 +448,12 @@ async def list_async(
448448
page_size: int = 20,
449449
config: Optional[Config] = None,
450450
) -> List[SuperAgent]:
451-
"""异步列出超级 Agent (固定 tag 过滤, 过滤非 SUPER_AGENT)."""
451+
"""异步列出超级 Agent (固定 systemTag 过滤, 过滤非 SUPER_AGENT)."""
452452
cfg = Config.with_configs(self.config, config)
453453
rt_input = AgentRuntimeListInput(
454454
page_number=page_number,
455455
page_size=page_size,
456-
tags=SUPER_AGENT_TAG,
456+
system_tags=SUPER_AGENT_TAG,
457457
)
458458
runtimes = await self._rt.list_async(rt_input, config=cfg)
459459
result: List[SuperAgent] = []
@@ -472,12 +472,12 @@ def list(
472472
page_size: int = 20,
473473
config: Optional[Config] = None,
474474
) -> List[SuperAgent]:
475-
"""同步列出超级 Agent (固定 tag 过滤, 过滤非 SUPER_AGENT)."""
475+
"""同步列出超级 Agent (固定 systemTag 过滤, 过滤非 SUPER_AGENT)."""
476476
cfg = Config.with_configs(self.config, config)
477477
rt_input = AgentRuntimeListInput(
478478
page_number=page_number,
479479
page_size=page_size,
480-
tags=SUPER_AGENT_TAG,
480+
system_tags=SUPER_AGENT_TAG,
481481
)
482482
runtimes = self._rt.list(rt_input, config=cfg)
483483
result: List[SuperAgent] = []

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies = [
1313
"litellm>=1.79.3",
1414
"alibabacloud-devs20230714>=2.4.1",
1515
"pydash>=8.0.5",
16-
"alibabacloud-agentrun20250910>=5.6.0",
16+
"alibabacloud-agentrun20250910>=5.6.1",
1717
"alibabacloud_tea_openapi>=0.4.2",
1818
"alibabacloud_bailian20231229>=2.6.2",
1919
"agentrun-mem0ai>=0.0.10",

0 commit comments

Comments
 (0)