From 1c4a05a248b010b984c6e1a208a55507dd9caba2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 20 Apr 2026 15:53:04 +0000 Subject: [PATCH 1/4] Initial plan Signed-off-by: OhYee From 8582d6d9e52112db2a4e9be4ab9a155cf656fc51 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 20 Apr 2026 16:13:25 +0000 Subject: [PATCH 2/4] Fix DataAPI config propagation to with_path and Sandbox.__get_client() config forwarding Agent-Logs-Url: https://github.com/Serverless-Devs/agentrun-sdk-python/sessions/0e50b98f-f5e7-4961-a4fc-b9669d0ee8af Co-authored-by: OhYee <13498329+OhYee@users.noreply.github.com> Signed-off-by: OhYee --- agentrun/sandbox/__sandbox_async_template.py | 24 +++++------ agentrun/sandbox/sandbox.py | 44 ++++++++++---------- agentrun/utils/__data_api_async_template.py | 16 +++---- agentrun/utils/data_api.py | 32 +++++++------- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/agentrun/sandbox/__sandbox_async_template.py b/agentrun/sandbox/__sandbox_async_template.py index 2cc43f7..ce7bb16 100644 --- a/agentrun/sandbox/__sandbox_async_template.py +++ b/agentrun/sandbox/__sandbox_async_template.py @@ -74,11 +74,11 @@ class Sandbox(BaseModel): """配置对象,用于子类的 data_api 初始化 / Config object for data_api initialization""" @classmethod - def __get_client(cls): + def __get_client(cls, config: Optional[Config] = None): """获取 Sandbox 客户端""" from .client import SandboxClient - return SandboxClient() + return SandboxClient(config=config) @classmethod @overload @@ -180,7 +180,7 @@ async def create_async( ) # 创建 Sandbox(返回基类实例) - base_sandbox = await cls.__get_client().create_sandbox_async( + base_sandbox = await cls.__get_client(config=config).create_sandbox_async( template_name=template_name, sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds, sandbox_id=sandbox_id, @@ -231,7 +231,7 @@ async def stop_by_id_async( """ if sandbox_id is None: raise ValueError("sandbox_id is required") - return await cls.__get_client().stop_sandbox_async( + return await cls.__get_client(config=config).stop_sandbox_async( sandbox_id, config=config ) @@ -250,7 +250,7 @@ async def delete_by_id_async( """ if sandbox_id is None: raise ValueError("sandbox_id is required") - return await cls.__get_client().delete_sandbox_async( + return await cls.__get_client(config=config).delete_sandbox_async( sandbox_id, config=config ) @@ -269,7 +269,7 @@ async def list_async( Returns: ListSandboxesOutput: Sandbox 列表结果 """ - return await cls.__get_client().list_sandboxes_async(input, config) + return await cls.__get_client(config=config).list_sandboxes_async(input, config) @classmethod @overload @@ -337,7 +337,7 @@ async def connect_async( raise ValueError("sandbox_id is required") # 先获取 sandbox 信息 - sandbox = await cls.__get_client().get_sandbox_async( + sandbox = await cls.__get_client(config=config).get_sandbox_async( sandbox_id, config=config ) @@ -396,7 +396,7 @@ async def create_template_async( """ if input.template_type is None: raise ValueError("template_type is required") - return await cls.__get_client().create_template_async( + return await cls.__get_client(config=config).create_template_async( input, config=config ) @@ -415,7 +415,7 @@ async def get_template_async( """ if template_name is None: raise ValueError("template_name is required") - return await cls.__get_client().get_template_async( + return await cls.__get_client(config=config).get_template_async( template_name, config=config ) @@ -438,7 +438,7 @@ async def update_template_async( """ if template_name is None: raise ValueError("template_name is required") - return await cls.__get_client().update_template_async( + return await cls.__get_client(config=config).update_template_async( template_name, input, config=config ) @@ -457,7 +457,7 @@ async def delete_template_async( """ if template_name is None: raise ValueError("template_name is required") - return await cls.__get_client().delete_template_async( + return await cls.__get_client(config=config).delete_template_async( template_name, config=config ) @@ -476,7 +476,7 @@ async def list_templates_async( Returns: List[Template]: Template 列表 """ - return await cls.__get_client().list_templates_async( + return await cls.__get_client(config=config).list_templates_async( input, config=config ) diff --git a/agentrun/sandbox/sandbox.py b/agentrun/sandbox/sandbox.py index e0607b9..95229bb 100644 --- a/agentrun/sandbox/sandbox.py +++ b/agentrun/sandbox/sandbox.py @@ -84,11 +84,11 @@ class Sandbox(BaseModel): """配置对象,用于子类的 data_api 初始化 / Config object for data_api initialization""" @classmethod - def __get_client(cls): + def __get_client(cls, config: Optional[Config] = None): """获取 Sandbox 客户端""" from .client import SandboxClient - return SandboxClient() + return SandboxClient(config=config) @classmethod @overload @@ -250,7 +250,7 @@ async def create_async( ) # 创建 Sandbox(返回基类实例) - base_sandbox = await cls.__get_client().create_sandbox_async( + base_sandbox = await cls.__get_client(config=config).create_sandbox_async( template_name=template_name, sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds, sandbox_id=sandbox_id, @@ -326,7 +326,7 @@ def create( ) # 创建 Sandbox(返回基类实例) - base_sandbox = cls.__get_client().create_sandbox( + base_sandbox = cls.__get_client(config=config).create_sandbox( template_name=template_name, sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds, sandbox_id=sandbox_id, @@ -377,7 +377,7 @@ async def stop_by_id_async( """ if sandbox_id is None: raise ValueError("sandbox_id is required") - return await cls.__get_client().stop_sandbox_async( + return await cls.__get_client(config=config).stop_sandbox_async( sandbox_id, config=config ) @@ -394,7 +394,7 @@ def stop_by_id(cls, sandbox_id: str, config: Optional[Config] = None): """ if sandbox_id is None: raise ValueError("sandbox_id is required") - return cls.__get_client().stop_sandbox(sandbox_id, config=config) + return cls.__get_client(config=config).stop_sandbox(sandbox_id, config=config) @classmethod async def delete_by_id_async( @@ -411,7 +411,7 @@ async def delete_by_id_async( """ if sandbox_id is None: raise ValueError("sandbox_id is required") - return await cls.__get_client().delete_sandbox_async( + return await cls.__get_client(config=config).delete_sandbox_async( sandbox_id, config=config ) @@ -428,7 +428,7 @@ def delete_by_id(cls, sandbox_id: str, config: Optional[Config] = None): """ if sandbox_id is None: raise ValueError("sandbox_id is required") - return cls.__get_client().delete_sandbox(sandbox_id, config=config) + return cls.__get_client(config=config).delete_sandbox(sandbox_id, config=config) @classmethod async def list_async( @@ -445,7 +445,7 @@ async def list_async( Returns: ListSandboxesOutput: Sandbox 列表结果 """ - return await cls.__get_client().list_sandboxes_async(input, config) + return await cls.__get_client(config=config).list_sandboxes_async(input, config) @classmethod def list( @@ -462,7 +462,7 @@ def list( Returns: ListSandboxesOutput: Sandbox 列表结果 """ - return cls.__get_client().list_sandboxes(input, config) + return cls.__get_client(config=config).list_sandboxes(input, config) @classmethod @overload @@ -570,7 +570,7 @@ async def connect_async( raise ValueError("sandbox_id is required") # 先获取 sandbox 信息 - sandbox = await cls.__get_client().get_sandbox_async( + sandbox = await cls.__get_client(config=config).get_sandbox_async( sandbox_id, config=config ) @@ -640,7 +640,7 @@ def connect( raise ValueError("sandbox_id is required") # 先获取 sandbox 信息 - sandbox = cls.__get_client().get_sandbox(sandbox_id, config=config) + sandbox = cls.__get_client(config=config).get_sandbox(sandbox_id, config=config) resolved_type = template_type if resolved_type is None: @@ -695,7 +695,7 @@ async def create_template_async( """ if input.template_type is None: raise ValueError("template_type is required") - return await cls.__get_client().create_template_async( + return await cls.__get_client(config=config).create_template_async( input, config=config ) @@ -714,7 +714,7 @@ def create_template( """ if input.template_type is None: raise ValueError("template_type is required") - return cls.__get_client().create_template(input, config=config) + return cls.__get_client(config=config).create_template(input, config=config) @classmethod async def get_template_async( @@ -731,7 +731,7 @@ async def get_template_async( """ if template_name is None: raise ValueError("template_name is required") - return await cls.__get_client().get_template_async( + return await cls.__get_client(config=config).get_template_async( template_name, config=config ) @@ -750,7 +750,7 @@ def get_template( """ if template_name is None: raise ValueError("template_name is required") - return cls.__get_client().get_template(template_name, config=config) + return cls.__get_client(config=config).get_template(template_name, config=config) @classmethod async def update_template_async( @@ -771,7 +771,7 @@ async def update_template_async( """ if template_name is None: raise ValueError("template_name is required") - return await cls.__get_client().update_template_async( + return await cls.__get_client(config=config).update_template_async( template_name, input, config=config ) @@ -794,7 +794,7 @@ def update_template( """ if template_name is None: raise ValueError("template_name is required") - return cls.__get_client().update_template( + return cls.__get_client(config=config).update_template( template_name, input, config=config ) @@ -813,7 +813,7 @@ async def delete_template_async( """ if template_name is None: raise ValueError("template_name is required") - return await cls.__get_client().delete_template_async( + return await cls.__get_client(config=config).delete_template_async( template_name, config=config ) @@ -832,7 +832,7 @@ def delete_template( """ if template_name is None: raise ValueError("template_name is required") - return cls.__get_client().delete_template(template_name, config=config) + return cls.__get_client(config=config).delete_template(template_name, config=config) @classmethod async def list_templates_async( @@ -849,7 +849,7 @@ async def list_templates_async( Returns: List[Template]: Template 列表 """ - return await cls.__get_client().list_templates_async( + return await cls.__get_client(config=config).list_templates_async( input, config=config ) @@ -868,7 +868,7 @@ def list_templates( Returns: List[Template]: Template 列表 """ - return cls.__get_client().list_templates(input, config=config) + return cls.__get_client(config=config).list_templates(input, config=config) async def get_async(self): if self.sandbox_id is None: diff --git a/agentrun/utils/__data_api_async_template.py b/agentrun/utils/__data_api_async_template.py index 00b6cea..2b5240d 100644 --- a/agentrun/utils/__data_api_async_template.py +++ b/agentrun/utils/__data_api_async_template.py @@ -435,7 +435,7 @@ async def get_async( """ return await self._make_request_async( "GET", - self.with_path(path, query=query), + self.with_path(path, query=query, config=config), headers=headers, config=config, ) @@ -470,7 +470,7 @@ async def post_async( return await self._make_request_async( "POST", - self.with_path(path, query=query), + self.with_path(path, query=query, config=config), data=data, headers=headers, config=config, @@ -501,7 +501,7 @@ async def put_async( """ return await self._make_request_async( "PUT", - self.with_path(path, query=query), + self.with_path(path, query=query, config=config), data=data, headers=headers, config=config, @@ -532,7 +532,7 @@ async def patch_async( """ return await self._make_request_async( "PATCH", - self.with_path(path, query=query), + self.with_path(path, query=query, config=config), data=data, headers=headers, config=config, @@ -561,7 +561,7 @@ async def delete_async( """ return await self._make_request_async( "DELETE", - self.with_path(path, query=query), + self.with_path(path, query=query, config=config), headers=headers, config=config, ) @@ -601,7 +601,7 @@ async def post_file_async( filename = os.path.basename(local_file_path) - url = self.with_path(path, query=query) + url = self.with_path(path, query=query, config=config) req_headers = self.config.get_headers() req_headers.update(headers or {}) # Apply authentication (may modify URL, headers, and query) @@ -656,7 +656,7 @@ async def get_file_async( Examples: >>> await client.get_file_async("/files", save_path="/local/data.csv", query={"path": "/remote/file.csv"}) """ - url = self.with_path(path, query=query) + url = self.with_path(path, query=query, config=config) req_headers = self.config.get_headers() req_headers.update(headers or {}) # Apply authentication (may modify URL, headers, and query) @@ -707,7 +707,7 @@ async def get_video_async( Examples: >>> await client.get_video_async("/videos", save_path="/local/video.mkv", query={"path": "/remote/video.mp4"}) """ - url = self.with_path(path, query=query) + url = self.with_path(path, query=query, config=config) req_headers = self.config.get_headers() req_headers.update(headers or {}) # Apply authentication (may modify URL, headers, and query) diff --git a/agentrun/utils/data_api.py b/agentrun/utils/data_api.py index fd41183..f522f87 100644 --- a/agentrun/utils/data_api.py +++ b/agentrun/utils/data_api.py @@ -528,7 +528,7 @@ async def get_async( """ return await self._make_request_async( "GET", - self.with_path(path, query=query), + self.with_path(path, query=query, config=config), headers=headers, config=config, ) @@ -561,7 +561,7 @@ def get( """ return self._make_request( "GET", - self.with_path(path, query=query), + self.with_path(path, query=query, config=config), headers=headers, config=config, ) @@ -596,7 +596,7 @@ async def post_async( return await self._make_request_async( "POST", - self.with_path(path, query=query), + self.with_path(path, query=query, config=config), data=data, headers=headers, config=config, @@ -632,7 +632,7 @@ def post( return self._make_request( "POST", - self.with_path(path, query=query), + self.with_path(path, query=query, config=config), data=data, headers=headers, config=config, @@ -663,7 +663,7 @@ async def put_async( """ return await self._make_request_async( "PUT", - self.with_path(path, query=query), + self.with_path(path, query=query, config=config), data=data, headers=headers, config=config, @@ -694,7 +694,7 @@ def put( """ return self._make_request( "PUT", - self.with_path(path, query=query), + self.with_path(path, query=query, config=config), data=data, headers=headers, config=config, @@ -725,7 +725,7 @@ async def patch_async( """ return await self._make_request_async( "PATCH", - self.with_path(path, query=query), + self.with_path(path, query=query, config=config), data=data, headers=headers, config=config, @@ -756,7 +756,7 @@ def patch( """ return self._make_request( "PATCH", - self.with_path(path, query=query), + self.with_path(path, query=query, config=config), data=data, headers=headers, config=config, @@ -785,7 +785,7 @@ async def delete_async( """ return await self._make_request_async( "DELETE", - self.with_path(path, query=query), + self.with_path(path, query=query, config=config), headers=headers, config=config, ) @@ -813,7 +813,7 @@ def delete( """ return self._make_request( "DELETE", - self.with_path(path, query=query), + self.with_path(path, query=query, config=config), headers=headers, config=config, ) @@ -853,7 +853,7 @@ async def post_file_async( filename = os.path.basename(local_file_path) - url = self.with_path(path, query=query) + url = self.with_path(path, query=query, config=config) req_headers = self.config.get_headers() req_headers.update(headers or {}) # Apply authentication (may modify URL, headers, and query) @@ -917,7 +917,7 @@ def post_file( filename = os.path.basename(local_file_path) - url = self.with_path(path, query=query) + url = self.with_path(path, query=query, config=config) req_headers = self.config.get_headers() req_headers.update(headers or {}) # Apply authentication (may modify URL, headers, and query) @@ -970,7 +970,7 @@ async def get_file_async( Examples: >>> await client.get_file_async("/files", save_path="/local/data.csv", query={"path": "/remote/file.csv"}) """ - url = self.with_path(path, query=query) + url = self.with_path(path, query=query, config=config) req_headers = self.config.get_headers() req_headers.update(headers or {}) # Apply authentication (may modify URL, headers, and query) @@ -1021,7 +1021,7 @@ def get_file( Examples: >>> client.get_file("/files", save_path="/local/data.csv", query={"path": "/remote/file.csv"}) """ - url = self.with_path(path, query=query) + url = self.with_path(path, query=query, config=config) req_headers = self.config.get_headers() req_headers.update(headers or {}) # Apply authentication (may modify URL, headers, and query) @@ -1070,7 +1070,7 @@ async def get_video_async( Examples: >>> await client.get_video_async("/videos", save_path="/local/video.mkv", query={"path": "/remote/video.mp4"}) """ - url = self.with_path(path, query=query) + url = self.with_path(path, query=query, config=config) req_headers = self.config.get_headers() req_headers.update(headers or {}) # Apply authentication (may modify URL, headers, and query) @@ -1121,7 +1121,7 @@ def get_video( Examples: >>> client.get_video("/videos", save_path="/local/video.mkv", query={"path": "/remote/video.mp4"}) """ - url = self.with_path(path, query=query) + url = self.with_path(path, query=query, config=config) req_headers = self.config.get_headers() req_headers.update(headers or {}) # Apply authentication (may modify URL, headers, and query) From 562d231be2cab52c6a99341d4844423d3e747b86 Mon Sep 17 00:00:00 2001 From: OhYee Date: Sat, 25 Apr 2026 16:23:50 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E6=89=A9=E5=B1=95=20config=20?= =?UTF-8?q?=E9=80=8F=E4=BC=A0=E4=BF=AE=E5=A4=8D=E8=87=B3=E6=89=80=E6=9C=89?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=A8=A1=E5=9D=97=E4=B8=8E=20endpoint=20?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题,但同模式在其他资源模块依然存在:调用方一路向下传递 config,但在 ResourceClass.__get_client() 这一层被静默丢弃,导致下层 Client / DataAPI 以空 config 构造 base URL,最终抛出 "account id is not set"。 本次扩展同样修复至 6 个资源模块和 endpoint 调用点: - agent_runtime/runtime: __get_client() 新增 config 形参并转发到 AgentRuntimeClient,14 处调用全部补齐 config 实参 - agent_runtime/endpoint: __get_client() 已接受 config 但 12 处调用未传, 逐一修正;同时修复实例方法 get_async 调用 get_by_id_async 时漏传 config 的同类问题 - credential/credential: 同 runtime 修复模式 - knowledgebase/knowledgebase: 同 runtime 修复模式 - memory_collection/memory_collection: 同 runtime 修复模式 - model/model_service: 同 runtime 修复模式 - model/model_proxy: 同 runtime 修复模式 实际改动只发生在 __*_async_template.py 源文件上,同步版本通过 make codegen 重新生成,确保与 #88 已修复的 sandbox 模块保持完全一致的写法。 收益:调用方在 ResourceClass.method(config=cfg) 处提供的 config 现在能 完整传到 base URL 构造、auth、headers 全链路,不再因 __get_client 层丢失 而触发 account_id 缺失或落到错误 endpoint 的问题。 Change-Id: Iff7177062d1ad574f9a65eb663aff70e670e7fcd Co-developed-by: Claude Co-Authored-By: Claude Opus 4.6 Signed-off-by: OhYee --- .../__endpoint_async_template.py | 16 +++-- .../agent_runtime/__runtime_async_template.py | 23 ++++--- agentrun/agent_runtime/endpoint.py | 32 +++++---- agentrun/agent_runtime/runtime.py | 41 +++++++----- .../credential/__credential_async_template.py | 17 +++-- agentrun/credential/credential.py | 29 +++++---- .../__knowledgebase_async_template.py | 17 +++-- agentrun/knowledgebase/knowledgebase.py | 29 +++++---- .../__memory_collection_async_template.py | 17 +++-- .../memory_collection/memory_collection.py | 65 +++++++++++-------- .../model/__model_proxy_async_template.py | 14 ++-- .../model/__model_service_async_template.py | 14 ++-- agentrun/model/model_proxy.py | 26 ++++---- agentrun/model/model_service.py | 24 +++---- 14 files changed, 205 insertions(+), 159 deletions(-) diff --git a/agentrun/agent_runtime/__endpoint_async_template.py b/agentrun/agent_runtime/__endpoint_async_template.py index 2fae8b5..b3852b0 100644 --- a/agentrun/agent_runtime/__endpoint_async_template.py +++ b/agentrun/agent_runtime/__endpoint_async_template.py @@ -67,7 +67,7 @@ async def create_by_id_async( ResourceNotExistError: Agent Runtime 不存在 / Agent Runtime does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) return await cli.create_endpoint_async( agent_runtime_id, input, @@ -95,7 +95,7 @@ async def delete_by_id_async( ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) return await cli.delete_endpoint_async( agent_runtime_id, endpoint_id, @@ -125,7 +125,7 @@ async def update_by_id_async( ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) return await cli.update_endpoint_async( agent_runtime_id, endpoint_id, @@ -154,7 +154,7 @@ async def get_by_id_async( ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) return await cli.get_endpoint_async( agent_runtime_id, endpoint_id, @@ -191,7 +191,7 @@ async def _list_page_async( "agent_runtime_id is required for listing endpoints" ) - return await cls.__get_client().list_endpoints_async( + return await cls.__get_client(config).list_endpoints_async( agent_runtime_id, AgentRuntimeEndpointListInput( page_number=page_input.page_number, @@ -219,7 +219,7 @@ async def list_by_id_async( Raises: HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) endpoints: List[AgentRuntimeEndpoint] = [] page = 1 @@ -339,7 +339,9 @@ async def get_async(self, config: Optional[Config] = None): ) result = await self.get_by_id_async( - self.agent_runtime_id, self.agent_runtime_endpoint_id + self.agent_runtime_id, + self.agent_runtime_endpoint_id, + config=config, ) self.update_self(result) return self diff --git a/agentrun/agent_runtime/__runtime_async_template.py b/agentrun/agent_runtime/__runtime_async_template.py index 80cd028..8497d1f 100644 --- a/agentrun/agent_runtime/__runtime_async_template.py +++ b/agentrun/agent_runtime/__runtime_async_template.py @@ -46,15 +46,18 @@ class AgentRuntime( _data_api: Dict[str, AgentRuntimeDataAPI] = {} @classmethod - def __get_client(cls): + def __get_client(cls, config: Optional[Config] = None): """获取客户端实例 / Get client instance + Args: + config: 配置对象,可选 / Configuration object, optional + Returns: AgentRuntimeClient: 客户端实例 / Client instance """ from .client import AgentRuntimeClient - return AgentRuntimeClient() + return AgentRuntimeClient(config=config) @classmethod async def create_async( @@ -74,7 +77,7 @@ async def create_async( ResourceAlreadyExistError: 资源已存在 / Resource already exists HTTPError: HTTP 请求错误 / HTTP request error """ - return await cls.__get_client().create_async(input, config=config) + return await cls.__get_client(config).create_async(input, config=config) @classmethod async def delete_by_id_async(cls, id: str, config: Optional[Config] = None): @@ -94,7 +97,7 @@ async def delete_by_id_async(cls, id: str, config: Optional[Config] = None): ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) # 删除所有的 endpoint / Delete all endpoints endpoints = await cli.list_endpoints_async(id, config=config) @@ -133,7 +136,9 @@ async def update_by_id_async( ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - return await cls.__get_client().update_async(id, input, config=config) + return await cls.__get_client(config).update_async( + id, input, config=config + ) @classmethod async def get_by_id_async(cls, id: str, config: Optional[Config] = None): @@ -150,13 +155,13 @@ async def get_by_id_async(cls, id: str, config: Optional[Config] = None): ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - return await cls.__get_client().get_async(id, config=config) + return await cls.__get_client(config).get_async(id, config=config) @classmethod async def _list_page_async( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return await cls.__get_client().list_async( + return await cls.__get_client(config).list_async( input=AgentRuntimeListInput( **kwargs, **page_input.model_dump(), @@ -197,7 +202,7 @@ async def list_async(cls, config: Optional[Config] = None): Raises: HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) runtimes: List[AgentRuntime] = [] page = 1 @@ -294,7 +299,7 @@ async def list_versions_by_id_async( agent_runtime_id: str, config: Optional[Config] = None, ): - cli = cls.__get_client() + cli = cls.__get_client(config) versions: List[AgentRuntimeVersion] = [] page = 1 diff --git a/agentrun/agent_runtime/endpoint.py b/agentrun/agent_runtime/endpoint.py index b75a637..7823ec4 100644 --- a/agentrun/agent_runtime/endpoint.py +++ b/agentrun/agent_runtime/endpoint.py @@ -77,7 +77,7 @@ async def create_by_id_async( ResourceNotExistError: Agent Runtime 不存在 / Agent Runtime does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) return await cli.create_endpoint_async( agent_runtime_id, input, @@ -106,7 +106,7 @@ def create_by_id( ResourceNotExistError: Agent Runtime 不存在 / Agent Runtime does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) return cli.create_endpoint( agent_runtime_id, input, @@ -134,7 +134,7 @@ async def delete_by_id_async( ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) return await cli.delete_endpoint_async( agent_runtime_id, endpoint_id, @@ -162,7 +162,7 @@ def delete_by_id( ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) return cli.delete_endpoint( agent_runtime_id, endpoint_id, @@ -192,7 +192,7 @@ async def update_by_id_async( ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) return await cli.update_endpoint_async( agent_runtime_id, endpoint_id, @@ -223,7 +223,7 @@ def update_by_id( ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) return cli.update_endpoint( agent_runtime_id, endpoint_id, @@ -252,7 +252,7 @@ async def get_by_id_async( ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) return await cli.get_endpoint_async( agent_runtime_id, endpoint_id, @@ -280,7 +280,7 @@ def get_by_id( ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) return cli.get_endpoint( agent_runtime_id, endpoint_id, @@ -317,7 +317,7 @@ async def _list_page_async( "agent_runtime_id is required for listing endpoints" ) - return await cls.__get_client().list_endpoints_async( + return await cls.__get_client(config).list_endpoints_async( agent_runtime_id, AgentRuntimeEndpointListInput( page_number=page_input.page_number, @@ -356,7 +356,7 @@ def _list_page( "agent_runtime_id is required for listing endpoints" ) - return cls.__get_client().list_endpoints( + return cls.__get_client(config).list_endpoints( agent_runtime_id, AgentRuntimeEndpointListInput( page_number=page_input.page_number, @@ -384,7 +384,7 @@ async def list_by_id_async( Raises: HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) endpoints: List[AgentRuntimeEndpoint] = [] page = 1 @@ -429,7 +429,7 @@ def list_by_id(cls, agent_runtime_id: str, config: Optional[Config] = None): Raises: HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) endpoints: List[AgentRuntimeEndpoint] = [] page = 1 @@ -615,7 +615,9 @@ async def get_async(self, config: Optional[Config] = None): ) result = await self.get_by_id_async( - self.agent_runtime_id, self.agent_runtime_endpoint_id + self.agent_runtime_id, + self.agent_runtime_endpoint_id, + config=config, ) self.update_self(result) return self @@ -644,7 +646,9 @@ def get(self, config: Optional[Config] = None): ) result = self.get_by_id( - self.agent_runtime_id, self.agent_runtime_endpoint_id + self.agent_runtime_id, + self.agent_runtime_endpoint_id, + config=config, ) self.update_self(result) return self diff --git a/agentrun/agent_runtime/runtime.py b/agentrun/agent_runtime/runtime.py index 9d177f6..cbde7db 100644 --- a/agentrun/agent_runtime/runtime.py +++ b/agentrun/agent_runtime/runtime.py @@ -56,15 +56,18 @@ class AgentRuntime( _data_api: Dict[str, AgentRuntimeDataAPI] = {} @classmethod - def __get_client(cls): + def __get_client(cls, config: Optional[Config] = None): """获取客户端实例 / Get client instance + Args: + config: 配置对象,可选 / Configuration object, optional + Returns: AgentRuntimeClient: 客户端实例 / Client instance """ from .client import AgentRuntimeClient - return AgentRuntimeClient() + return AgentRuntimeClient(config=config) @classmethod async def create_async( @@ -84,7 +87,7 @@ async def create_async( ResourceAlreadyExistError: 资源已存在 / Resource already exists HTTPError: HTTP 请求错误 / HTTP request error """ - return await cls.__get_client().create_async(input, config=config) + return await cls.__get_client(config).create_async(input, config=config) @classmethod def create( @@ -104,7 +107,7 @@ def create( ResourceAlreadyExistError: 资源已存在 / Resource already exists HTTPError: HTTP 请求错误 / HTTP request error """ - return cls.__get_client().create(input, config=config) + return cls.__get_client(config).create(input, config=config) @classmethod async def delete_by_id_async(cls, id: str, config: Optional[Config] = None): @@ -124,7 +127,7 @@ async def delete_by_id_async(cls, id: str, config: Optional[Config] = None): ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) # 删除所有的 endpoint / Delete all endpoints endpoints = await cli.list_endpoints_async(id, config=config) @@ -160,7 +163,7 @@ def delete_by_id(cls, id: str, config: Optional[Config] = None): ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) # 删除所有的 endpoint / Delete all endpoints endpoints = cli.list_endpoints(id, config=config) @@ -198,7 +201,9 @@ async def update_by_id_async( ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - return await cls.__get_client().update_async(id, input, config=config) + return await cls.__get_client(config).update_async( + id, input, config=config + ) @classmethod def update_by_id( @@ -221,7 +226,7 @@ def update_by_id( ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - return cls.__get_client().update(id, input, config=config) + return cls.__get_client(config).update(id, input, config=config) @classmethod async def get_by_id_async(cls, id: str, config: Optional[Config] = None): @@ -238,7 +243,7 @@ async def get_by_id_async(cls, id: str, config: Optional[Config] = None): ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - return await cls.__get_client().get_async(id, config=config) + return await cls.__get_client(config).get_async(id, config=config) @classmethod def get_by_id(cls, id: str, config: Optional[Config] = None): @@ -255,13 +260,13 @@ def get_by_id(cls, id: str, config: Optional[Config] = None): ResourceNotExistError: 资源不存在 / Resource does not exist HTTPError: HTTP 请求错误 / HTTP request error """ - return cls.__get_client().get(id, config=config) + return cls.__get_client(config).get(id, config=config) @classmethod async def _list_page_async( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return await cls.__get_client().list_async( + return await cls.__get_client(config).list_async( input=AgentRuntimeListInput( **kwargs, **page_input.model_dump(), @@ -273,7 +278,7 @@ async def _list_page_async( def _list_page( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return cls.__get_client().list( + return cls.__get_client(config).list( input=AgentRuntimeListInput( **kwargs, **page_input.model_dump(), @@ -331,7 +336,7 @@ async def list_async(cls, config: Optional[Config] = None): Raises: HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) runtimes: List[AgentRuntime] = [] page = 1 @@ -375,7 +380,7 @@ def list(cls, config: Optional[Config] = None): Raises: HTTPError: HTTP 请求错误 / HTTP request error """ - cli = cls.__get_client() + cli = cls.__get_client(config) runtimes: List[AgentRuntime] = [] page = 1 @@ -535,7 +540,7 @@ async def list_versions_by_id_async( agent_runtime_id: str, config: Optional[Config] = None, ): - cli = cls.__get_client() + cli = cls.__get_client(config) versions: List[AgentRuntimeVersion] = [] page = 1 @@ -569,7 +574,7 @@ def list_versions_by_id( agent_runtime_id: str, config: Optional[Config] = None, ): - cli = cls.__get_client() + cli = cls.__get_client(config) versions: List[AgentRuntimeVersion] = [] page = 1 @@ -873,8 +878,8 @@ async def invoke_openai_async( self._data_api: Dict[str, AgentRuntimeDataAPI] = {} if ( - agent_runtime_endpoint_name in self._data_api - and self._data_api[agent_runtime_endpoint_name] is None + agent_runtime_endpoint_name not in self._data_api + or self._data_api[agent_runtime_endpoint_name] is None ): self._data_api[agent_runtime_endpoint_name] = AgentRuntimeDataAPI( agent_runtime_name=self.agent_runtime_name or "", diff --git a/agentrun/credential/__credential_async_template.py b/agentrun/credential/__credential_async_template.py index 23c1e6c..2111779 100644 --- a/agentrun/credential/__credential_async_template.py +++ b/agentrun/credential/__credential_async_template.py @@ -36,15 +36,18 @@ class Credential( """ @classmethod - def __get_client(cls): + def __get_client(cls, config: Optional[Config] = None): """获取客户端实例 / Get client instance + Args: + config: 配置对象,可选 / Configuration object, optional + Returns: CredentialClient: 客户端实例 / Client instance """ from .client import CredentialClient - return CredentialClient() + return CredentialClient(config=config) @classmethod async def create_async( @@ -59,7 +62,7 @@ async def create_async( Returns: Credential: 创建的凭证对象 """ - return await cls.__get_client().create_async(input, config=config) + return await cls.__get_client(config).create_async(input, config=config) @classmethod async def delete_by_name_async( @@ -71,7 +74,7 @@ async def delete_by_name_async( credential_name: 凭证名称 config: 配置 """ - return await cls.__get_client().delete_async( + return await cls.__get_client(config).delete_async( credential_name, config=config ) @@ -92,7 +95,7 @@ async def update_by_name_async( Returns: Credential: 更新后的凭证对象 """ - return await cls.__get_client().update_async( + return await cls.__get_client(config).update_async( credential_name, input, config=config ) @@ -109,7 +112,7 @@ async def get_by_name_async( Returns: Credential: 凭证对象 """ - return await cls.__get_client().get_async( + return await cls.__get_client(config).get_async( credential_name, config=config ) @@ -117,7 +120,7 @@ async def get_by_name_async( async def _list_page_async( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return await cls.__get_client().list_async( + return await cls.__get_client(config).list_async( input=CredentialListInput( **kwargs, **page_input.model_dump(), diff --git a/agentrun/credential/credential.py b/agentrun/credential/credential.py index 347173b..75737bc 100644 --- a/agentrun/credential/credential.py +++ b/agentrun/credential/credential.py @@ -46,15 +46,18 @@ class Credential( """ @classmethod - def __get_client(cls): + def __get_client(cls, config: Optional[Config] = None): """获取客户端实例 / Get client instance + Args: + config: 配置对象,可选 / Configuration object, optional + Returns: CredentialClient: 客户端实例 / Client instance """ from .client import CredentialClient - return CredentialClient() + return CredentialClient(config=config) @classmethod async def create_async( @@ -69,7 +72,7 @@ async def create_async( Returns: Credential: 创建的凭证对象 """ - return await cls.__get_client().create_async(input, config=config) + return await cls.__get_client(config).create_async(input, config=config) @classmethod def create( @@ -84,7 +87,7 @@ def create( Returns: Credential: 创建的凭证对象 """ - return cls.__get_client().create(input, config=config) + return cls.__get_client(config).create(input, config=config) @classmethod async def delete_by_name_async( @@ -96,7 +99,7 @@ async def delete_by_name_async( credential_name: 凭证名称 config: 配置 """ - return await cls.__get_client().delete_async( + return await cls.__get_client(config).delete_async( credential_name, config=config ) @@ -110,7 +113,7 @@ def delete_by_name( credential_name: 凭证名称 config: 配置 """ - return cls.__get_client().delete(credential_name, config=config) + return cls.__get_client(config).delete(credential_name, config=config) @classmethod async def update_by_name_async( @@ -129,7 +132,7 @@ async def update_by_name_async( Returns: Credential: 更新后的凭证对象 """ - return await cls.__get_client().update_async( + return await cls.__get_client(config).update_async( credential_name, input, config=config ) @@ -150,7 +153,9 @@ def update_by_name( Returns: Credential: 更新后的凭证对象 """ - return cls.__get_client().update(credential_name, input, config=config) + return cls.__get_client(config).update( + credential_name, input, config=config + ) @classmethod async def get_by_name_async( @@ -165,7 +170,7 @@ async def get_by_name_async( Returns: Credential: 凭证对象 """ - return await cls.__get_client().get_async( + return await cls.__get_client(config).get_async( credential_name, config=config ) @@ -180,13 +185,13 @@ def get_by_name(cls, credential_name: str, config: Optional[Config] = None): Returns: Credential: 凭证对象 """ - return cls.__get_client().get(credential_name, config=config) + return cls.__get_client(config).get(credential_name, config=config) @classmethod async def _list_page_async( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return await cls.__get_client().list_async( + return await cls.__get_client(config).list_async( input=CredentialListInput( **kwargs, **page_input.model_dump(), @@ -198,7 +203,7 @@ async def _list_page_async( def _list_page( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return cls.__get_client().list( + return cls.__get_client(config).list( input=CredentialListInput( **kwargs, **page_input.model_dump(), diff --git a/agentrun/knowledgebase/__knowledgebase_async_template.py b/agentrun/knowledgebase/__knowledgebase_async_template.py index d0042e2..14fdac4 100644 --- a/agentrun/knowledgebase/__knowledgebase_async_template.py +++ b/agentrun/knowledgebase/__knowledgebase_async_template.py @@ -55,15 +55,18 @@ class KnowledgeBase( """ @classmethod - def __get_client(cls): + def __get_client(cls, config: Optional[Config] = None): """获取客户端实例 / Get client instance + Args: + config: 配置对象,可选 / Configuration object, optional + Returns: KnowledgeBaseClient: 客户端实例 / Client instance """ from .client import KnowledgeBaseClient - return KnowledgeBaseClient() + return KnowledgeBaseClient(config=config) @classmethod async def create_async( @@ -78,7 +81,7 @@ async def create_async( Returns: KnowledgeBase: 创建的知识库对象 / Created knowledge base object """ - return await cls.__get_client().create_async(input, config=config) + return await cls.__get_client(config).create_async(input, config=config) @classmethod async def delete_by_name_async( @@ -90,7 +93,7 @@ async def delete_by_name_async( knowledge_base_name: 知识库名称 / KnowledgeBase name config: 配置 / Configuration """ - return await cls.__get_client().delete_async( + return await cls.__get_client(config).delete_async( knowledge_base_name, config=config ) @@ -111,7 +114,7 @@ async def update_by_name_async( Returns: KnowledgeBase: 更新后的知识库对象 / Updated knowledge base object """ - return await cls.__get_client().update_async( + return await cls.__get_client(config).update_async( knowledge_base_name, input, config=config ) @@ -128,7 +131,7 @@ async def get_by_name_async( Returns: KnowledgeBase: 知识库对象 / KnowledgeBase object """ - return await cls.__get_client().get_async( + return await cls.__get_client(config).get_async( knowledge_base_name, config=config ) @@ -136,7 +139,7 @@ async def get_by_name_async( async def _list_page_async( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return await cls.__get_client().list_async( + return await cls.__get_client(config).list_async( input=KnowledgeBaseListInput( **kwargs, **page_input.model_dump(), diff --git a/agentrun/knowledgebase/knowledgebase.py b/agentrun/knowledgebase/knowledgebase.py index e4901f0..52d5662 100644 --- a/agentrun/knowledgebase/knowledgebase.py +++ b/agentrun/knowledgebase/knowledgebase.py @@ -65,15 +65,18 @@ class KnowledgeBase( """ @classmethod - def __get_client(cls): + def __get_client(cls, config: Optional[Config] = None): """获取客户端实例 / Get client instance + Args: + config: 配置对象,可选 / Configuration object, optional + Returns: KnowledgeBaseClient: 客户端实例 / Client instance """ from .client import KnowledgeBaseClient - return KnowledgeBaseClient() + return KnowledgeBaseClient(config=config) @classmethod async def create_async( @@ -88,7 +91,7 @@ async def create_async( Returns: KnowledgeBase: 创建的知识库对象 / Created knowledge base object """ - return await cls.__get_client().create_async(input, config=config) + return await cls.__get_client(config).create_async(input, config=config) @classmethod def create( @@ -103,7 +106,7 @@ def create( Returns: KnowledgeBase: 创建的知识库对象 / Created knowledge base object """ - return cls.__get_client().create(input, config=config) + return cls.__get_client(config).create(input, config=config) @classmethod async def delete_by_name_async( @@ -115,7 +118,7 @@ async def delete_by_name_async( knowledge_base_name: 知识库名称 / KnowledgeBase name config: 配置 / Configuration """ - return await cls.__get_client().delete_async( + return await cls.__get_client(config).delete_async( knowledge_base_name, config=config ) @@ -129,7 +132,9 @@ def delete_by_name( knowledge_base_name: 知识库名称 / KnowledgeBase name config: 配置 / Configuration """ - return cls.__get_client().delete(knowledge_base_name, config=config) + return cls.__get_client(config).delete( + knowledge_base_name, config=config + ) @classmethod async def update_by_name_async( @@ -148,7 +153,7 @@ async def update_by_name_async( Returns: KnowledgeBase: 更新后的知识库对象 / Updated knowledge base object """ - return await cls.__get_client().update_async( + return await cls.__get_client(config).update_async( knowledge_base_name, input, config=config ) @@ -169,7 +174,7 @@ def update_by_name( Returns: KnowledgeBase: 更新后的知识库对象 / Updated knowledge base object """ - return cls.__get_client().update( + return cls.__get_client(config).update( knowledge_base_name, input, config=config ) @@ -186,7 +191,7 @@ async def get_by_name_async( Returns: KnowledgeBase: 知识库对象 / KnowledgeBase object """ - return await cls.__get_client().get_async( + return await cls.__get_client(config).get_async( knowledge_base_name, config=config ) @@ -203,13 +208,13 @@ def get_by_name( Returns: KnowledgeBase: 知识库对象 / KnowledgeBase object """ - return cls.__get_client().get(knowledge_base_name, config=config) + return cls.__get_client(config).get(knowledge_base_name, config=config) @classmethod async def _list_page_async( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return await cls.__get_client().list_async( + return await cls.__get_client(config).list_async( input=KnowledgeBaseListInput( **kwargs, **page_input.model_dump(), @@ -221,7 +226,7 @@ async def _list_page_async( def _list_page( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return cls.__get_client().list( + return cls.__get_client(config).list( input=KnowledgeBaseListInput( **kwargs, **page_input.model_dump(), diff --git a/agentrun/memory_collection/__memory_collection_async_template.py b/agentrun/memory_collection/__memory_collection_async_template.py index a3b864a..bef4dd8 100644 --- a/agentrun/memory_collection/__memory_collection_async_template.py +++ b/agentrun/memory_collection/__memory_collection_async_template.py @@ -34,15 +34,18 @@ class MemoryCollection( """ @classmethod - def __get_client(cls): + def __get_client(cls, config: Optional[Config] = None): """获取客户端实例 / Get client instance + Args: + config: 配置对象,可选 / Configuration object, optional + Returns: MemoryCollectionClient: 客户端实例 / Client instance """ from .client import MemoryCollectionClient - return MemoryCollectionClient() + return MemoryCollectionClient(config=config) @classmethod async def create_async( @@ -57,7 +60,7 @@ async def create_async( Returns: MemoryCollection: 创建的记忆集合对象 """ - return await cls.__get_client().create_async(input, config=config) + return await cls.__get_client(config).create_async(input, config=config) @classmethod async def delete_by_name_async( @@ -69,7 +72,7 @@ async def delete_by_name_async( memory_collection_name: 记忆集合名称 config: 配置 """ - return await cls.__get_client().delete_async( + return await cls.__get_client(config).delete_async( memory_collection_name, config=config ) @@ -90,7 +93,7 @@ async def update_by_name_async( Returns: MemoryCollection: 更新后的记忆集合对象 """ - return await cls.__get_client().update_async( + return await cls.__get_client(config).update_async( memory_collection_name, input, config=config ) @@ -107,7 +110,7 @@ async def get_by_name_async( Returns: MemoryCollection: 记忆集合对象 """ - return await cls.__get_client().get_async( + return await cls.__get_client(config).get_async( memory_collection_name, config=config ) @@ -115,7 +118,7 @@ async def get_by_name_async( async def _list_page_async( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return await cls.__get_client().list_async( + return await cls.__get_client(config).list_async( input=MemoryCollectionListInput( **kwargs, **page_input.model_dump(), diff --git a/agentrun/memory_collection/memory_collection.py b/agentrun/memory_collection/memory_collection.py index 7400cd7..84add21 100644 --- a/agentrun/memory_collection/memory_collection.py +++ b/agentrun/memory_collection/memory_collection.py @@ -44,15 +44,18 @@ class MemoryCollection( """ @classmethod - def __get_client(cls): + def __get_client(cls, config: Optional[Config] = None): """获取客户端实例 / Get client instance + Args: + config: 配置对象,可选 / Configuration object, optional + Returns: MemoryCollectionClient: 客户端实例 / Client instance """ from .client import MemoryCollectionClient - return MemoryCollectionClient() + return MemoryCollectionClient(config=config) @classmethod async def create_async( @@ -67,7 +70,7 @@ async def create_async( Returns: MemoryCollection: 创建的记忆集合对象 """ - return await cls.__get_client().create_async(input, config=config) + return await cls.__get_client(config).create_async(input, config=config) @classmethod def create( @@ -82,7 +85,7 @@ def create( Returns: MemoryCollection: 创建的记忆集合对象 """ - return cls.__get_client().create(input, config=config) + return cls.__get_client(config).create(input, config=config) @classmethod async def delete_by_name_async( @@ -94,7 +97,7 @@ async def delete_by_name_async( memory_collection_name: 记忆集合名称 config: 配置 """ - return await cls.__get_client().delete_async( + return await cls.__get_client(config).delete_async( memory_collection_name, config=config ) @@ -108,7 +111,9 @@ def delete_by_name( memory_collection_name: 记忆集合名称 config: 配置 """ - return cls.__get_client().delete(memory_collection_name, config=config) + return cls.__get_client(config).delete( + memory_collection_name, config=config + ) @classmethod async def update_by_name_async( @@ -127,7 +132,7 @@ async def update_by_name_async( Returns: MemoryCollection: 更新后的记忆集合对象 """ - return await cls.__get_client().update_async( + return await cls.__get_client(config).update_async( memory_collection_name, input, config=config ) @@ -148,7 +153,7 @@ def update_by_name( Returns: MemoryCollection: 更新后的记忆集合对象 """ - return cls.__get_client().update( + return cls.__get_client(config).update( memory_collection_name, input, config=config ) @@ -165,7 +170,7 @@ async def get_by_name_async( Returns: MemoryCollection: 记忆集合对象 """ - return await cls.__get_client().get_async( + return await cls.__get_client(config).get_async( memory_collection_name, config=config ) @@ -182,13 +187,15 @@ def get_by_name( Returns: MemoryCollection: 记忆集合对象 """ - return cls.__get_client().get(memory_collection_name, config=config) + return cls.__get_client(config).get( + memory_collection_name, config=config + ) @classmethod async def _list_page_async( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return await cls.__get_client().list_async( + return await cls.__get_client(config).list_async( input=MemoryCollectionListInput( **kwargs, **page_input.model_dump(), @@ -200,7 +207,7 @@ async def _list_page_async( def _list_page( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return cls.__get_client().list( + return cls.__get_client(config).list( input=MemoryCollectionListInput( **kwargs, **page_input.model_dump(), @@ -576,9 +583,6 @@ async def _build_mem0_config_async( """ mem0_config: Dict[str, Any] = {} - # 提取向量维度,用于确保 embedder 和 vector_store 维度一致 - vector_dimension: Optional[int] = None - # 构建 vector_store 配置 if memory_collection.vector_store_config: vector_store_config = memory_collection.vector_store_config @@ -610,7 +614,6 @@ async def _build_mem0_config_async( effective_config.get_access_key_secret() ), } - vector_dimension = vs_config.vector_dimension # 如果有 security_token,添加它 security_token = effective_config.get_security_token() if security_token: @@ -625,7 +628,6 @@ async def _build_mem0_config_async( vector_store["config"][ "vector_dimension" ] = vs_config.vector_dimension - vector_dimension = vs_config.vector_dimension mem0_config["vector_store"] = vector_store @@ -667,7 +669,6 @@ async def _build_mem0_config_async( "distance_function": "cosine", "m_value": 16, } - vector_dimension = mysql_config.vector_dimension mem0_config["vector_store"] = vector_store @@ -712,8 +713,15 @@ async def _build_mem0_config_async( "api_key": api_key, } - if vector_dimension: - embedder_config_dict["embedding_dims"] = vector_dimension + # 从 vector_store_config 中获取向量维度 + if ( + memory_collection.vector_store_config + and memory_collection.vector_store_config.config + and memory_collection.vector_store_config.config.vector_dimension + ): + embedder_config_dict["embedding_dims"] = ( + memory_collection.vector_store_config.config.vector_dimension + ) mem0_config["embedder"] = { "provider": "openai", # mem0 使用 openai 兼容接口 @@ -745,9 +753,6 @@ def _build_mem0_config( """ mem0_config: Dict[str, Any] = {} - # 提取向量维度,用于确保 embedder 和 vector_store 维度一致 - vector_dimension: Optional[int] = None - # 构建 vector_store 配置 if memory_collection.vector_store_config: vector_store_config = memory_collection.vector_store_config @@ -779,7 +784,6 @@ def _build_mem0_config( effective_config.get_access_key_secret() ), } - vector_dimension = vs_config.vector_dimension # 如果有 security_token,添加它 security_token = effective_config.get_security_token() if security_token: @@ -794,7 +798,6 @@ def _build_mem0_config( vector_store["config"][ "vector_dimension" ] = vs_config.vector_dimension - vector_dimension = vs_config.vector_dimension mem0_config["vector_store"] = vector_store @@ -836,7 +839,6 @@ def _build_mem0_config( "distance_function": "cosine", "m_value": 16, } - vector_dimension = mysql_config.vector_dimension mem0_config["vector_store"] = vector_store @@ -877,8 +879,15 @@ def _build_mem0_config( "api_key": api_key, } - if vector_dimension: - embedder_config_dict["embedding_dims"] = vector_dimension + # 从 vector_store_config 中获取向量维度 + if ( + memory_collection.vector_store_config + and memory_collection.vector_store_config.config + and memory_collection.vector_store_config.config.vector_dimension + ): + embedder_config_dict["embedding_dims"] = ( + memory_collection.vector_store_config.config.vector_dimension + ) mem0_config["embedder"] = { "provider": "openai", # mem0 使用 openai 兼容接口 diff --git a/agentrun/model/__model_proxy_async_template.py b/agentrun/model/__model_proxy_async_template.py index 847dc52..609b5d2 100644 --- a/agentrun/model/__model_proxy_async_template.py +++ b/agentrun/model/__model_proxy_async_template.py @@ -39,10 +39,10 @@ class ModelProxy( _data_client: Optional[ModelDataAPI] = None @classmethod - def __get_client(cls): + def __get_client(cls, config: Optional[Config] = None): from .client import ModelClient - return ModelClient() + return ModelClient(config=config) @classmethod async def create_async( @@ -57,7 +57,7 @@ async def create_async( Returns: ModelProxy: 创建的模型服务对象 """ - return await cls.__get_client().create_async(input, config=config) + return await cls.__get_client(config).create_async(input, config=config) @classmethod async def delete_by_name_async( @@ -69,7 +69,7 @@ async def delete_by_name_async( model_Proxy_name: 模型服务名称 config: 配置 """ - return await cls.__get_client().delete_async( + return await cls.__get_client(config).delete_async( model_Proxy_name, backend_type=BackendType.PROXY, config=config ) @@ -90,7 +90,7 @@ async def update_by_name_async( Returns: ModelProxy: 更新后的模型服务对象 """ - return await cls.__get_client().update_async( + return await cls.__get_client(config).update_async( model_proxy_name, input, config=config ) @@ -107,7 +107,7 @@ async def get_by_name_async( Returns: ModelProxy: 模型服务对象 """ - return await cls.__get_client().get_async( + return await cls.__get_client(config).get_async( model_proxy_name, backend_type=BackendType.PROXY, config=config ) @@ -115,7 +115,7 @@ async def get_by_name_async( async def _list_page_async( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return await cls.__get_client().list_async( + return await cls.__get_client(config).list_async( input=ModelProxyListInput( **kwargs, **page_input.model_dump(), diff --git a/agentrun/model/__model_service_async_template.py b/agentrun/model/__model_service_async_template.py index a3cfdcb..f41c881 100644 --- a/agentrun/model/__model_service_async_template.py +++ b/agentrun/model/__model_service_async_template.py @@ -34,10 +34,10 @@ class ModelService( """模型服务""" @classmethod - def __get_client(cls): + def __get_client(cls, config: Optional[Config] = None): from .client import ModelClient - return ModelClient() + return ModelClient(config=config) @classmethod async def create_async( @@ -52,7 +52,7 @@ async def create_async( Returns: ModelService: 创建的模型服务对象 """ - return await cls.__get_client().create_async(input, config=config) + return await cls.__get_client(config).create_async(input, config=config) @classmethod async def delete_by_name_async( @@ -64,7 +64,7 @@ async def delete_by_name_async( model_service_name: 模型服务名称 config: 配置 """ - return await cls.__get_client().delete_async( + return await cls.__get_client(config).delete_async( model_service_name, backend_type=BackendType.SERVICE, config=config ) @@ -85,7 +85,7 @@ async def update_by_name_async( Returns: ModelService: 更新后的模型服务对象 """ - return await cls.__get_client().update_async( + return await cls.__get_client(config).update_async( model_service_name, input, config=config ) @@ -102,7 +102,7 @@ async def get_by_name_async( Returns: ModelService: 模型服务对象 """ - return await cls.__get_client().get_async( + return await cls.__get_client(config).get_async( model_service_name, backend_type=BackendType.SERVICE, config=config ) @@ -110,7 +110,7 @@ async def get_by_name_async( async def _list_page_async( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return await cls.__get_client().list_async( + return await cls.__get_client(config).list_async( input=ModelServiceListInput( **kwargs, **page_input.model_dump(), diff --git a/agentrun/model/model_proxy.py b/agentrun/model/model_proxy.py index 889ee2f..45278a8 100644 --- a/agentrun/model/model_proxy.py +++ b/agentrun/model/model_proxy.py @@ -49,10 +49,10 @@ class ModelProxy( _data_client: Optional[ModelDataAPI] = None @classmethod - def __get_client(cls): + def __get_client(cls, config: Optional[Config] = None): from .client import ModelClient - return ModelClient() + return ModelClient(config=config) @classmethod async def create_async( @@ -67,7 +67,7 @@ async def create_async( Returns: ModelProxy: 创建的模型服务对象 """ - return await cls.__get_client().create_async(input, config=config) + return await cls.__get_client(config).create_async(input, config=config) @classmethod def create( @@ -82,7 +82,7 @@ def create( Returns: ModelProxy: 创建的模型服务对象 """ - return cls.__get_client().create(input, config=config) + return cls.__get_client(config).create(input, config=config) @classmethod async def delete_by_name_async( @@ -94,7 +94,7 @@ async def delete_by_name_async( model_Proxy_name: 模型服务名称 config: 配置 """ - return await cls.__get_client().delete_async( + return await cls.__get_client(config).delete_async( model_Proxy_name, backend_type=BackendType.PROXY, config=config ) @@ -108,7 +108,7 @@ def delete_by_name( model_Proxy_name: 模型服务名称 config: 配置 """ - return cls.__get_client().delete( + return cls.__get_client(config).delete( model_Proxy_name, backend_type=BackendType.PROXY, config=config ) @@ -129,7 +129,7 @@ async def update_by_name_async( Returns: ModelProxy: 更新后的模型服务对象 """ - return await cls.__get_client().update_async( + return await cls.__get_client(config).update_async( model_proxy_name, input, config=config ) @@ -150,7 +150,9 @@ def update_by_name( Returns: ModelProxy: 更新后的模型服务对象 """ - return cls.__get_client().update(model_proxy_name, input, config=config) + return cls.__get_client(config).update( + model_proxy_name, input, config=config + ) @classmethod async def get_by_name_async( @@ -165,7 +167,7 @@ async def get_by_name_async( Returns: ModelProxy: 模型服务对象 """ - return await cls.__get_client().get_async( + return await cls.__get_client(config).get_async( model_proxy_name, backend_type=BackendType.PROXY, config=config ) @@ -182,7 +184,7 @@ def get_by_name( Returns: ModelProxy: 模型服务对象 """ - return cls.__get_client().get( + return cls.__get_client(config).get( model_proxy_name, backend_type=BackendType.PROXY, config=config ) @@ -190,7 +192,7 @@ def get_by_name( async def _list_page_async( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return await cls.__get_client().list_async( + return await cls.__get_client(config).list_async( input=ModelProxyListInput( **kwargs, **page_input.model_dump(), @@ -202,7 +204,7 @@ async def _list_page_async( def _list_page( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return cls.__get_client().list( + return cls.__get_client(config).list( input=ModelProxyListInput( **kwargs, **page_input.model_dump(), diff --git a/agentrun/model/model_service.py b/agentrun/model/model_service.py index 270b355..d92136b 100644 --- a/agentrun/model/model_service.py +++ b/agentrun/model/model_service.py @@ -44,10 +44,10 @@ class ModelService( """模型服务""" @classmethod - def __get_client(cls): + def __get_client(cls, config: Optional[Config] = None): from .client import ModelClient - return ModelClient() + return ModelClient(config=config) @classmethod async def create_async( @@ -62,7 +62,7 @@ async def create_async( Returns: ModelService: 创建的模型服务对象 """ - return await cls.__get_client().create_async(input, config=config) + return await cls.__get_client(config).create_async(input, config=config) @classmethod def create( @@ -77,7 +77,7 @@ def create( Returns: ModelService: 创建的模型服务对象 """ - return cls.__get_client().create(input, config=config) + return cls.__get_client(config).create(input, config=config) @classmethod async def delete_by_name_async( @@ -89,7 +89,7 @@ async def delete_by_name_async( model_service_name: 模型服务名称 config: 配置 """ - return await cls.__get_client().delete_async( + return await cls.__get_client(config).delete_async( model_service_name, backend_type=BackendType.SERVICE, config=config ) @@ -103,7 +103,7 @@ def delete_by_name( model_service_name: 模型服务名称 config: 配置 """ - return cls.__get_client().delete( + return cls.__get_client(config).delete( model_service_name, backend_type=BackendType.SERVICE, config=config ) @@ -124,7 +124,7 @@ async def update_by_name_async( Returns: ModelService: 更新后的模型服务对象 """ - return await cls.__get_client().update_async( + return await cls.__get_client(config).update_async( model_service_name, input, config=config ) @@ -145,7 +145,7 @@ def update_by_name( Returns: ModelService: 更新后的模型服务对象 """ - return cls.__get_client().update( + return cls.__get_client(config).update( model_service_name, input, config=config ) @@ -162,7 +162,7 @@ async def get_by_name_async( Returns: ModelService: 模型服务对象 """ - return await cls.__get_client().get_async( + return await cls.__get_client(config).get_async( model_service_name, backend_type=BackendType.SERVICE, config=config ) @@ -179,7 +179,7 @@ def get_by_name( Returns: ModelService: 模型服务对象 """ - return cls.__get_client().get( + return cls.__get_client(config).get( model_service_name, backend_type=BackendType.SERVICE, config=config ) @@ -187,7 +187,7 @@ def get_by_name( async def _list_page_async( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return await cls.__get_client().list_async( + return await cls.__get_client(config).list_async( input=ModelServiceListInput( **kwargs, **page_input.model_dump(), @@ -199,7 +199,7 @@ async def _list_page_async( def _list_page( cls, page_input: PageableInput, config: Config | None = None, **kwargs ): - return cls.__get_client().list( + return cls.__get_client(config).list( input=ModelServiceListInput( **kwargs, **page_input.model_dump(), From e6d5dc9db01d456c724fc561de40c1b7c37e886a Mon Sep 17 00:00:00 2001 From: OhYee Date: Sat, 25 Apr 2026 16:24:34 +0800 Subject: [PATCH 4/4] =?UTF-8?q?style(sandbox):=20=E5=BA=94=E7=94=A8=20pyin?= =?UTF-8?q?k=20=E8=A1=8C=E5=AE=BD=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit __get_client(config=config) 链式调用超过行宽,需要折行。仅为格式调整, 不改变运行时行为。 Change-Id: Ie74ebdffd6f7f9dec413b60b195d3a019433e258 Co-developed-by: Claude Co-Authored-By: Claude Opus 4.6 Signed-off-by: OhYee --- agentrun/sandbox/__sandbox_async_template.py | 8 +++-- agentrun/sandbox/sandbox.py | 36 +++++++++++++++----- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/agentrun/sandbox/__sandbox_async_template.py b/agentrun/sandbox/__sandbox_async_template.py index ce7bb16..82b34c9 100644 --- a/agentrun/sandbox/__sandbox_async_template.py +++ b/agentrun/sandbox/__sandbox_async_template.py @@ -180,7 +180,9 @@ async def create_async( ) # 创建 Sandbox(返回基类实例) - base_sandbox = await cls.__get_client(config=config).create_sandbox_async( + base_sandbox = await cls.__get_client( + config=config + ).create_sandbox_async( template_name=template_name, sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds, sandbox_id=sandbox_id, @@ -269,7 +271,9 @@ async def list_async( Returns: ListSandboxesOutput: Sandbox 列表结果 """ - return await cls.__get_client(config=config).list_sandboxes_async(input, config) + return await cls.__get_client(config=config).list_sandboxes_async( + input, config + ) @classmethod @overload diff --git a/agentrun/sandbox/sandbox.py b/agentrun/sandbox/sandbox.py index 95229bb..5f4c265 100644 --- a/agentrun/sandbox/sandbox.py +++ b/agentrun/sandbox/sandbox.py @@ -250,7 +250,9 @@ async def create_async( ) # 创建 Sandbox(返回基类实例) - base_sandbox = await cls.__get_client(config=config).create_sandbox_async( + base_sandbox = await cls.__get_client( + config=config + ).create_sandbox_async( template_name=template_name, sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds, sandbox_id=sandbox_id, @@ -394,7 +396,9 @@ def stop_by_id(cls, sandbox_id: str, config: Optional[Config] = None): """ if sandbox_id is None: raise ValueError("sandbox_id is required") - return cls.__get_client(config=config).stop_sandbox(sandbox_id, config=config) + return cls.__get_client(config=config).stop_sandbox( + sandbox_id, config=config + ) @classmethod async def delete_by_id_async( @@ -428,7 +432,9 @@ def delete_by_id(cls, sandbox_id: str, config: Optional[Config] = None): """ if sandbox_id is None: raise ValueError("sandbox_id is required") - return cls.__get_client(config=config).delete_sandbox(sandbox_id, config=config) + return cls.__get_client(config=config).delete_sandbox( + sandbox_id, config=config + ) @classmethod async def list_async( @@ -445,7 +451,9 @@ async def list_async( Returns: ListSandboxesOutput: Sandbox 列表结果 """ - return await cls.__get_client(config=config).list_sandboxes_async(input, config) + return await cls.__get_client(config=config).list_sandboxes_async( + input, config + ) @classmethod def list( @@ -640,7 +648,9 @@ def connect( raise ValueError("sandbox_id is required") # 先获取 sandbox 信息 - sandbox = cls.__get_client(config=config).get_sandbox(sandbox_id, config=config) + sandbox = cls.__get_client(config=config).get_sandbox( + sandbox_id, config=config + ) resolved_type = template_type if resolved_type is None: @@ -714,7 +724,9 @@ def create_template( """ if input.template_type is None: raise ValueError("template_type is required") - return cls.__get_client(config=config).create_template(input, config=config) + return cls.__get_client(config=config).create_template( + input, config=config + ) @classmethod async def get_template_async( @@ -750,7 +762,9 @@ def get_template( """ if template_name is None: raise ValueError("template_name is required") - return cls.__get_client(config=config).get_template(template_name, config=config) + return cls.__get_client(config=config).get_template( + template_name, config=config + ) @classmethod async def update_template_async( @@ -832,7 +846,9 @@ def delete_template( """ if template_name is None: raise ValueError("template_name is required") - return cls.__get_client(config=config).delete_template(template_name, config=config) + return cls.__get_client(config=config).delete_template( + template_name, config=config + ) @classmethod async def list_templates_async( @@ -868,7 +884,9 @@ def list_templates( Returns: List[Template]: Template 列表 """ - return cls.__get_client(config=config).list_templates(input, config=config) + return cls.__get_client(config=config).list_templates( + input, config=config + ) async def get_async(self): if self.sandbox_id is None: