agentscope-runtime 0.1.0__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 (131) hide show
  1. agentscope_runtime/__init__.py +4 -0
  2. agentscope_runtime/engine/__init__.py +9 -0
  3. agentscope_runtime/engine/agents/__init__.py +2 -0
  4. agentscope_runtime/engine/agents/agentscope_agent/__init__.py +6 -0
  5. agentscope_runtime/engine/agents/agentscope_agent/agent.py +342 -0
  6. agentscope_runtime/engine/agents/agentscope_agent/hooks.py +156 -0
  7. agentscope_runtime/engine/agents/agno_agent.py +220 -0
  8. agentscope_runtime/engine/agents/base_agent.py +29 -0
  9. agentscope_runtime/engine/agents/langgraph_agent.py +59 -0
  10. agentscope_runtime/engine/agents/llm_agent.py +51 -0
  11. agentscope_runtime/engine/deployers/__init__.py +3 -0
  12. agentscope_runtime/engine/deployers/adapter/__init__.py +0 -0
  13. agentscope_runtime/engine/deployers/adapter/a2a/__init__.py +2 -0
  14. agentscope_runtime/engine/deployers/adapter/a2a/a2a_adapter_utils.py +425 -0
  15. agentscope_runtime/engine/deployers/adapter/a2a/a2a_agent_adapter.py +69 -0
  16. agentscope_runtime/engine/deployers/adapter/a2a/a2a_protocol_adapter.py +60 -0
  17. agentscope_runtime/engine/deployers/adapter/protocol_adapter.py +24 -0
  18. agentscope_runtime/engine/deployers/base.py +17 -0
  19. agentscope_runtime/engine/deployers/local_deployer.py +586 -0
  20. agentscope_runtime/engine/helpers/helper.py +127 -0
  21. agentscope_runtime/engine/llms/__init__.py +3 -0
  22. agentscope_runtime/engine/llms/base_llm.py +60 -0
  23. agentscope_runtime/engine/llms/qwen_llm.py +47 -0
  24. agentscope_runtime/engine/misc/__init__.py +0 -0
  25. agentscope_runtime/engine/runner.py +186 -0
  26. agentscope_runtime/engine/schemas/__init__.py +0 -0
  27. agentscope_runtime/engine/schemas/agent_schemas.py +551 -0
  28. agentscope_runtime/engine/schemas/context.py +54 -0
  29. agentscope_runtime/engine/services/__init__.py +9 -0
  30. agentscope_runtime/engine/services/base.py +77 -0
  31. agentscope_runtime/engine/services/context_manager.py +129 -0
  32. agentscope_runtime/engine/services/environment_manager.py +50 -0
  33. agentscope_runtime/engine/services/manager.py +174 -0
  34. agentscope_runtime/engine/services/memory_service.py +270 -0
  35. agentscope_runtime/engine/services/sandbox_service.py +198 -0
  36. agentscope_runtime/engine/services/session_history_service.py +256 -0
  37. agentscope_runtime/engine/tracing/__init__.py +40 -0
  38. agentscope_runtime/engine/tracing/base.py +309 -0
  39. agentscope_runtime/engine/tracing/local_logging_handler.py +356 -0
  40. agentscope_runtime/engine/tracing/tracing_metric.py +69 -0
  41. agentscope_runtime/engine/tracing/wrapper.py +321 -0
  42. agentscope_runtime/sandbox/__init__.py +14 -0
  43. agentscope_runtime/sandbox/box/__init__.py +0 -0
  44. agentscope_runtime/sandbox/box/base/__init__.py +0 -0
  45. agentscope_runtime/sandbox/box/base/base_sandbox.py +37 -0
  46. agentscope_runtime/sandbox/box/base/box/__init__.py +0 -0
  47. agentscope_runtime/sandbox/box/browser/__init__.py +0 -0
  48. agentscope_runtime/sandbox/box/browser/box/__init__.py +0 -0
  49. agentscope_runtime/sandbox/box/browser/browser_sandbox.py +176 -0
  50. agentscope_runtime/sandbox/box/dummy/__init__.py +0 -0
  51. agentscope_runtime/sandbox/box/dummy/dummy_sandbox.py +26 -0
  52. agentscope_runtime/sandbox/box/filesystem/__init__.py +0 -0
  53. agentscope_runtime/sandbox/box/filesystem/box/__init__.py +0 -0
  54. agentscope_runtime/sandbox/box/filesystem/filesystem_sandbox.py +87 -0
  55. agentscope_runtime/sandbox/box/sandbox.py +115 -0
  56. agentscope_runtime/sandbox/box/shared/__init__.py +0 -0
  57. agentscope_runtime/sandbox/box/shared/app.py +44 -0
  58. agentscope_runtime/sandbox/box/shared/dependencies/__init__.py +5 -0
  59. agentscope_runtime/sandbox/box/shared/dependencies/deps.py +22 -0
  60. agentscope_runtime/sandbox/box/shared/routers/__init__.py +12 -0
  61. agentscope_runtime/sandbox/box/shared/routers/generic.py +173 -0
  62. agentscope_runtime/sandbox/box/shared/routers/mcp.py +207 -0
  63. agentscope_runtime/sandbox/box/shared/routers/mcp_utils.py +153 -0
  64. agentscope_runtime/sandbox/box/shared/routers/runtime_watcher.py +187 -0
  65. agentscope_runtime/sandbox/box/shared/routers/workspace.py +325 -0
  66. agentscope_runtime/sandbox/box/training_box/__init__.py +0 -0
  67. agentscope_runtime/sandbox/box/training_box/base.py +120 -0
  68. agentscope_runtime/sandbox/box/training_box/env_service.py +752 -0
  69. agentscope_runtime/sandbox/box/training_box/environments/__init__.py +0 -0
  70. agentscope_runtime/sandbox/box/training_box/environments/appworld/appworld_env.py +987 -0
  71. agentscope_runtime/sandbox/box/training_box/registry.py +54 -0
  72. agentscope_runtime/sandbox/box/training_box/src/trajectory.py +278 -0
  73. agentscope_runtime/sandbox/box/training_box/training_box.py +219 -0
  74. agentscope_runtime/sandbox/build.py +213 -0
  75. agentscope_runtime/sandbox/client/__init__.py +5 -0
  76. agentscope_runtime/sandbox/client/http_client.py +527 -0
  77. agentscope_runtime/sandbox/client/training_client.py +265 -0
  78. agentscope_runtime/sandbox/constant.py +5 -0
  79. agentscope_runtime/sandbox/custom/__init__.py +16 -0
  80. agentscope_runtime/sandbox/custom/custom_sandbox.py +40 -0
  81. agentscope_runtime/sandbox/custom/example.py +37 -0
  82. agentscope_runtime/sandbox/enums.py +68 -0
  83. agentscope_runtime/sandbox/manager/__init__.py +4 -0
  84. agentscope_runtime/sandbox/manager/collections/__init__.py +22 -0
  85. agentscope_runtime/sandbox/manager/collections/base_mapping.py +20 -0
  86. agentscope_runtime/sandbox/manager/collections/base_queue.py +25 -0
  87. agentscope_runtime/sandbox/manager/collections/base_set.py +25 -0
  88. agentscope_runtime/sandbox/manager/collections/in_memory_mapping.py +22 -0
  89. agentscope_runtime/sandbox/manager/collections/in_memory_queue.py +28 -0
  90. agentscope_runtime/sandbox/manager/collections/in_memory_set.py +27 -0
  91. agentscope_runtime/sandbox/manager/collections/redis_mapping.py +26 -0
  92. agentscope_runtime/sandbox/manager/collections/redis_queue.py +27 -0
  93. agentscope_runtime/sandbox/manager/collections/redis_set.py +23 -0
  94. agentscope_runtime/sandbox/manager/container_clients/__init__.py +8 -0
  95. agentscope_runtime/sandbox/manager/container_clients/base_client.py +39 -0
  96. agentscope_runtime/sandbox/manager/container_clients/docker_client.py +170 -0
  97. agentscope_runtime/sandbox/manager/sandbox_manager.py +694 -0
  98. agentscope_runtime/sandbox/manager/server/__init__.py +0 -0
  99. agentscope_runtime/sandbox/manager/server/app.py +194 -0
  100. agentscope_runtime/sandbox/manager/server/config.py +68 -0
  101. agentscope_runtime/sandbox/manager/server/models.py +17 -0
  102. agentscope_runtime/sandbox/manager/storage/__init__.py +10 -0
  103. agentscope_runtime/sandbox/manager/storage/data_storage.py +16 -0
  104. agentscope_runtime/sandbox/manager/storage/local_storage.py +44 -0
  105. agentscope_runtime/sandbox/manager/storage/oss_storage.py +89 -0
  106. agentscope_runtime/sandbox/manager/utils.py +78 -0
  107. agentscope_runtime/sandbox/mcp_server.py +192 -0
  108. agentscope_runtime/sandbox/model/__init__.py +12 -0
  109. agentscope_runtime/sandbox/model/api.py +16 -0
  110. agentscope_runtime/sandbox/model/container.py +72 -0
  111. agentscope_runtime/sandbox/model/manager_config.py +158 -0
  112. agentscope_runtime/sandbox/registry.py +129 -0
  113. agentscope_runtime/sandbox/tools/__init__.py +12 -0
  114. agentscope_runtime/sandbox/tools/base/__init__.py +8 -0
  115. agentscope_runtime/sandbox/tools/base/tool.py +52 -0
  116. agentscope_runtime/sandbox/tools/browser/__init__.py +57 -0
  117. agentscope_runtime/sandbox/tools/browser/tool.py +597 -0
  118. agentscope_runtime/sandbox/tools/filesystem/__init__.py +32 -0
  119. agentscope_runtime/sandbox/tools/filesystem/tool.py +319 -0
  120. agentscope_runtime/sandbox/tools/function_tool.py +321 -0
  121. agentscope_runtime/sandbox/tools/mcp_tool.py +191 -0
  122. agentscope_runtime/sandbox/tools/sandbox_tool.py +104 -0
  123. agentscope_runtime/sandbox/tools/tool.py +123 -0
  124. agentscope_runtime/sandbox/tools/utils.py +68 -0
  125. agentscope_runtime/version.py +2 -0
  126. agentscope_runtime-0.1.0.dist-info/METADATA +327 -0
  127. agentscope_runtime-0.1.0.dist-info/RECORD +131 -0
  128. agentscope_runtime-0.1.0.dist-info/WHEEL +5 -0
  129. agentscope_runtime-0.1.0.dist-info/entry_points.txt +4 -0
  130. agentscope_runtime-0.1.0.dist-info/licenses/LICENSE +202 -0
  131. agentscope_runtime-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ from .base_client import BaseClient
3
+ from .docker_client import DockerClient
4
+
5
+ __all__ = [
6
+ "BaseClient",
7
+ "DockerClient",
8
+ ]
@@ -0,0 +1,39 @@
1
+ # -*- coding: utf-8 -*-
2
+ from abc import ABC, abstractmethod
3
+
4
+
5
+ class BaseClient(ABC):
6
+ @abstractmethod
7
+ def create(
8
+ self,
9
+ image,
10
+ name=None,
11
+ ports=None,
12
+ volumes=None,
13
+ environment=None,
14
+ runtime_config=None,
15
+ ):
16
+ """
17
+ Create a new container with the specified image and environment
18
+ variables.
19
+ """
20
+
21
+ @abstractmethod
22
+ def start(self, container_id):
23
+ """Start a specified container."""
24
+
25
+ @abstractmethod
26
+ def stop(self, container_id, timeout=None):
27
+ """Stop a running container."""
28
+
29
+ @abstractmethod
30
+ def remove(self, container_id, force=False):
31
+ """Remove a specified container, optionally forcing removal."""
32
+
33
+ @abstractmethod
34
+ def inspect(self, container_id):
35
+ """Get detailed information about the specified container."""
36
+
37
+ @abstractmethod
38
+ def get_status(self, container_id):
39
+ """Get the current status of the specified container."""
@@ -0,0 +1,170 @@
1
+ # -*- coding: utf-8 -*-
2
+ import traceback
3
+ import logging
4
+
5
+ import docker
6
+ from .base_client import BaseClient
7
+
8
+
9
+ logger = logging.getLogger(__name__)
10
+
11
+
12
+ class DockerClient(BaseClient):
13
+ def __init__(self):
14
+ try:
15
+ self.client = docker.from_env()
16
+ except Exception as e:
17
+ raise RuntimeError(
18
+ f"Docker client initialization failed: {str(e)}\n"
19
+ "Solutions:\n"
20
+ "• Ensure Docker is running\n"
21
+ "• Check Docker permissions\n"
22
+ "• For Colima: "
23
+ "export DOCKER_HOST=unix://$HOME/.colima/docker.sock",
24
+ ) from e
25
+
26
+ def _try_pull_from_acr(self, image):
27
+ """
28
+ Attempt to pull the image from the Alibaba Cloud Container Registry
29
+ (ACR) and retag it.
30
+ """
31
+ try:
32
+ acr_registry = "agentscope-registry.ap-southeast-1.cr.aliyuncs.com"
33
+ acr_image = f"{acr_registry}/{image}"
34
+
35
+ logger.debug(f"Attempting to pull from ACR: {acr_image}")
36
+ self.client.images.pull(acr_image)
37
+ logger.debug(f"Successfully pulled image from ACR: {acr_image}")
38
+
39
+ # Retag the image
40
+ acr_img_obj = self.client.images.get(acr_image)
41
+ acr_img_obj.tag(image)
42
+ logger.debug(f"Successfully tagged image as: {image}")
43
+
44
+ # Optionally remove the original tag to save space
45
+ try:
46
+ self.client.images.remove(acr_image)
47
+ logger.debug(f"Removed original tag: {acr_image}")
48
+ except Exception as e:
49
+ logger.debug(f"Failed to remove original tag: {e}")
50
+ return True
51
+ except Exception as e:
52
+ logger.error(f"Failed to pull from ACR: {e}")
53
+ return False
54
+
55
+ def create(
56
+ self,
57
+ image,
58
+ name=None,
59
+ ports=None,
60
+ volumes=None,
61
+ environment=None,
62
+ runtime_config=None,
63
+ ):
64
+ """Create a new Docker container."""
65
+ if runtime_config is None:
66
+ runtime_config = {}
67
+
68
+ try:
69
+ try:
70
+ # Check if the image exists locally
71
+ self.client.images.get(image)
72
+ logger.debug(f"Image '{image}' found locally.")
73
+ except docker.errors.ImageNotFound:
74
+ logger.debug(
75
+ f"Image '{image}' not found locally. "
76
+ f"Attempting to pull it...",
77
+ )
78
+ try:
79
+ self.client.images.pull(image)
80
+ logger.debug(
81
+ f"Image '{image}' successfully pulled from default "
82
+ f"registry.",
83
+ )
84
+ pull_success = True
85
+ except docker.errors.APIError as e:
86
+ logger.warning(
87
+ f"Failed to pull from default registry: {e}",
88
+ )
89
+ logger.debug("Trying to pull from ACR fallback...")
90
+ pull_success = self._try_pull_from_acr(image)
91
+
92
+ if not pull_success:
93
+ logger.error(
94
+ f"Failed to pull image '{image}' from both "
95
+ f"default and ACR",
96
+ )
97
+ return False
98
+
99
+ except docker.errors.APIError as e:
100
+ logger.error(f"Error occurred while checking the image: {e}")
101
+ return False
102
+
103
+ # Create and run the container
104
+ container = self.client.containers.run(
105
+ image,
106
+ detach=True,
107
+ ports=ports,
108
+ name=name,
109
+ volumes=volumes,
110
+ environment=environment,
111
+ **runtime_config,
112
+ )
113
+ container.reload()
114
+ return True
115
+ except Exception as e:
116
+ logger.error(f"An error occurred: {e}, {traceback.format_exc()}")
117
+ return False
118
+
119
+ def start(self, container_id):
120
+ """Start a Docker container."""
121
+ try:
122
+ container = self.client.containers.get(
123
+ container_id,
124
+ )
125
+ container.start()
126
+ return True
127
+ except Exception as e:
128
+ logger.error(f"An error occurred: {e}, {traceback.format_exc()}")
129
+ return False
130
+
131
+ def stop(self, container_id, timeout=None):
132
+ """Stop a Docker container."""
133
+ try:
134
+ container = self.client.containers.get(
135
+ container_id,
136
+ )
137
+ container.stop(timeout=timeout)
138
+ return True
139
+ except Exception as e:
140
+ logger.error(f"An error occurred: {e}, {traceback.format_exc()}")
141
+ return False
142
+
143
+ def remove(self, container_id, force=False):
144
+ """Remove a Docker container."""
145
+ try:
146
+ container = self.client.containers.get(
147
+ container_id,
148
+ )
149
+ container.remove(force=force)
150
+ return True
151
+ except Exception as e:
152
+ logger.error(f"An error occurred: {e}, {traceback.format_exc()}")
153
+ return False
154
+
155
+ def inspect(self, container_id):
156
+ """Inspect a Docker container."""
157
+ try:
158
+ # Get the container object
159
+ container = self.client.containers.get(container_id)
160
+ # Access the detailed information
161
+ return container.attrs
162
+ except Exception:
163
+ return None
164
+
165
+ def get_status(self, container_id):
166
+ """Get the current status of the specified container."""
167
+ container_attrs = self.inspect(container_id=container_id)
168
+ if container_attrs:
169
+ return container_attrs["State"]["Status"]
170
+ return None