agentscope-runtime 1.0.4a1__py3-none-any.whl → 1.0.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentscope_runtime/adapters/agentscope/stream.py +2 -8
- agentscope_runtime/adapters/langgraph/stream.py +120 -70
- agentscope_runtime/adapters/ms_agent_framework/__init__.py +0 -0
- agentscope_runtime/adapters/ms_agent_framework/message.py +205 -0
- agentscope_runtime/adapters/ms_agent_framework/stream.py +418 -0
- agentscope_runtime/adapters/utils.py +6 -0
- agentscope_runtime/cli/commands/deploy.py +836 -1
- agentscope_runtime/cli/commands/stop.py +16 -0
- agentscope_runtime/common/container_clients/__init__.py +52 -0
- agentscope_runtime/common/container_clients/agentrun_client.py +6 -4
- agentscope_runtime/common/container_clients/boxlite_client.py +442 -0
- agentscope_runtime/common/container_clients/docker_client.py +0 -20
- agentscope_runtime/common/container_clients/fc_client.py +6 -4
- agentscope_runtime/common/container_clients/gvisor_client.py +38 -0
- agentscope_runtime/common/container_clients/knative_client.py +467 -0
- agentscope_runtime/common/utils/deprecation.py +164 -0
- agentscope_runtime/engine/__init__.py +4 -0
- agentscope_runtime/engine/app/agent_app.py +16 -4
- agentscope_runtime/engine/constant.py +1 -0
- agentscope_runtime/engine/deployers/__init__.py +34 -11
- agentscope_runtime/engine/deployers/adapter/__init__.py +8 -0
- agentscope_runtime/engine/deployers/adapter/a2a/__init__.py +26 -51
- agentscope_runtime/engine/deployers/adapter/a2a/a2a_protocol_adapter.py +23 -13
- agentscope_runtime/engine/deployers/adapter/a2a/a2a_registry.py +4 -201
- agentscope_runtime/engine/deployers/adapter/a2a/nacos_a2a_registry.py +152 -25
- agentscope_runtime/engine/deployers/adapter/agui/__init__.py +8 -0
- agentscope_runtime/engine/deployers/adapter/agui/agui_adapter_utils.py +652 -0
- agentscope_runtime/engine/deployers/adapter/agui/agui_protocol_adapter.py +225 -0
- agentscope_runtime/engine/deployers/agentrun_deployer.py +2 -2
- agentscope_runtime/engine/deployers/fc_deployer.py +1506 -0
- agentscope_runtime/engine/deployers/knative_deployer.py +290 -0
- agentscope_runtime/engine/deployers/pai_deployer.py +2335 -0
- agentscope_runtime/engine/deployers/utils/net_utils.py +37 -0
- agentscope_runtime/engine/deployers/utils/oss_utils.py +38 -0
- agentscope_runtime/engine/deployers/utils/package.py +46 -42
- agentscope_runtime/engine/helpers/agent_api_client.py +372 -0
- agentscope_runtime/engine/runner.py +13 -0
- agentscope_runtime/engine/schemas/agent_schemas.py +9 -3
- agentscope_runtime/engine/services/agent_state/__init__.py +7 -0
- agentscope_runtime/engine/services/memory/__init__.py +7 -0
- agentscope_runtime/engine/services/memory/redis_memory_service.py +15 -16
- agentscope_runtime/engine/services/session_history/__init__.py +7 -0
- agentscope_runtime/engine/tracing/local_logging_handler.py +2 -3
- agentscope_runtime/engine/tracing/wrapper.py +18 -4
- agentscope_runtime/sandbox/__init__.py +14 -6
- agentscope_runtime/sandbox/box/base/__init__.py +2 -2
- agentscope_runtime/sandbox/box/base/base_sandbox.py +51 -1
- agentscope_runtime/sandbox/box/browser/__init__.py +2 -2
- agentscope_runtime/sandbox/box/browser/browser_sandbox.py +198 -2
- agentscope_runtime/sandbox/box/filesystem/__init__.py +2 -2
- agentscope_runtime/sandbox/box/filesystem/filesystem_sandbox.py +99 -2
- agentscope_runtime/sandbox/box/gui/__init__.py +2 -2
- agentscope_runtime/sandbox/box/gui/gui_sandbox.py +117 -1
- agentscope_runtime/sandbox/box/mobile/__init__.py +2 -2
- agentscope_runtime/sandbox/box/mobile/mobile_sandbox.py +247 -100
- agentscope_runtime/sandbox/box/sandbox.py +102 -65
- agentscope_runtime/sandbox/box/shared/routers/generic.py +36 -29
- agentscope_runtime/sandbox/client/__init__.py +6 -1
- agentscope_runtime/sandbox/client/async_http_client.py +339 -0
- agentscope_runtime/sandbox/client/base.py +74 -0
- agentscope_runtime/sandbox/client/http_client.py +108 -329
- agentscope_runtime/sandbox/enums.py +7 -0
- agentscope_runtime/sandbox/manager/sandbox_manager.py +275 -29
- agentscope_runtime/sandbox/manager/server/app.py +7 -1
- agentscope_runtime/sandbox/manager/server/config.py +3 -1
- agentscope_runtime/sandbox/model/manager_config.py +11 -9
- agentscope_runtime/tools/modelstudio_memory/__init__.py +106 -0
- agentscope_runtime/tools/modelstudio_memory/base.py +220 -0
- agentscope_runtime/tools/modelstudio_memory/config.py +86 -0
- agentscope_runtime/tools/modelstudio_memory/core.py +594 -0
- agentscope_runtime/tools/modelstudio_memory/exceptions.py +60 -0
- agentscope_runtime/tools/modelstudio_memory/schemas.py +253 -0
- agentscope_runtime/version.py +1 -1
- {agentscope_runtime-1.0.4a1.dist-info → agentscope_runtime-1.0.5.dist-info}/METADATA +186 -73
- {agentscope_runtime-1.0.4a1.dist-info → agentscope_runtime-1.0.5.dist-info}/RECORD +79 -55
- {agentscope_runtime-1.0.4a1.dist-info → agentscope_runtime-1.0.5.dist-info}/WHEEL +0 -0
- {agentscope_runtime-1.0.4a1.dist-info → agentscope_runtime-1.0.5.dist-info}/entry_points.txt +0 -0
- {agentscope_runtime-1.0.4a1.dist-info → agentscope_runtime-1.0.5.dist-info}/licenses/LICENSE +0 -0
- {agentscope_runtime-1.0.4a1.dist-info → agentscope_runtime-1.0.5.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Base class for ModelStudio Memory components.
|
|
4
|
+
"""
|
|
5
|
+
import logging
|
|
6
|
+
from types import TracebackType
|
|
7
|
+
from typing import Any, Dict, Optional, Type
|
|
8
|
+
|
|
9
|
+
import aiohttp
|
|
10
|
+
|
|
11
|
+
from .config import (
|
|
12
|
+
MemoryServiceConfig,
|
|
13
|
+
)
|
|
14
|
+
from .exceptions import (
|
|
15
|
+
MemoryAPIError,
|
|
16
|
+
MemoryAuthenticationError,
|
|
17
|
+
MemoryNetworkError,
|
|
18
|
+
MemoryNotFoundError,
|
|
19
|
+
MemoryValidationError,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
logger = logging.getLogger(__name__)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ModelStudioMemoryBase:
|
|
26
|
+
"""
|
|
27
|
+
Base class for ModelStudio Memory API components.
|
|
28
|
+
|
|
29
|
+
This class provides common functionality for all memory components,
|
|
30
|
+
including:
|
|
31
|
+
- Configuration management
|
|
32
|
+
- HTTP request handling with error handling
|
|
33
|
+
- Common headers generation
|
|
34
|
+
- Session management
|
|
35
|
+
|
|
36
|
+
Attributes:
|
|
37
|
+
config: Configuration for the memory service
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
def __init__(self, config: Optional[MemoryServiceConfig] = None):
|
|
41
|
+
"""
|
|
42
|
+
Initialize the base memory component.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
config: Optional configuration. If not provided, will be loaded
|
|
46
|
+
from environment variables.
|
|
47
|
+
|
|
48
|
+
Raises:
|
|
49
|
+
ValueError: If required configuration is missing
|
|
50
|
+
"""
|
|
51
|
+
self.config = config or MemoryServiceConfig.from_env()
|
|
52
|
+
self._session: Optional[aiohttp.ClientSession] = None
|
|
53
|
+
|
|
54
|
+
def _get_headers(self) -> Dict[str, str]:
|
|
55
|
+
"""
|
|
56
|
+
Get common HTTP headers for API requests.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
Dictionary of HTTP headers
|
|
60
|
+
"""
|
|
61
|
+
return {
|
|
62
|
+
"Content-Type": "application/json",
|
|
63
|
+
"User-Agent": "agentscope-runtime",
|
|
64
|
+
"Authorization": f"Bearer {self.config.api_key}",
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async def _get_session(self) -> aiohttp.ClientSession:
|
|
68
|
+
"""
|
|
69
|
+
Get or create an aiohttp session.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
An aiohttp ClientSession
|
|
73
|
+
"""
|
|
74
|
+
if self._session is None or self._session.closed:
|
|
75
|
+
self._session = aiohttp.ClientSession()
|
|
76
|
+
return self._session
|
|
77
|
+
|
|
78
|
+
async def _request(
|
|
79
|
+
self,
|
|
80
|
+
method: str,
|
|
81
|
+
url: str,
|
|
82
|
+
**kwargs: Any,
|
|
83
|
+
) -> Dict[str, Any]:
|
|
84
|
+
"""
|
|
85
|
+
Common HTTP request handler with comprehensive error handling.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
method: HTTP method (GET, POST, DELETE, etc.)
|
|
89
|
+
url: Request URL
|
|
90
|
+
**kwargs: Additional arguments for the request
|
|
91
|
+
|
|
92
|
+
Returns:
|
|
93
|
+
Response JSON as dictionary
|
|
94
|
+
|
|
95
|
+
Raises:
|
|
96
|
+
MemoryAuthenticationError: If authentication fails (401)
|
|
97
|
+
MemoryNotFoundError: If resource not found (404)
|
|
98
|
+
MemoryAPIError: For other API errors
|
|
99
|
+
MemoryNetworkError: For network-related errors
|
|
100
|
+
"""
|
|
101
|
+
try:
|
|
102
|
+
session = await self._get_session()
|
|
103
|
+
logger.debug(f"Making {method} request to {url}")
|
|
104
|
+
|
|
105
|
+
async with session.request(
|
|
106
|
+
method,
|
|
107
|
+
url,
|
|
108
|
+
headers=self._get_headers(),
|
|
109
|
+
**kwargs,
|
|
110
|
+
) as response:
|
|
111
|
+
# Handle successful response
|
|
112
|
+
if response.status == 200:
|
|
113
|
+
result = await response.json()
|
|
114
|
+
logger.debug(
|
|
115
|
+
f"Request successful: {method} {url}",
|
|
116
|
+
)
|
|
117
|
+
return result
|
|
118
|
+
|
|
119
|
+
# Handle error responses (4XX, 5XX)
|
|
120
|
+
# Try to parse JSON error response first
|
|
121
|
+
error_data = None
|
|
122
|
+
try:
|
|
123
|
+
error_data = await response.json()
|
|
124
|
+
except Exception:
|
|
125
|
+
# If JSON parsing fails, fall back to text
|
|
126
|
+
error_text = await response.text()
|
|
127
|
+
error_data = {"message": error_text}
|
|
128
|
+
|
|
129
|
+
# Extract error information
|
|
130
|
+
error_code = error_data.get("code", "Unknown")
|
|
131
|
+
error_message = error_data.get("message", "Unknown error")
|
|
132
|
+
request_id = error_data.get("request_id", "")
|
|
133
|
+
|
|
134
|
+
# Format error log
|
|
135
|
+
error_log = (
|
|
136
|
+
f"API Error - Status: {response.status}, "
|
|
137
|
+
f"Code: {error_code}, Message: {error_message}, "
|
|
138
|
+
f"Request ID: {request_id}"
|
|
139
|
+
)
|
|
140
|
+
logger.error(error_log)
|
|
141
|
+
|
|
142
|
+
# Raise appropriate exception based on status code
|
|
143
|
+
if response.status in [401, 403]:
|
|
144
|
+
raise MemoryAuthenticationError(
|
|
145
|
+
error_message,
|
|
146
|
+
status_code=response.status,
|
|
147
|
+
error_code=error_code,
|
|
148
|
+
request_id=request_id,
|
|
149
|
+
)
|
|
150
|
+
if response.status == 404:
|
|
151
|
+
raise MemoryNotFoundError(
|
|
152
|
+
error_message,
|
|
153
|
+
status_code=response.status,
|
|
154
|
+
error_code=error_code,
|
|
155
|
+
request_id=request_id,
|
|
156
|
+
)
|
|
157
|
+
if response.status == 400:
|
|
158
|
+
raise MemoryValidationError(
|
|
159
|
+
error_message,
|
|
160
|
+
status_code=response.status,
|
|
161
|
+
error_code=error_code,
|
|
162
|
+
request_id=request_id,
|
|
163
|
+
)
|
|
164
|
+
if 400 <= response.status < 500:
|
|
165
|
+
# Other 4XX errors
|
|
166
|
+
raise MemoryValidationError(
|
|
167
|
+
error_message,
|
|
168
|
+
status_code=response.status,
|
|
169
|
+
error_code=error_code,
|
|
170
|
+
request_id=request_id,
|
|
171
|
+
)
|
|
172
|
+
raise MemoryAPIError(
|
|
173
|
+
error_message,
|
|
174
|
+
status_code=response.status,
|
|
175
|
+
error_code=error_code,
|
|
176
|
+
request_id=request_id,
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
except aiohttp.ClientError as e:
|
|
180
|
+
logger.exception(f"Network error: {str(e)}")
|
|
181
|
+
raise MemoryNetworkError(
|
|
182
|
+
f"Network error during {method} request to {url}: {str(e)}",
|
|
183
|
+
) from e
|
|
184
|
+
except (
|
|
185
|
+
MemoryAuthenticationError,
|
|
186
|
+
MemoryNotFoundError,
|
|
187
|
+
MemoryValidationError,
|
|
188
|
+
MemoryAPIError,
|
|
189
|
+
):
|
|
190
|
+
# Re-raise our custom exceptions (already have proper error info)
|
|
191
|
+
raise
|
|
192
|
+
except Exception as e:
|
|
193
|
+
logger.exception(f"Unexpected error: {str(e)}")
|
|
194
|
+
raise MemoryAPIError(
|
|
195
|
+
f"Unexpected error during {method} request to {url}: {str(e)}",
|
|
196
|
+
) from e
|
|
197
|
+
|
|
198
|
+
async def close(self) -> None:
|
|
199
|
+
"""
|
|
200
|
+
Close the HTTP session.
|
|
201
|
+
|
|
202
|
+
Should be called when the component is no longer needed to clean up
|
|
203
|
+
resources.
|
|
204
|
+
"""
|
|
205
|
+
if self._session and not self._session.closed:
|
|
206
|
+
await self._session.close()
|
|
207
|
+
logger.debug("Session closed")
|
|
208
|
+
|
|
209
|
+
async def __aenter__(self) -> "ModelStudioMemoryBase":
|
|
210
|
+
"""Support async context manager."""
|
|
211
|
+
return self
|
|
212
|
+
|
|
213
|
+
async def __aexit__(
|
|
214
|
+
self,
|
|
215
|
+
exc_type: Optional[Type[BaseException]],
|
|
216
|
+
exc_val: Optional[BaseException],
|
|
217
|
+
exc_tb: Optional[TracebackType],
|
|
218
|
+
) -> None:
|
|
219
|
+
"""Support async context manager."""
|
|
220
|
+
await self.close()
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Configuration management for ModelStudio Memory service.
|
|
4
|
+
"""
|
|
5
|
+
import os
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# Default endpoint
|
|
10
|
+
DEFAULT_MEMORY_SERVICE_ENDPOINT = (
|
|
11
|
+
"https://dashscope.aliyuncs.com/api/v2/apps/memory"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass
|
|
16
|
+
class MemoryServiceConfig:
|
|
17
|
+
"""
|
|
18
|
+
Configuration for ModelStudio Memory Service.
|
|
19
|
+
|
|
20
|
+
Attributes:
|
|
21
|
+
api_key: DashScope API key for authentication
|
|
22
|
+
service_endpoint: Base URL for the memory service API
|
|
23
|
+
service_id: Service identifier
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
api_key: str
|
|
27
|
+
service_endpoint: str = DEFAULT_MEMORY_SERVICE_ENDPOINT
|
|
28
|
+
service_id: str = "memory_service"
|
|
29
|
+
|
|
30
|
+
@classmethod
|
|
31
|
+
def from_env(cls) -> "MemoryServiceConfig":
|
|
32
|
+
"""
|
|
33
|
+
Create configuration from environment variables.
|
|
34
|
+
|
|
35
|
+
Environment Variables:
|
|
36
|
+
DASHSCOPE_API_KEY: Required. API key for authentication
|
|
37
|
+
MEMORY_SERVICE_ENDPOINT: Optional. API endpoint URL
|
|
38
|
+
MODELSTUDIO_SERVICE_ID: Optional. Service identifier
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
MemoryServiceConfig: Configuration instance
|
|
42
|
+
|
|
43
|
+
Raises:
|
|
44
|
+
ValueError: If DASHSCOPE_API_KEY is not set
|
|
45
|
+
"""
|
|
46
|
+
api_key = os.getenv("DASHSCOPE_API_KEY")
|
|
47
|
+
if not api_key:
|
|
48
|
+
raise ValueError(
|
|
49
|
+
"DASHSCOPE_API_KEY environment variable is required. "
|
|
50
|
+
"Please set it before using ModelStudio Memory components.",
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
return cls(
|
|
54
|
+
api_key=api_key,
|
|
55
|
+
service_endpoint=os.getenv(
|
|
56
|
+
"MEMORY_SERVICE_ENDPOINT",
|
|
57
|
+
DEFAULT_MEMORY_SERVICE_ENDPOINT,
|
|
58
|
+
),
|
|
59
|
+
service_id=os.getenv("MODELSTUDIO_SERVICE_ID", "memory_service"),
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
def get_add_memory_url(self) -> str:
|
|
63
|
+
"""Get URL for adding memory."""
|
|
64
|
+
return f"{self.service_endpoint}/add"
|
|
65
|
+
|
|
66
|
+
def get_search_memory_url(self) -> str:
|
|
67
|
+
"""Get URL for searching memory."""
|
|
68
|
+
return f"{self.service_endpoint}/memory_nodes/search"
|
|
69
|
+
|
|
70
|
+
def get_list_memory_url(self) -> str:
|
|
71
|
+
"""Get URL for listing memory."""
|
|
72
|
+
return f"{self.service_endpoint}/memory_nodes"
|
|
73
|
+
|
|
74
|
+
def get_delete_memory_url(self, memory_node_id: str) -> str:
|
|
75
|
+
"""Get URL for deleting a specific memory node."""
|
|
76
|
+
return f"{self.service_endpoint}/memory_nodes/{memory_node_id}"
|
|
77
|
+
|
|
78
|
+
def get_create_profile_schema_url(self) -> str:
|
|
79
|
+
"""Get URL for creating profile schema."""
|
|
80
|
+
return f"{self.service_endpoint}/profile_schemas"
|
|
81
|
+
|
|
82
|
+
def get_user_profile_url(self, schema_id: str) -> str:
|
|
83
|
+
"""Get URL for getting user profile."""
|
|
84
|
+
return (
|
|
85
|
+
f"{self.service_endpoint}/profile_schemas/{schema_id}/user_profile"
|
|
86
|
+
)
|