kweaver-dolphin 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 (199) hide show
  1. DolphinLanguageSDK/__init__.py +58 -0
  2. dolphin/__init__.py +62 -0
  3. dolphin/cli/__init__.py +20 -0
  4. dolphin/cli/args/__init__.py +9 -0
  5. dolphin/cli/args/parser.py +567 -0
  6. dolphin/cli/builtin_agents/__init__.py +22 -0
  7. dolphin/cli/commands/__init__.py +4 -0
  8. dolphin/cli/interrupt/__init__.py +8 -0
  9. dolphin/cli/interrupt/handler.py +205 -0
  10. dolphin/cli/interrupt/keyboard.py +82 -0
  11. dolphin/cli/main.py +49 -0
  12. dolphin/cli/multimodal/__init__.py +34 -0
  13. dolphin/cli/multimodal/clipboard.py +327 -0
  14. dolphin/cli/multimodal/handler.py +249 -0
  15. dolphin/cli/multimodal/image_processor.py +214 -0
  16. dolphin/cli/multimodal/input_parser.py +149 -0
  17. dolphin/cli/runner/__init__.py +8 -0
  18. dolphin/cli/runner/runner.py +989 -0
  19. dolphin/cli/ui/__init__.py +10 -0
  20. dolphin/cli/ui/console.py +2795 -0
  21. dolphin/cli/ui/input.py +340 -0
  22. dolphin/cli/ui/layout.py +425 -0
  23. dolphin/cli/ui/stream_renderer.py +302 -0
  24. dolphin/cli/utils/__init__.py +8 -0
  25. dolphin/cli/utils/helpers.py +135 -0
  26. dolphin/cli/utils/version.py +49 -0
  27. dolphin/core/__init__.py +107 -0
  28. dolphin/core/agent/__init__.py +10 -0
  29. dolphin/core/agent/agent_state.py +69 -0
  30. dolphin/core/agent/base_agent.py +970 -0
  31. dolphin/core/code_block/__init__.py +0 -0
  32. dolphin/core/code_block/agent_init_block.py +0 -0
  33. dolphin/core/code_block/assign_block.py +98 -0
  34. dolphin/core/code_block/basic_code_block.py +1865 -0
  35. dolphin/core/code_block/explore_block.py +1327 -0
  36. dolphin/core/code_block/explore_block_v2.py +712 -0
  37. dolphin/core/code_block/explore_strategy.py +672 -0
  38. dolphin/core/code_block/judge_block.py +220 -0
  39. dolphin/core/code_block/prompt_block.py +32 -0
  40. dolphin/core/code_block/skill_call_deduplicator.py +291 -0
  41. dolphin/core/code_block/tool_block.py +129 -0
  42. dolphin/core/common/__init__.py +17 -0
  43. dolphin/core/common/constants.py +176 -0
  44. dolphin/core/common/enums.py +1173 -0
  45. dolphin/core/common/exceptions.py +133 -0
  46. dolphin/core/common/multimodal.py +539 -0
  47. dolphin/core/common/object_type.py +165 -0
  48. dolphin/core/common/output_format.py +432 -0
  49. dolphin/core/common/types.py +36 -0
  50. dolphin/core/config/__init__.py +16 -0
  51. dolphin/core/config/global_config.py +1289 -0
  52. dolphin/core/config/ontology_config.py +133 -0
  53. dolphin/core/context/__init__.py +12 -0
  54. dolphin/core/context/context.py +1580 -0
  55. dolphin/core/context/context_manager.py +161 -0
  56. dolphin/core/context/var_output.py +82 -0
  57. dolphin/core/context/variable_pool.py +356 -0
  58. dolphin/core/context_engineer/__init__.py +41 -0
  59. dolphin/core/context_engineer/config/__init__.py +5 -0
  60. dolphin/core/context_engineer/config/settings.py +402 -0
  61. dolphin/core/context_engineer/core/__init__.py +7 -0
  62. dolphin/core/context_engineer/core/budget_manager.py +327 -0
  63. dolphin/core/context_engineer/core/context_assembler.py +583 -0
  64. dolphin/core/context_engineer/core/context_manager.py +637 -0
  65. dolphin/core/context_engineer/core/tokenizer_service.py +260 -0
  66. dolphin/core/context_engineer/example/incremental_example.py +267 -0
  67. dolphin/core/context_engineer/example/traditional_example.py +334 -0
  68. dolphin/core/context_engineer/services/__init__.py +5 -0
  69. dolphin/core/context_engineer/services/compressor.py +399 -0
  70. dolphin/core/context_engineer/utils/__init__.py +6 -0
  71. dolphin/core/context_engineer/utils/context_utils.py +441 -0
  72. dolphin/core/context_engineer/utils/message_formatter.py +270 -0
  73. dolphin/core/context_engineer/utils/token_utils.py +139 -0
  74. dolphin/core/coroutine/__init__.py +15 -0
  75. dolphin/core/coroutine/context_snapshot.py +154 -0
  76. dolphin/core/coroutine/context_snapshot_profile.py +922 -0
  77. dolphin/core/coroutine/context_snapshot_store.py +268 -0
  78. dolphin/core/coroutine/execution_frame.py +145 -0
  79. dolphin/core/coroutine/execution_state_registry.py +161 -0
  80. dolphin/core/coroutine/resume_handle.py +101 -0
  81. dolphin/core/coroutine/step_result.py +101 -0
  82. dolphin/core/executor/__init__.py +18 -0
  83. dolphin/core/executor/debug_controller.py +630 -0
  84. dolphin/core/executor/dolphin_executor.py +1063 -0
  85. dolphin/core/executor/executor.py +624 -0
  86. dolphin/core/flags/__init__.py +27 -0
  87. dolphin/core/flags/definitions.py +49 -0
  88. dolphin/core/flags/manager.py +113 -0
  89. dolphin/core/hook/__init__.py +95 -0
  90. dolphin/core/hook/expression_evaluator.py +499 -0
  91. dolphin/core/hook/hook_dispatcher.py +380 -0
  92. dolphin/core/hook/hook_types.py +248 -0
  93. dolphin/core/hook/isolated_variable_pool.py +284 -0
  94. dolphin/core/interfaces.py +53 -0
  95. dolphin/core/llm/__init__.py +0 -0
  96. dolphin/core/llm/llm.py +495 -0
  97. dolphin/core/llm/llm_call.py +100 -0
  98. dolphin/core/llm/llm_client.py +1285 -0
  99. dolphin/core/llm/message_sanitizer.py +120 -0
  100. dolphin/core/logging/__init__.py +20 -0
  101. dolphin/core/logging/logger.py +526 -0
  102. dolphin/core/message/__init__.py +8 -0
  103. dolphin/core/message/compressor.py +749 -0
  104. dolphin/core/parser/__init__.py +8 -0
  105. dolphin/core/parser/parser.py +405 -0
  106. dolphin/core/runtime/__init__.py +10 -0
  107. dolphin/core/runtime/runtime_graph.py +926 -0
  108. dolphin/core/runtime/runtime_instance.py +446 -0
  109. dolphin/core/skill/__init__.py +14 -0
  110. dolphin/core/skill/context_retention.py +157 -0
  111. dolphin/core/skill/skill_function.py +686 -0
  112. dolphin/core/skill/skill_matcher.py +282 -0
  113. dolphin/core/skill/skillkit.py +700 -0
  114. dolphin/core/skill/skillset.py +72 -0
  115. dolphin/core/trajectory/__init__.py +10 -0
  116. dolphin/core/trajectory/recorder.py +189 -0
  117. dolphin/core/trajectory/trajectory.py +522 -0
  118. dolphin/core/utils/__init__.py +9 -0
  119. dolphin/core/utils/cache_kv.py +212 -0
  120. dolphin/core/utils/tools.py +340 -0
  121. dolphin/lib/__init__.py +93 -0
  122. dolphin/lib/debug/__init__.py +8 -0
  123. dolphin/lib/debug/visualizer.py +409 -0
  124. dolphin/lib/memory/__init__.py +28 -0
  125. dolphin/lib/memory/async_processor.py +220 -0
  126. dolphin/lib/memory/llm_calls.py +195 -0
  127. dolphin/lib/memory/manager.py +78 -0
  128. dolphin/lib/memory/sandbox.py +46 -0
  129. dolphin/lib/memory/storage.py +245 -0
  130. dolphin/lib/memory/utils.py +51 -0
  131. dolphin/lib/ontology/__init__.py +12 -0
  132. dolphin/lib/ontology/basic/__init__.py +0 -0
  133. dolphin/lib/ontology/basic/base.py +102 -0
  134. dolphin/lib/ontology/basic/concept.py +130 -0
  135. dolphin/lib/ontology/basic/object.py +11 -0
  136. dolphin/lib/ontology/basic/relation.py +63 -0
  137. dolphin/lib/ontology/datasource/__init__.py +27 -0
  138. dolphin/lib/ontology/datasource/datasource.py +66 -0
  139. dolphin/lib/ontology/datasource/oracle_datasource.py +338 -0
  140. dolphin/lib/ontology/datasource/sql.py +845 -0
  141. dolphin/lib/ontology/mapping.py +177 -0
  142. dolphin/lib/ontology/ontology.py +733 -0
  143. dolphin/lib/ontology/ontology_context.py +16 -0
  144. dolphin/lib/ontology/ontology_manager.py +107 -0
  145. dolphin/lib/skill_results/__init__.py +31 -0
  146. dolphin/lib/skill_results/cache_backend.py +559 -0
  147. dolphin/lib/skill_results/result_processor.py +181 -0
  148. dolphin/lib/skill_results/result_reference.py +179 -0
  149. dolphin/lib/skill_results/skillkit_hook.py +324 -0
  150. dolphin/lib/skill_results/strategies.py +328 -0
  151. dolphin/lib/skill_results/strategy_registry.py +150 -0
  152. dolphin/lib/skillkits/__init__.py +44 -0
  153. dolphin/lib/skillkits/agent_skillkit.py +155 -0
  154. dolphin/lib/skillkits/cognitive_skillkit.py +82 -0
  155. dolphin/lib/skillkits/env_skillkit.py +250 -0
  156. dolphin/lib/skillkits/mcp_adapter.py +616 -0
  157. dolphin/lib/skillkits/mcp_skillkit.py +771 -0
  158. dolphin/lib/skillkits/memory_skillkit.py +650 -0
  159. dolphin/lib/skillkits/noop_skillkit.py +31 -0
  160. dolphin/lib/skillkits/ontology_skillkit.py +89 -0
  161. dolphin/lib/skillkits/plan_act_skillkit.py +452 -0
  162. dolphin/lib/skillkits/resource/__init__.py +52 -0
  163. dolphin/lib/skillkits/resource/models/__init__.py +6 -0
  164. dolphin/lib/skillkits/resource/models/skill_config.py +109 -0
  165. dolphin/lib/skillkits/resource/models/skill_meta.py +127 -0
  166. dolphin/lib/skillkits/resource/resource_skillkit.py +393 -0
  167. dolphin/lib/skillkits/resource/skill_cache.py +215 -0
  168. dolphin/lib/skillkits/resource/skill_loader.py +395 -0
  169. dolphin/lib/skillkits/resource/skill_validator.py +406 -0
  170. dolphin/lib/skillkits/resource_skillkit.py +11 -0
  171. dolphin/lib/skillkits/search_skillkit.py +163 -0
  172. dolphin/lib/skillkits/sql_skillkit.py +274 -0
  173. dolphin/lib/skillkits/system_skillkit.py +509 -0
  174. dolphin/lib/skillkits/vm_skillkit.py +65 -0
  175. dolphin/lib/utils/__init__.py +9 -0
  176. dolphin/lib/utils/data_process.py +207 -0
  177. dolphin/lib/utils/handle_progress.py +178 -0
  178. dolphin/lib/utils/security.py +139 -0
  179. dolphin/lib/utils/text_retrieval.py +462 -0
  180. dolphin/lib/vm/__init__.py +11 -0
  181. dolphin/lib/vm/env_executor.py +895 -0
  182. dolphin/lib/vm/python_session_manager.py +453 -0
  183. dolphin/lib/vm/vm.py +610 -0
  184. dolphin/sdk/__init__.py +60 -0
  185. dolphin/sdk/agent/__init__.py +12 -0
  186. dolphin/sdk/agent/agent_factory.py +236 -0
  187. dolphin/sdk/agent/dolphin_agent.py +1106 -0
  188. dolphin/sdk/api/__init__.py +4 -0
  189. dolphin/sdk/runtime/__init__.py +8 -0
  190. dolphin/sdk/runtime/env.py +363 -0
  191. dolphin/sdk/skill/__init__.py +10 -0
  192. dolphin/sdk/skill/global_skills.py +706 -0
  193. dolphin/sdk/skill/traditional_toolkit.py +260 -0
  194. kweaver_dolphin-0.1.0.dist-info/METADATA +521 -0
  195. kweaver_dolphin-0.1.0.dist-info/RECORD +199 -0
  196. kweaver_dolphin-0.1.0.dist-info/WHEEL +5 -0
  197. kweaver_dolphin-0.1.0.dist-info/entry_points.txt +27 -0
  198. kweaver_dolphin-0.1.0.dist-info/licenses/LICENSE.txt +201 -0
  199. kweaver_dolphin-0.1.0.dist-info/top_level.txt +2 -0
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+ """API 模块 - 高级 API 封装"""
3
+
4
+ __all__ = []
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Runtime 模块 - 运行时环境"""
3
+
4
+ from dolphin.sdk.runtime.env import Env
5
+
6
+ __all__ = [
7
+ "Env",
8
+ ]
@@ -0,0 +1,363 @@
1
+ import asyncio
2
+ import logging
3
+ import os
4
+ import glob
5
+ import importlib.util
6
+ import inspect
7
+ import traceback
8
+ from typing import Dict, Optional, AsyncGenerator, Any
9
+
10
+ from dolphin.core.config.global_config import GlobalConfig
11
+ from dolphin.sdk.agent.dolphin_agent import DolphinAgent
12
+ from dolphin.core.logging.logger import console
13
+ from dolphin.sdk.skill.global_skills import GlobalSkills
14
+ from dolphin.core.common.object_type import ObjectTypeFactory
15
+
16
+
17
+ class Env:
18
+ """
19
+ Environment class for managing multiple DPH agents
20
+ """
21
+
22
+ def __init__(
23
+ self,
24
+ globalConfig: GlobalConfig,
25
+ agentFolderPath: str,
26
+ skillkitFolderPath: str | None = None,
27
+ verbose: bool = False,
28
+ is_cli: bool = False,
29
+ log_level: int = logging.INFO,
30
+ output_variables: list[str] = [],
31
+ ):
32
+ """
33
+ Initialize environment with global config and folder path
34
+
35
+ Args:
36
+ globalConfig (GlobalConfig): Global configuration object
37
+ agentFolderPath (str): Directory path to scan for DPH files
38
+ skillkitFolderPath (str): Directory path to scan for custom skillkits
39
+
40
+ Raises:
41
+ ValueError: If folder path doesn't exist
42
+ """
43
+ self.globalConfig = globalConfig
44
+ self.agentFolderPath = agentFolderPath
45
+ self.skillkitFolderPath = skillkitFolderPath
46
+ self.verbose = verbose
47
+ self.is_cli = is_cli
48
+ self.log_level = log_level
49
+ self.agents: Dict[str, DolphinAgent] = {}
50
+ self.output_variables = output_variables
51
+
52
+ # Validate folder existence
53
+ if not os.path.exists(agentFolderPath):
54
+ raise ValueError(f"Agent folder path not found: {agentFolderPath}")
55
+
56
+ # Initialize global skills manager
57
+ self.globalSkills = GlobalSkills(globalConfig)
58
+
59
+ # Initialize global types manager
60
+ self.global_types = ObjectTypeFactory()
61
+
62
+ # Load type definitions from .type files
63
+ self._loadTypeFiles()
64
+
65
+ # Load custom skillkits if specified
66
+ if skillkitFolderPath is not None:
67
+ self._loadCustomSkillkits()
68
+
69
+ # Scan and load agents
70
+ self._scanAndLoadAgents()
71
+
72
+ # Register agents as skills
73
+ self._registerAgentsAsSkills()
74
+
75
+ def _loadTypeFiles(self):
76
+ """
77
+ Scan for .type files in agent folder and load them into global_types
78
+ """
79
+ # Get all .type files recursively
80
+ searchPattern = os.path.join(self.agentFolderPath, "**", "*.type")
81
+ typeFiles = glob.glob(searchPattern, recursive=True)
82
+
83
+ for filePath in typeFiles:
84
+ try:
85
+ self.global_types.load(filePath)
86
+ if self.verbose:
87
+ console(f"Loaded type definition: {filePath}")
88
+ except Exception as e:
89
+ console(f"Failed to load type file {filePath}: {str(e)}")
90
+ continue
91
+
92
+ def _loadCustomSkillkits(self):
93
+ """
94
+ Load all skillkits from custom skillkit folder
95
+ """
96
+ if self.skillkitFolderPath is not None and not os.path.exists(
97
+ self.skillkitFolderPath
98
+ ):
99
+ console(f"Custom skillkit folder not found: {self.skillkitFolderPath}")
100
+ return
101
+
102
+ # Initialize VM if needed
103
+ vm = None
104
+ if (
105
+ hasattr(self.globalConfig, "vm_config")
106
+ and self.globalConfig.vm_config is not None
107
+ ):
108
+ try:
109
+ from dolphin.lib.vm.vm import VMFactory
110
+
111
+ vm = VMFactory.createVM(self.globalConfig.vm_config)
112
+ except Exception as e:
113
+ console(f"Failed to create VM: {str(e)}")
114
+
115
+ # Scan for Python files recursively
116
+ searchPattern = os.path.join(self.skillkitFolderPath, "**", "*.py")
117
+ pythonFiles = glob.glob(searchPattern, recursive=True)
118
+
119
+ for filePath in pythonFiles:
120
+ # Skip __init__.py and __pycache__ files
121
+ if os.path.basename(filePath).startswith("__"):
122
+ continue
123
+
124
+ try:
125
+ # Get module name from file path
126
+ relativePath = os.path.relpath(filePath, self.skillkitFolderPath)
127
+ moduleName = relativePath.replace(os.sep, ".").replace(".py", "")
128
+
129
+ # Load the module dynamically
130
+ spec = importlib.util.spec_from_file_location(moduleName, filePath)
131
+ module = importlib.util.module_from_spec(spec)
132
+ spec.loader.exec_module(module)
133
+
134
+ # Find all Skillkit classes in the module
135
+ for name, obj in inspect.getmembers(module, inspect.isclass):
136
+ # Check if it's a Skillkit subclass but not Skillkit itself
137
+ if (
138
+ hasattr(obj, "__bases__")
139
+ and any(base.__name__ == "Skillkit" for base in obj.__bases__)
140
+ and obj.__name__ != "Skillkit"
141
+ ):
142
+ # Create an instance of the skillkit
143
+ skillkit_instance = obj()
144
+
145
+ # Set VM if this is VMSkillkit and we have a VM configured
146
+ if hasattr(skillkit_instance, "setVM") and vm is not None:
147
+ skillkit_instance.setVM(vm)
148
+
149
+ # Add all skills from this skillkit to the installed skillset
150
+ for skill in skillkit_instance.getSkills():
151
+ self.globalSkills.installedSkillset.addSkill(skill)
152
+
153
+ if self.verbose:
154
+ console(
155
+ f"Loaded custom skillkit: {obj.__name__} from {filePath}"
156
+ )
157
+
158
+ except Exception as e:
159
+ # Log error but continue with other files
160
+ console(f"Failed to load custom skillkit from {filePath}: {str(e)}")
161
+ traceback.print_exc()
162
+ continue
163
+
164
+ def _scanAndLoadAgents(self):
165
+ """
166
+ Scan folder path (including subdirectories) for DPH files and create Agent instances
167
+ """
168
+ # Get all DPH files recursively
169
+ dolphinFiles = self._scanDolphinFiles(self.agentFolderPath)
170
+
171
+ for filePath in dolphinFiles:
172
+ try:
173
+ # Pass the shared GlobalSkills instance and global_types to DolphinAgent
174
+ agent = DolphinAgent(
175
+ file_path=filePath,
176
+ global_config=self.globalConfig,
177
+ global_skills=self.globalSkills,
178
+ global_types=self.global_types,
179
+ verbose=self.verbose,
180
+ is_cli=self.is_cli,
181
+ log_level=self.log_level,
182
+ output_variables=self.output_variables,
183
+ )
184
+ agentName = agent.get_name()
185
+
186
+ # Handle duplicate names by appending directory info
187
+ originalName = agentName
188
+ counter = 1
189
+ while agentName in self.agents:
190
+ agentName = f"{originalName}_{counter}"
191
+ counter += 1
192
+
193
+ self.agents[agentName] = agent
194
+ if self.verbose:
195
+ console(
196
+ f"Loaded agent: {agentName} from {filePath}", verbose=self.verbose
197
+ )
198
+
199
+ except Exception as e:
200
+ console(f"Failed to load agent from {filePath}: {str(e)}")
201
+ continue
202
+
203
+ def _scanDolphinFiles(self, folderPath: str) -> list:
204
+ """
205
+ Scan folder and subdirectories for DPH files
206
+
207
+ Args:
208
+ folderPath (str): Directory path to scan
209
+
210
+ Returns:
211
+ List of DPH file paths
212
+ """
213
+ dolphinFiles = []
214
+
215
+ # Use glob to find all .dph files recursively
216
+ searchPattern = os.path.join(folderPath, "**", "*.dph")
217
+ dolphinFiles.extend(glob.glob(searchPattern, recursive=True))
218
+
219
+ return dolphinFiles
220
+
221
+ def _registerAgentsAsSkills(self):
222
+ """
223
+ Register all loaded agents as skills in the global skills manager
224
+ """
225
+ for agentName, agent in self.agents.items():
226
+ self.globalSkills.registerAgentSkill(agentName, agent)
227
+
228
+ def getAgent(self, agentName: str) -> Optional[DolphinAgent]:
229
+ """
230
+ Get agent by name
231
+
232
+ Args:
233
+ agentName (str): Name of the agent
234
+
235
+ Returns:
236
+ DolphinAgent instance or None if not found
237
+ """
238
+ return self.agents.get(agentName)
239
+
240
+ def getAgents(self) -> Dict[str, DolphinAgent]:
241
+ """
242
+ Get all agents
243
+
244
+ Returns:
245
+ Dictionary of agent name to DolphinAgent instance
246
+ """
247
+ return self.agents.copy()
248
+
249
+ def getAgentNames(self) -> list:
250
+ """
251
+ Get list of all agent names
252
+
253
+ Returns:
254
+ List of agent names
255
+ """
256
+ return list(self.agents.keys())
257
+
258
+ def _setupAgentContext(self, agent):
259
+ """
260
+ Setup agent context with all available agents and skills
261
+
262
+ Args:
263
+ agent: Agent instance to setup
264
+ """
265
+ # Set global skills (including agent skills) into the agent's executor context.
266
+ if hasattr(agent, "executor") and hasattr(agent.executor, "context"):
267
+ allSkills = self.globalSkills.getAllSkills()
268
+ agent.set_skills(allSkills)
269
+
270
+ async def arun(self, agentName: str, **kwargs) -> AsyncGenerator[Any, None]:
271
+ """
272
+ Asynchronously run specified agent
273
+
274
+ Args:
275
+ agentName (str): Name of the agent to run
276
+ **kwargs: Additional arguments to pass to agent
277
+
278
+ Yields:
279
+ Execution results from each step
280
+
281
+ Raises:
282
+ ValueError: If agent not found
283
+ """
284
+ agent = self.getAgent(agentName)
285
+ if agent is None:
286
+ raise ValueError(f"Agent not found: {agentName}")
287
+
288
+ # Ensure that the agent's executor context contains all agents
289
+ self._setupAgentContext(agent)
290
+
291
+ async for result in agent.arun(**kwargs):
292
+ yield result
293
+
294
+ def getGlobalSkills(self) -> GlobalSkills:
295
+ """
296
+ Get the global skills manager
297
+
298
+ Returns:
299
+ GlobalSkills instance
300
+ """
301
+ return self.globalSkills
302
+
303
+ def getGlobalTypes(self) -> ObjectTypeFactory:
304
+ """
305
+ Get the global types manager
306
+
307
+ Returns:
308
+ ObjectTypeFactory instance
309
+ """
310
+ return self.global_types
311
+
312
+ def addAgent(self, agentName: str, agent: DolphinAgent):
313
+ """
314
+ Add a new agent to the environment
315
+
316
+ Args:
317
+ agentName (str): Name for the agent
318
+ agent (DolphinAgent): DolphinAgent instance
319
+ """
320
+ self.agents[agentName] = agent
321
+ self.globalSkills.registerAgentSkill(agentName, agent)
322
+
323
+ async def ashutdown(self):
324
+ """
325
+ Gracefully shutdown the environment and its components asynchronously.
326
+ """
327
+ # Shutdown all agents if they have shutdown methods
328
+ for agent in self.agents.values():
329
+ await agent.terminate()
330
+
331
+ # Clear agents dictionary
332
+ self.agents.clear()
333
+
334
+ def shutdown(self):
335
+ """
336
+ Gracefully shutdown the environment and its components.
337
+ """
338
+ # Shutdown all agents if they have shutdown methods
339
+ for agent in self.agents.values():
340
+ try:
341
+ # Try to get the current event loop
342
+ loop = asyncio.get_event_loop()
343
+ if loop.is_running():
344
+ # If the event loop is running, create a task
345
+ loop.create_task(agent.terminate())
346
+ else:
347
+ # Otherwise run until completion
348
+ loop.run_until_complete(agent.terminate())
349
+ except RuntimeError:
350
+ # If no event loop is running, create a new one.
351
+ asyncio.run(agent.terminate())
352
+
353
+ # Clear agents dictionary
354
+ self.agents.clear()
355
+
356
+ def __str__(self) -> str:
357
+ """
358
+ String representation of the environment
359
+
360
+ Returns:
361
+ Environment description string
362
+ """
363
+ return f"Env(agentFolder={self.agentFolderPath}, skillkitFolder={self.skillkitFolderPath}, agents={len(self.agents)})"
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Skill 模块 - Skill 扩展"""
3
+
4
+ from dolphin.sdk.skill.global_skills import GlobalSkills
5
+ from dolphin.sdk.skill.traditional_toolkit import TriditionalToolkit
6
+
7
+ __all__ = [
8
+ "GlobalSkills",
9
+ "TriditionalToolkit",
10
+ ]