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.
Files changed (79) hide show
  1. agentscope_runtime/adapters/agentscope/stream.py +2 -8
  2. agentscope_runtime/adapters/langgraph/stream.py +120 -70
  3. agentscope_runtime/adapters/ms_agent_framework/__init__.py +0 -0
  4. agentscope_runtime/adapters/ms_agent_framework/message.py +205 -0
  5. agentscope_runtime/adapters/ms_agent_framework/stream.py +418 -0
  6. agentscope_runtime/adapters/utils.py +6 -0
  7. agentscope_runtime/cli/commands/deploy.py +836 -1
  8. agentscope_runtime/cli/commands/stop.py +16 -0
  9. agentscope_runtime/common/container_clients/__init__.py +52 -0
  10. agentscope_runtime/common/container_clients/agentrun_client.py +6 -4
  11. agentscope_runtime/common/container_clients/boxlite_client.py +442 -0
  12. agentscope_runtime/common/container_clients/docker_client.py +0 -20
  13. agentscope_runtime/common/container_clients/fc_client.py +6 -4
  14. agentscope_runtime/common/container_clients/gvisor_client.py +38 -0
  15. agentscope_runtime/common/container_clients/knative_client.py +467 -0
  16. agentscope_runtime/common/utils/deprecation.py +164 -0
  17. agentscope_runtime/engine/__init__.py +4 -0
  18. agentscope_runtime/engine/app/agent_app.py +16 -4
  19. agentscope_runtime/engine/constant.py +1 -0
  20. agentscope_runtime/engine/deployers/__init__.py +34 -11
  21. agentscope_runtime/engine/deployers/adapter/__init__.py +8 -0
  22. agentscope_runtime/engine/deployers/adapter/a2a/__init__.py +26 -51
  23. agentscope_runtime/engine/deployers/adapter/a2a/a2a_protocol_adapter.py +23 -13
  24. agentscope_runtime/engine/deployers/adapter/a2a/a2a_registry.py +4 -201
  25. agentscope_runtime/engine/deployers/adapter/a2a/nacos_a2a_registry.py +152 -25
  26. agentscope_runtime/engine/deployers/adapter/agui/__init__.py +8 -0
  27. agentscope_runtime/engine/deployers/adapter/agui/agui_adapter_utils.py +652 -0
  28. agentscope_runtime/engine/deployers/adapter/agui/agui_protocol_adapter.py +225 -0
  29. agentscope_runtime/engine/deployers/agentrun_deployer.py +2 -2
  30. agentscope_runtime/engine/deployers/fc_deployer.py +1506 -0
  31. agentscope_runtime/engine/deployers/knative_deployer.py +290 -0
  32. agentscope_runtime/engine/deployers/pai_deployer.py +2335 -0
  33. agentscope_runtime/engine/deployers/utils/net_utils.py +37 -0
  34. agentscope_runtime/engine/deployers/utils/oss_utils.py +38 -0
  35. agentscope_runtime/engine/deployers/utils/package.py +46 -42
  36. agentscope_runtime/engine/helpers/agent_api_client.py +372 -0
  37. agentscope_runtime/engine/runner.py +13 -0
  38. agentscope_runtime/engine/schemas/agent_schemas.py +9 -3
  39. agentscope_runtime/engine/services/agent_state/__init__.py +7 -0
  40. agentscope_runtime/engine/services/memory/__init__.py +7 -0
  41. agentscope_runtime/engine/services/memory/redis_memory_service.py +15 -16
  42. agentscope_runtime/engine/services/session_history/__init__.py +7 -0
  43. agentscope_runtime/engine/tracing/local_logging_handler.py +2 -3
  44. agentscope_runtime/engine/tracing/wrapper.py +18 -4
  45. agentscope_runtime/sandbox/__init__.py +14 -6
  46. agentscope_runtime/sandbox/box/base/__init__.py +2 -2
  47. agentscope_runtime/sandbox/box/base/base_sandbox.py +51 -1
  48. agentscope_runtime/sandbox/box/browser/__init__.py +2 -2
  49. agentscope_runtime/sandbox/box/browser/browser_sandbox.py +198 -2
  50. agentscope_runtime/sandbox/box/filesystem/__init__.py +2 -2
  51. agentscope_runtime/sandbox/box/filesystem/filesystem_sandbox.py +99 -2
  52. agentscope_runtime/sandbox/box/gui/__init__.py +2 -2
  53. agentscope_runtime/sandbox/box/gui/gui_sandbox.py +117 -1
  54. agentscope_runtime/sandbox/box/mobile/__init__.py +2 -2
  55. agentscope_runtime/sandbox/box/mobile/mobile_sandbox.py +247 -100
  56. agentscope_runtime/sandbox/box/sandbox.py +102 -65
  57. agentscope_runtime/sandbox/box/shared/routers/generic.py +36 -29
  58. agentscope_runtime/sandbox/client/__init__.py +6 -1
  59. agentscope_runtime/sandbox/client/async_http_client.py +339 -0
  60. agentscope_runtime/sandbox/client/base.py +74 -0
  61. agentscope_runtime/sandbox/client/http_client.py +108 -329
  62. agentscope_runtime/sandbox/enums.py +7 -0
  63. agentscope_runtime/sandbox/manager/sandbox_manager.py +275 -29
  64. agentscope_runtime/sandbox/manager/server/app.py +7 -1
  65. agentscope_runtime/sandbox/manager/server/config.py +3 -1
  66. agentscope_runtime/sandbox/model/manager_config.py +11 -9
  67. agentscope_runtime/tools/modelstudio_memory/__init__.py +106 -0
  68. agentscope_runtime/tools/modelstudio_memory/base.py +220 -0
  69. agentscope_runtime/tools/modelstudio_memory/config.py +86 -0
  70. agentscope_runtime/tools/modelstudio_memory/core.py +594 -0
  71. agentscope_runtime/tools/modelstudio_memory/exceptions.py +60 -0
  72. agentscope_runtime/tools/modelstudio_memory/schemas.py +253 -0
  73. agentscope_runtime/version.py +1 -1
  74. {agentscope_runtime-1.0.4a1.dist-info → agentscope_runtime-1.0.5.dist-info}/METADATA +186 -73
  75. {agentscope_runtime-1.0.4a1.dist-info → agentscope_runtime-1.0.5.dist-info}/RECORD +79 -55
  76. {agentscope_runtime-1.0.4a1.dist-info → agentscope_runtime-1.0.5.dist-info}/WHEEL +0 -0
  77. {agentscope_runtime-1.0.4a1.dist-info → agentscope_runtime-1.0.5.dist-info}/entry_points.txt +0 -0
  78. {agentscope_runtime-1.0.4a1.dist-info → agentscope_runtime-1.0.5.dist-info}/licenses/LICENSE +0 -0
  79. {agentscope_runtime-1.0.4a1.dist-info → agentscope_runtime-1.0.5.dist-info}/top_level.txt +0 -0
@@ -8,11 +8,17 @@ for A2A protocol adapters.
8
8
  """
9
9
  import asyncio
10
10
  import logging
11
- from enum import Enum
12
- from typing import Optional, TYPE_CHECKING, List
11
+ import os
13
12
  import threading
13
+ from enum import Enum
14
+ from typing import Any, Optional, TYPE_CHECKING, List
14
15
 
15
16
  from a2a.types import AgentCard
17
+ from dotenv import find_dotenv, load_dotenv
18
+ from pydantic import ConfigDict
19
+ from pydantic_settings import BaseSettings
20
+
21
+ logger = logging.getLogger(__name__)
16
22
 
17
23
  # Make the v2.nacos imports optional to avoid hard dependency at
18
24
  # module import time.
@@ -36,6 +42,10 @@ else:
36
42
 
37
43
  _NACOS_SDK_AVAILABLE = True
38
44
  except Exception:
45
+ logger.warning(
46
+ "[NacosRegistry] Nacos SDK (nacos-sdk-python) is not available. "
47
+ "Install it with: pip install nacos-sdk-python",
48
+ )
39
49
 
40
50
  class ClientConfig:
41
51
  pass
@@ -55,12 +65,147 @@ else:
55
65
  _NACOS_SDK_AVAILABLE = False
56
66
 
57
67
  # Import after conditional imports to avoid circular dependencies
68
+ # flake8: noqa: E402
58
69
  from .a2a_registry import ( # pylint: disable=wrong-import-position
59
70
  A2ARegistry,
60
71
  A2ATransportsProperties,
61
72
  )
62
73
 
63
- logger = logging.getLogger(__name__)
74
+
75
+ class NacosSettings(BaseSettings):
76
+ """Nacos-specific settings loaded from environment variables."""
77
+
78
+ NACOS_SERVER_ADDR: str = "localhost:8848"
79
+ NACOS_USERNAME: Optional[str] = None
80
+ NACOS_PASSWORD: Optional[str] = None
81
+ NACOS_NAMESPACE_ID: Optional[str] = None
82
+ NACOS_ACCESS_KEY: Optional[str] = None
83
+ NACOS_SECRET_KEY: Optional[str] = None
84
+
85
+ model_config = ConfigDict(
86
+ extra="allow",
87
+ )
88
+
89
+
90
+ _nacos_settings: Optional[NacosSettings] = None
91
+
92
+
93
+ def get_nacos_settings() -> NacosSettings:
94
+ """Return a singleton Nacos settings instance, loading .env files
95
+ if needed."""
96
+ global _nacos_settings
97
+
98
+ if _nacos_settings is None:
99
+ dotenv_path = find_dotenv(raise_error_if_not_found=False)
100
+ if dotenv_path:
101
+ load_dotenv(dotenv_path, override=False)
102
+ else:
103
+ if os.path.exists(".env.example"):
104
+ load_dotenv(".env.example", override=False)
105
+ _nacos_settings = NacosSettings()
106
+
107
+ return _nacos_settings
108
+
109
+
110
+ def _build_nacos_client_config(settings: NacosSettings) -> Any:
111
+ """Build Nacos client configuration from settings.
112
+
113
+ Supports both username/password and access key authentication.
114
+ """
115
+ try:
116
+ from v2.nacos import ClientConfigBuilder
117
+ except (ImportError, ModuleNotFoundError) as e:
118
+ logger.warning(
119
+ "[A2A] Nacos SDK (nacos-sdk-python) is not available. "
120
+ "Install it with: pip install nacos-sdk-python",
121
+ )
122
+ raise ImportError(
123
+ "Nacos SDK (nacos-sdk-python) is not available. "
124
+ "Install it with: pip install nacos-sdk-python",
125
+ ) from e
126
+
127
+ builder = ClientConfigBuilder().server_address(settings.NACOS_SERVER_ADDR)
128
+
129
+ if settings.NACOS_NAMESPACE_ID:
130
+ builder.namespace_id(settings.NACOS_NAMESPACE_ID)
131
+ logger.debug(
132
+ "[A2A] Using Nacos namespace: %s",
133
+ settings.NACOS_NAMESPACE_ID,
134
+ )
135
+
136
+ if settings.NACOS_USERNAME and settings.NACOS_PASSWORD:
137
+ builder.username(settings.NACOS_USERNAME).password(
138
+ settings.NACOS_PASSWORD,
139
+ )
140
+ logger.debug("[A2A] Using Nacos username/password authentication")
141
+
142
+ if settings.NACOS_ACCESS_KEY and settings.NACOS_SECRET_KEY:
143
+ builder.access_key(settings.NACOS_ACCESS_KEY).secret_key(
144
+ settings.NACOS_SECRET_KEY,
145
+ )
146
+ logger.debug("[A2A] Using Nacos access key authentication")
147
+
148
+ return builder.build()
149
+
150
+
151
+ def create_nacos_registry_from_env() -> Optional[A2ARegistry]:
152
+ """Create a NacosRegistry instance from environment settings.
153
+
154
+ Returns None if the required nacos SDK is not available or
155
+ construction fails.
156
+ """
157
+ if not _NACOS_SDK_AVAILABLE:
158
+ return None
159
+
160
+ # Only create a Nacos registry if the user has explicitly configured
161
+ # at least one NACOS_* related environment variable. If none of these
162
+ # are present, we assume the user does NOT want to use any registry.
163
+ nacos_settings = get_nacos_settings()
164
+ env_keys = [
165
+ "NACOS_SERVER_ADDR",
166
+ "NACOS_USERNAME",
167
+ "NACOS_PASSWORD",
168
+ "NACOS_NAMESPACE_ID",
169
+ "NACOS_ACCESS_KEY",
170
+ "NACOS_SECRET_KEY",
171
+ ]
172
+ if not any(key in os.environ for key in env_keys):
173
+ logger.info(
174
+ "[A2A] No NACOS_* environment variables found; "
175
+ "registry will not be enabled.",
176
+ )
177
+ return None
178
+
179
+ try:
180
+ nacos_client_config = _build_nacos_client_config(nacos_settings)
181
+ registry = NacosRegistry(nacos_client_config=nacos_client_config)
182
+
183
+ auth_methods = []
184
+ if nacos_settings.NACOS_USERNAME and nacos_settings.NACOS_PASSWORD:
185
+ auth_methods.append("username/password")
186
+ if nacos_settings.NACOS_ACCESS_KEY and nacos_settings.NACOS_SECRET_KEY:
187
+ auth_methods.append("access_key")
188
+ auth_status = ", ".join(auth_methods) if auth_methods else "disabled"
189
+
190
+ namespace_info = (
191
+ f", namespace={nacos_settings.NACOS_NAMESPACE_ID}"
192
+ if nacos_settings.NACOS_NAMESPACE_ID
193
+ else ""
194
+ )
195
+ logger.info(
196
+ f"[A2A] Created Nacos registry from environment: "
197
+ f"server={nacos_settings.NACOS_SERVER_ADDR}, "
198
+ f"authentication={auth_status}{namespace_info}",
199
+ )
200
+ return registry
201
+ except (ImportError, ModuleNotFoundError):
202
+ return None
203
+ except Exception:
204
+ logger.warning(
205
+ "[A2A] Failed to construct Nacos registry from settings",
206
+ exc_info=True,
207
+ )
208
+ return None
64
209
 
65
210
 
66
211
  class RegistrationStatus(Enum):
@@ -127,11 +272,10 @@ class NacosRegistry(A2ARegistry):
127
272
  a2a_transports_properties: List of transport configurations.
128
273
  Each transport will be registered separately.
129
274
  """
130
- # If Nacos SDK is not available, log and return
131
275
  if not _NACOS_SDK_AVAILABLE:
132
- logger.debug(
133
- "[NacosRegistry] Nacos SDK is not available; "
134
- "skipping registration",
276
+ logger.warning(
277
+ "[NacosRegistry] Nacos SDK (nacos-sdk-python) is not "
278
+ "available. Install it with: pip install nacos-sdk-python",
135
279
  )
136
280
  return
137
281
 
@@ -154,11 +298,7 @@ class NacosRegistry(A2ARegistry):
154
298
  thread and run the registration using asyncio.run so
155
299
  registration still occurs in synchronous contexts.
156
300
  """
157
- # All status checks and updates must be within the lock to
158
- # ensure atomicity
159
301
  with self._registration_lock:
160
- # Check if shutdown was already requested (inside lock
161
- # for atomicity)
162
302
  if self._shutdown_event.is_set():
163
303
  logger.info(
164
304
  "[NacosRegistry] Shutdown already requested, "
@@ -167,7 +307,6 @@ class NacosRegistry(A2ARegistry):
167
307
  self._registration_status = RegistrationStatus.CANCELLED
168
308
  return
169
309
 
170
- # Check if registration is already in progress or completed
171
310
  if self._registration_status in (
172
311
  RegistrationStatus.IN_PROGRESS,
173
312
  RegistrationStatus.COMPLETED,
@@ -184,8 +323,6 @@ class NacosRegistry(A2ARegistry):
184
323
  try:
185
324
  loop = asyncio.get_running_loop()
186
325
  except RuntimeError:
187
- # No running loop in this thread; we'll fall back to a
188
- # background thread
189
326
  loop = None
190
327
 
191
328
  if loop is not None:
@@ -203,7 +340,6 @@ class NacosRegistry(A2ARegistry):
203
340
  )
204
341
  return
205
342
 
206
- # No running loop: use a background thread to run asyncio.run
207
343
  def _thread_runner():
208
344
  try:
209
345
  with self._registration_lock:
@@ -257,8 +393,6 @@ class NacosRegistry(A2ARegistry):
257
393
  daemon=True,
258
394
  )
259
395
  thread.start()
260
- # Store thread reference after successful start for
261
- # proper tracking and cleanup
262
396
  with self._registration_lock:
263
397
  self._register_thread = thread
264
398
  logger.info(
@@ -282,14 +416,7 @@ class NacosRegistry(A2ARegistry):
282
416
  if self._nacos_client_config is not None:
283
417
  return self._nacos_client_config
284
418
 
285
- # Use centralized config builder from a2a_registry module
286
- # This ensures consistent behavior with env-based registry creation
287
- from .a2a_registry import (
288
- get_registry_settings,
289
- _build_nacos_client_config,
290
- )
291
-
292
- settings = get_registry_settings()
419
+ settings = get_nacos_settings()
293
420
  return _build_nacos_client_config(settings)
294
421
 
295
422
  # pylint: disable=too-many-branches,too-many-statements
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ from .agui_protocol_adapter import (
3
+ AGUIDefaultAdapter,
4
+ FlexibleRunAgentInput,
5
+ AGUIAdaptorConfig,
6
+ )
7
+
8
+ __all__ = ["AGUIDefaultAdapter", "FlexibleRunAgentInput", "AGUIAdaptorConfig"]