Skip to content

Commit 651caaa

Browse files
congxiao-wxxclaude
andcommitted
feat(sdk): add workspace_id support across all SDK modules
Thread workspace_id parameter through all SDK resource clients and high-level APIs: agent_runtime, conversation_service, credential, knowledgebase, memory_collection, model, sandbox, super_agent, tool, toolset, and shared utilities. Change-Id: I9fc53cafa8237df8872de352115181c72414ef98 Co-developed-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: congxiao.wxx <congxiao.wxx@alibaba-inc.com>
1 parent 5d5d91e commit 651caaa

35 files changed

Lines changed: 852 additions & 199 deletions

agentrun/agent_runtime/api/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
当前文件为自动生成的控制 API 客户端代码。请勿手动修改此文件。
77
使用 `make codegen` 命令重新生成。
88
9-
source: agentrun/agent_runtime/api/__data_async_template.py
9+
source: .claude/worktrees/infallible-pasteur-94186e/agentrun/agent_runtime/api/__data_async_template.py
1010
"""
1111

1212
from typing import Iterable, Optional, TypedDict

agentrun/agent_runtime/client.py

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
当前文件为自动生成的控制 API 客户端代码。请勿手动修改此文件。
77
使用 `make codegen` 命令重新生成。
88
9-
source: agentrun/agent_runtime/__client_async_template.py
9+
source: .claude/worktrees/infallible-pasteur-94186e/agentrun/agent_runtime/__client_async_template.py
1010
1111
Agent Runtime 客户端 / Agent Runtime Client
1212
@@ -180,7 +180,9 @@ async def delete_async(
180180
except HTTPError as e:
181181
raise e.to_resource_error("AgentRuntime", id) from e
182182

183-
def delete(self, id: str, config: Optional[Config] = None) -> AgentRuntime:
183+
def delete(
184+
self, id: str, config: Optional[Config] = None
185+
) -> AgentRuntime:
184186
"""同步删除 Agent Runtime / Delete Agent Runtime synchronously
185187
186188
Args:
@@ -195,7 +197,9 @@ def delete(self, id: str, config: Optional[Config] = None) -> AgentRuntime:
195197
HTTPError: HTTP 请求错误 / HTTP request error
196198
"""
197199
try:
198-
result = self.__control_api.delete_agent_runtime(id, config=config)
200+
result = self.__control_api.delete_agent_runtime(
201+
id, config=config
202+
)
199203
# Delete 响应只有 agentRuntimeId 有效,其他字段为空字符串/零值,
200204
# 走 from_inner_object 会在 status/artifactType 等 Enum 字段上触发
201205
# 伪校验错误。这里直接构造一个只带 id 的极简对象。
@@ -443,12 +447,14 @@ def create_endpoint(
443447
HTTPError: HTTP 请求错误 / HTTP request error
444448
"""
445449
try:
446-
result = self.__control_api.create_agent_runtime_endpoint(
447-
agent_runtime_id,
448-
CreateAgentRuntimeEndpointInput().from_map(
449-
endpoint.model_dump()
450-
),
451-
config=config,
450+
result = (
451+
self.__control_api.create_agent_runtime_endpoint(
452+
agent_runtime_id,
453+
CreateAgentRuntimeEndpointInput().from_map(
454+
endpoint.model_dump()
455+
),
456+
config=config,
457+
)
452458
)
453459
except HTTPError as e:
454460
raise e.to_resource_error(
@@ -521,10 +527,12 @@ def delete_endpoint(
521527
HTTPError: HTTP 请求错误 / HTTP request error
522528
"""
523529
try:
524-
result = self.__control_api.delete_agent_runtime_endpoint(
525-
agent_runtime_id,
526-
endpoint_id,
527-
config=config,
530+
result = (
531+
self.__control_api.delete_agent_runtime_endpoint(
532+
agent_runtime_id,
533+
endpoint_id,
534+
config=config,
535+
)
528536
)
529537
except HTTPError as e:
530538
raise e.to_resource_error(
@@ -604,13 +612,15 @@ def update_endpoint(
604612
HTTPError: HTTP 请求错误 / HTTP request error
605613
"""
606614
try:
607-
result = self.__control_api.update_agent_runtime_endpoint(
608-
agent_runtime_id,
609-
endpoint_id,
610-
UpdateAgentRuntimeEndpointInput().from_map(
611-
endpoint.model_dump()
612-
),
613-
config=config,
615+
result = (
616+
self.__control_api.update_agent_runtime_endpoint(
617+
agent_runtime_id,
618+
endpoint_id,
619+
UpdateAgentRuntimeEndpointInput().from_map(
620+
endpoint.model_dump()
621+
),
622+
config=config,
623+
)
614624
)
615625
except HTTPError as e:
616626
raise e.to_resource_error(
@@ -759,10 +769,14 @@ def list_endpoints(
759769
if input is None:
760770
input = AgentRuntimeEndpointListInput()
761771

762-
results = self.__control_api.list_agent_runtime_endpoints(
763-
agent_runtime_id,
764-
ListAgentRuntimeEndpointsRequest().from_map(input.model_dump()),
765-
config=config,
772+
results = (
773+
self.__control_api.list_agent_runtime_endpoints(
774+
agent_runtime_id,
775+
ListAgentRuntimeEndpointsRequest().from_map(
776+
input.model_dump()
777+
),
778+
config=config,
779+
)
766780
)
767781
return [
768782
AgentRuntimeEndpoint.from_inner_object(item)
@@ -833,10 +847,14 @@ def list_versions(
833847
if input is None:
834848
input = AgentRuntimeVersionListInput()
835849

836-
results = self.__control_api.list_agent_runtime_versions(
837-
agent_runtime_id,
838-
ListAgentRuntimeVersionsRequest().from_map(input.model_dump()),
839-
config=config,
850+
results = (
851+
self.__control_api.list_agent_runtime_versions(
852+
agent_runtime_id,
853+
ListAgentRuntimeVersionsRequest().from_map(
854+
input.model_dump()
855+
),
856+
config=config,
857+
)
840858
)
841859
return [
842860
AgentRuntimeVersion.from_inner_object(item)

agentrun/agent_runtime/endpoint.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
当前文件为自动生成的控制 API 客户端代码。请勿手动修改此文件。
77
使用 `make codegen` 命令重新生成。
88
9-
source: agentrun/agent_runtime/__endpoint_async_template.py
9+
source: .claude/worktrees/infallible-pasteur-94186e/agentrun/agent_runtime/__endpoint_async_template.py
1010
1111
Agent Runtime 端点资源 / Agent Runtime Endpoint Resource
1212
@@ -413,7 +413,9 @@ async def list_by_id_async(
413413
return results
414414

415415
@classmethod
416-
def list_by_id(cls, agent_runtime_id: str, config: Optional[Config] = None):
416+
def list_by_id(
417+
cls, agent_runtime_id: str, config: Optional[Config] = None
418+
):
417419
"""根据 Agent Runtime ID 同步列出所有端点 / List all endpoints by Agent Runtime ID synchronously
418420
419421
此方法会自动分页获取所有端点并去重。
@@ -488,7 +490,9 @@ async def delete_async(
488490
self.update_self(result)
489491
return self
490492

491-
def delete(self, config: Optional[Config] = None) -> "AgentRuntimeEndpoint":
493+
def delete(
494+
self, config: Optional[Config] = None
495+
) -> "AgentRuntimeEndpoint":
492496
"""同步删除当前端点 / Delete current endpoint synchronously
493497
494498
Args:
@@ -719,7 +723,9 @@ def invoke_openai(self, **kwargs: Unpack[InvokeArgs]):
719723
if self.__data_api is None:
720724
if not self.__agent_runtime_name:
721725
client = self.__get_client(cfg)
722-
ar = client.get(id=self.agent_runtime_id or "", config=cfg)
726+
ar = client.get(
727+
id=self.agent_runtime_id or "", config=cfg
728+
)
723729
self.__agent_runtime_name = ar.agent_runtime_name
724730

725731
self.__data_api = AgentRuntimeDataAPI(

agentrun/agent_runtime/runtime.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
当前文件为自动生成的控制 API 客户端代码。请勿手动修改此文件。
77
使用 `make codegen` 命令重新生成。
88
9-
source: agentrun/agent_runtime/__runtime_async_template.py
9+
source: .claude/worktrees/infallible-pasteur-94186e/agentrun/agent_runtime/__runtime_async_template.py
1010
1111
Agent Runtime 高层 API / Agent Runtime High-Level API
1212
@@ -172,6 +172,7 @@ def delete_by_id(cls, id: str, config: Optional[Config] = None):
172172

173173
# 等待所有端点删除完成 / Wait for all endpoints to be deleted
174174
while len(cli.list_endpoints(id, config=config)) > 0:
175+
175176

176177
time.sleep(1)
177178

@@ -226,7 +227,9 @@ def update_by_id(
226227
ResourceNotExistError: 资源不存在 / Resource does not exist
227228
HTTPError: HTTP 请求错误 / HTTP request error
228229
"""
229-
return cls.__get_client(config=config).update(id, input, config=config)
230+
return cls.__get_client(config=config).update(
231+
id, input, config=config
232+
)
230233

231234
@classmethod
232235
async def get_by_id_async(cls, id: str, config: Optional[Config] = None):
@@ -620,7 +623,9 @@ def delete(self, config: Optional[Config] = None):
620623
"agent_runtime_id is required to delete an Agent Runtime"
621624
)
622625

623-
result = self.delete_by_id(self.agent_runtime_id, config=config)
626+
result = self.delete_by_id(
627+
self.agent_runtime_id, config=config
628+
)
624629
self.update_self(result)
625630
return self
626631

@@ -670,7 +675,9 @@ def get(self, config: Optional[Config] = None):
670675
"agent_runtime_id is required to get an Agent Runtime"
671676
)
672677

673-
result = self.get_by_id(self.agent_runtime_id, config=config)
678+
result = self.get_by_id(
679+
self.agent_runtime_id, config=config
680+
)
674681
self.update_self(result)
675682
return self
676683

@@ -912,6 +919,6 @@ def invoke_openai(
912919
config=cfg,
913920
)
914921

915-
return self._data_api[agent_runtime_endpoint_name].invoke_openai(
916-
**kwargs
917-
)
922+
return self._data_api[
923+
agent_runtime_endpoint_name
924+
].invoke_openai(**kwargs)

agentrun/conversation_service/ots_backend.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
当前文件为自动生成的控制 API 客户端代码。请勿手动修改此文件。
77
使用 `make codegen` 命令重新生成。
88
9-
source: agentrun/conversation_service/__ots_backend_async_template.py
9+
source: .claude/worktrees/infallible-pasteur-94186e/agentrun/conversation_service/__ots_backend_async_template.py
1010
1111
OTS 存储后端。
1212
@@ -1175,7 +1175,9 @@ def put_session(self, session: ConversationSession) -> None:
11751175

11761176
row = Row(primary_key, attribute_columns)
11771177
condition = Condition(RowExistenceExpectation.IGNORE)
1178-
self._client.put_row(self._conversation_table, row, condition)
1178+
self._client.put_row(
1179+
self._conversation_table, row, condition
1180+
)
11791181

11801182
async def get_session_async(
11811183
self,
@@ -1257,7 +1259,9 @@ def delete_session_row(
12571259
]
12581260
row = Row(primary_key)
12591261
condition = Condition(RowExistenceExpectation.IGNORE)
1260-
self._client.delete_row(self._conversation_table, row, condition)
1262+
self._client.delete_row(
1263+
self._conversation_table, row, condition
1264+
)
12611265

12621266
async def update_session_async(
12631267
self,
@@ -1333,7 +1337,9 @@ def update_session(
13331337
ComparatorType.EQUAL,
13341338
),
13351339
)
1336-
self._client.update_row(self._conversation_table, row, condition)
1340+
self._client.update_row(
1341+
self._conversation_table, row, condition
1342+
)
13371343

13381344
async def list_sessions_async(
13391345
self,
@@ -2411,7 +2417,9 @@ def put_state(
24112417
# 如果是更新(version > 0),需要清理旧的分片列
24122418
delete_cols: list[str] = []
24132419
if version > 0:
2414-
old_chunk_count = self._get_chunk_count(table_name, primary_key)
2420+
old_chunk_count = self._get_chunk_count(
2421+
table_name, primary_key
2422+
)
24152423

24162424
if new_chunk_count == 0 and old_chunk_count > 0:
24172425
# 旧的有分片,新的不分片:删除所有 state_N 列
@@ -3093,7 +3101,9 @@ def put_checkpoint_blob(
30933101
]
30943102
row = Row(primary_key, attribute_columns)
30953103
condition = Condition(RowExistenceExpectation.IGNORE)
3096-
self._client.put_row(self._checkpoint_blobs_table, row, condition)
3104+
self._client.put_row(
3105+
self._checkpoint_blobs_table, row, condition
3106+
)
30973107

30983108
async def get_checkpoint_blobs_async(
30993109
self,

0 commit comments

Comments
 (0)