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.
- DolphinLanguageSDK/__init__.py +58 -0
- dolphin/__init__.py +62 -0
- dolphin/cli/__init__.py +20 -0
- dolphin/cli/args/__init__.py +9 -0
- dolphin/cli/args/parser.py +567 -0
- dolphin/cli/builtin_agents/__init__.py +22 -0
- dolphin/cli/commands/__init__.py +4 -0
- dolphin/cli/interrupt/__init__.py +8 -0
- dolphin/cli/interrupt/handler.py +205 -0
- dolphin/cli/interrupt/keyboard.py +82 -0
- dolphin/cli/main.py +49 -0
- dolphin/cli/multimodal/__init__.py +34 -0
- dolphin/cli/multimodal/clipboard.py +327 -0
- dolphin/cli/multimodal/handler.py +249 -0
- dolphin/cli/multimodal/image_processor.py +214 -0
- dolphin/cli/multimodal/input_parser.py +149 -0
- dolphin/cli/runner/__init__.py +8 -0
- dolphin/cli/runner/runner.py +989 -0
- dolphin/cli/ui/__init__.py +10 -0
- dolphin/cli/ui/console.py +2795 -0
- dolphin/cli/ui/input.py +340 -0
- dolphin/cli/ui/layout.py +425 -0
- dolphin/cli/ui/stream_renderer.py +302 -0
- dolphin/cli/utils/__init__.py +8 -0
- dolphin/cli/utils/helpers.py +135 -0
- dolphin/cli/utils/version.py +49 -0
- dolphin/core/__init__.py +107 -0
- dolphin/core/agent/__init__.py +10 -0
- dolphin/core/agent/agent_state.py +69 -0
- dolphin/core/agent/base_agent.py +970 -0
- dolphin/core/code_block/__init__.py +0 -0
- dolphin/core/code_block/agent_init_block.py +0 -0
- dolphin/core/code_block/assign_block.py +98 -0
- dolphin/core/code_block/basic_code_block.py +1865 -0
- dolphin/core/code_block/explore_block.py +1327 -0
- dolphin/core/code_block/explore_block_v2.py +712 -0
- dolphin/core/code_block/explore_strategy.py +672 -0
- dolphin/core/code_block/judge_block.py +220 -0
- dolphin/core/code_block/prompt_block.py +32 -0
- dolphin/core/code_block/skill_call_deduplicator.py +291 -0
- dolphin/core/code_block/tool_block.py +129 -0
- dolphin/core/common/__init__.py +17 -0
- dolphin/core/common/constants.py +176 -0
- dolphin/core/common/enums.py +1173 -0
- dolphin/core/common/exceptions.py +133 -0
- dolphin/core/common/multimodal.py +539 -0
- dolphin/core/common/object_type.py +165 -0
- dolphin/core/common/output_format.py +432 -0
- dolphin/core/common/types.py +36 -0
- dolphin/core/config/__init__.py +16 -0
- dolphin/core/config/global_config.py +1289 -0
- dolphin/core/config/ontology_config.py +133 -0
- dolphin/core/context/__init__.py +12 -0
- dolphin/core/context/context.py +1580 -0
- dolphin/core/context/context_manager.py +161 -0
- dolphin/core/context/var_output.py +82 -0
- dolphin/core/context/variable_pool.py +356 -0
- dolphin/core/context_engineer/__init__.py +41 -0
- dolphin/core/context_engineer/config/__init__.py +5 -0
- dolphin/core/context_engineer/config/settings.py +402 -0
- dolphin/core/context_engineer/core/__init__.py +7 -0
- dolphin/core/context_engineer/core/budget_manager.py +327 -0
- dolphin/core/context_engineer/core/context_assembler.py +583 -0
- dolphin/core/context_engineer/core/context_manager.py +637 -0
- dolphin/core/context_engineer/core/tokenizer_service.py +260 -0
- dolphin/core/context_engineer/example/incremental_example.py +267 -0
- dolphin/core/context_engineer/example/traditional_example.py +334 -0
- dolphin/core/context_engineer/services/__init__.py +5 -0
- dolphin/core/context_engineer/services/compressor.py +399 -0
- dolphin/core/context_engineer/utils/__init__.py +6 -0
- dolphin/core/context_engineer/utils/context_utils.py +441 -0
- dolphin/core/context_engineer/utils/message_formatter.py +270 -0
- dolphin/core/context_engineer/utils/token_utils.py +139 -0
- dolphin/core/coroutine/__init__.py +15 -0
- dolphin/core/coroutine/context_snapshot.py +154 -0
- dolphin/core/coroutine/context_snapshot_profile.py +922 -0
- dolphin/core/coroutine/context_snapshot_store.py +268 -0
- dolphin/core/coroutine/execution_frame.py +145 -0
- dolphin/core/coroutine/execution_state_registry.py +161 -0
- dolphin/core/coroutine/resume_handle.py +101 -0
- dolphin/core/coroutine/step_result.py +101 -0
- dolphin/core/executor/__init__.py +18 -0
- dolphin/core/executor/debug_controller.py +630 -0
- dolphin/core/executor/dolphin_executor.py +1063 -0
- dolphin/core/executor/executor.py +624 -0
- dolphin/core/flags/__init__.py +27 -0
- dolphin/core/flags/definitions.py +49 -0
- dolphin/core/flags/manager.py +113 -0
- dolphin/core/hook/__init__.py +95 -0
- dolphin/core/hook/expression_evaluator.py +499 -0
- dolphin/core/hook/hook_dispatcher.py +380 -0
- dolphin/core/hook/hook_types.py +248 -0
- dolphin/core/hook/isolated_variable_pool.py +284 -0
- dolphin/core/interfaces.py +53 -0
- dolphin/core/llm/__init__.py +0 -0
- dolphin/core/llm/llm.py +495 -0
- dolphin/core/llm/llm_call.py +100 -0
- dolphin/core/llm/llm_client.py +1285 -0
- dolphin/core/llm/message_sanitizer.py +120 -0
- dolphin/core/logging/__init__.py +20 -0
- dolphin/core/logging/logger.py +526 -0
- dolphin/core/message/__init__.py +8 -0
- dolphin/core/message/compressor.py +749 -0
- dolphin/core/parser/__init__.py +8 -0
- dolphin/core/parser/parser.py +405 -0
- dolphin/core/runtime/__init__.py +10 -0
- dolphin/core/runtime/runtime_graph.py +926 -0
- dolphin/core/runtime/runtime_instance.py +446 -0
- dolphin/core/skill/__init__.py +14 -0
- dolphin/core/skill/context_retention.py +157 -0
- dolphin/core/skill/skill_function.py +686 -0
- dolphin/core/skill/skill_matcher.py +282 -0
- dolphin/core/skill/skillkit.py +700 -0
- dolphin/core/skill/skillset.py +72 -0
- dolphin/core/trajectory/__init__.py +10 -0
- dolphin/core/trajectory/recorder.py +189 -0
- dolphin/core/trajectory/trajectory.py +522 -0
- dolphin/core/utils/__init__.py +9 -0
- dolphin/core/utils/cache_kv.py +212 -0
- dolphin/core/utils/tools.py +340 -0
- dolphin/lib/__init__.py +93 -0
- dolphin/lib/debug/__init__.py +8 -0
- dolphin/lib/debug/visualizer.py +409 -0
- dolphin/lib/memory/__init__.py +28 -0
- dolphin/lib/memory/async_processor.py +220 -0
- dolphin/lib/memory/llm_calls.py +195 -0
- dolphin/lib/memory/manager.py +78 -0
- dolphin/lib/memory/sandbox.py +46 -0
- dolphin/lib/memory/storage.py +245 -0
- dolphin/lib/memory/utils.py +51 -0
- dolphin/lib/ontology/__init__.py +12 -0
- dolphin/lib/ontology/basic/__init__.py +0 -0
- dolphin/lib/ontology/basic/base.py +102 -0
- dolphin/lib/ontology/basic/concept.py +130 -0
- dolphin/lib/ontology/basic/object.py +11 -0
- dolphin/lib/ontology/basic/relation.py +63 -0
- dolphin/lib/ontology/datasource/__init__.py +27 -0
- dolphin/lib/ontology/datasource/datasource.py +66 -0
- dolphin/lib/ontology/datasource/oracle_datasource.py +338 -0
- dolphin/lib/ontology/datasource/sql.py +845 -0
- dolphin/lib/ontology/mapping.py +177 -0
- dolphin/lib/ontology/ontology.py +733 -0
- dolphin/lib/ontology/ontology_context.py +16 -0
- dolphin/lib/ontology/ontology_manager.py +107 -0
- dolphin/lib/skill_results/__init__.py +31 -0
- dolphin/lib/skill_results/cache_backend.py +559 -0
- dolphin/lib/skill_results/result_processor.py +181 -0
- dolphin/lib/skill_results/result_reference.py +179 -0
- dolphin/lib/skill_results/skillkit_hook.py +324 -0
- dolphin/lib/skill_results/strategies.py +328 -0
- dolphin/lib/skill_results/strategy_registry.py +150 -0
- dolphin/lib/skillkits/__init__.py +44 -0
- dolphin/lib/skillkits/agent_skillkit.py +155 -0
- dolphin/lib/skillkits/cognitive_skillkit.py +82 -0
- dolphin/lib/skillkits/env_skillkit.py +250 -0
- dolphin/lib/skillkits/mcp_adapter.py +616 -0
- dolphin/lib/skillkits/mcp_skillkit.py +771 -0
- dolphin/lib/skillkits/memory_skillkit.py +650 -0
- dolphin/lib/skillkits/noop_skillkit.py +31 -0
- dolphin/lib/skillkits/ontology_skillkit.py +89 -0
- dolphin/lib/skillkits/plan_act_skillkit.py +452 -0
- dolphin/lib/skillkits/resource/__init__.py +52 -0
- dolphin/lib/skillkits/resource/models/__init__.py +6 -0
- dolphin/lib/skillkits/resource/models/skill_config.py +109 -0
- dolphin/lib/skillkits/resource/models/skill_meta.py +127 -0
- dolphin/lib/skillkits/resource/resource_skillkit.py +393 -0
- dolphin/lib/skillkits/resource/skill_cache.py +215 -0
- dolphin/lib/skillkits/resource/skill_loader.py +395 -0
- dolphin/lib/skillkits/resource/skill_validator.py +406 -0
- dolphin/lib/skillkits/resource_skillkit.py +11 -0
- dolphin/lib/skillkits/search_skillkit.py +163 -0
- dolphin/lib/skillkits/sql_skillkit.py +274 -0
- dolphin/lib/skillkits/system_skillkit.py +509 -0
- dolphin/lib/skillkits/vm_skillkit.py +65 -0
- dolphin/lib/utils/__init__.py +9 -0
- dolphin/lib/utils/data_process.py +207 -0
- dolphin/lib/utils/handle_progress.py +178 -0
- dolphin/lib/utils/security.py +139 -0
- dolphin/lib/utils/text_retrieval.py +462 -0
- dolphin/lib/vm/__init__.py +11 -0
- dolphin/lib/vm/env_executor.py +895 -0
- dolphin/lib/vm/python_session_manager.py +453 -0
- dolphin/lib/vm/vm.py +610 -0
- dolphin/sdk/__init__.py +60 -0
- dolphin/sdk/agent/__init__.py +12 -0
- dolphin/sdk/agent/agent_factory.py +236 -0
- dolphin/sdk/agent/dolphin_agent.py +1106 -0
- dolphin/sdk/api/__init__.py +4 -0
- dolphin/sdk/runtime/__init__.py +8 -0
- dolphin/sdk/runtime/env.py +363 -0
- dolphin/sdk/skill/__init__.py +10 -0
- dolphin/sdk/skill/global_skills.py +706 -0
- dolphin/sdk/skill/traditional_toolkit.py +260 -0
- kweaver_dolphin-0.1.0.dist-info/METADATA +521 -0
- kweaver_dolphin-0.1.0.dist-info/RECORD +199 -0
- kweaver_dolphin-0.1.0.dist-info/WHEEL +5 -0
- kweaver_dolphin-0.1.0.dist-info/entry_points.txt +27 -0
- kweaver_dolphin-0.1.0.dist-info/licenses/LICENSE.txt +201 -0
- kweaver_dolphin-0.1.0.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"""Agent factory class, used to create agents of different types"""
|
|
2
|
+
|
|
3
|
+
from typing import Dict, Any, Optional, Type
|
|
4
|
+
from dolphin.core.config.global_config import GlobalConfig
|
|
5
|
+
from dolphin.core.agent.base_agent import BaseAgent
|
|
6
|
+
from dolphin.sdk.agent.dolphin_agent import DolphinAgent
|
|
7
|
+
from dolphin.core.logging.logger import get_logger
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AgentFactory:
|
|
11
|
+
"""Agent Factory Class"""
|
|
12
|
+
|
|
13
|
+
def __init__(self):
|
|
14
|
+
self._agent_types: Dict[str, Type[BaseAgent]] = {}
|
|
15
|
+
self._default_config: Dict[str, Any] = {}
|
|
16
|
+
|
|
17
|
+
# Register default Agent type
|
|
18
|
+
self.register_agent_type("dolphin", DolphinAgent)
|
|
19
|
+
|
|
20
|
+
def register_agent_type(self, name: str, agent_class: Type[BaseAgent]):
|
|
21
|
+
"""Register Agent Type"""
|
|
22
|
+
if not issubclass(agent_class, BaseAgent):
|
|
23
|
+
raise ValueError(
|
|
24
|
+
f"Agent class {agent_class.__name__} must inherit from BaseAgent"
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
self._agent_types[name] = agent_class
|
|
28
|
+
self._logger.debug(f"Registered agent type: {name} -> {agent_class.__name__}")
|
|
29
|
+
|
|
30
|
+
def unregister_agent_type(self, name: str):
|
|
31
|
+
"""Deregister Agent Type"""
|
|
32
|
+
if name in self._agent_types:
|
|
33
|
+
del self._agent_types[name]
|
|
34
|
+
self._logger.debug(f"Unregistered agent type: {name}")
|
|
35
|
+
|
|
36
|
+
def get_agent_types(self) -> Dict[str, Type[BaseAgent]]:
|
|
37
|
+
"""Get all registered Agent types"""
|
|
38
|
+
return self._agent_types.copy()
|
|
39
|
+
|
|
40
|
+
def set_default_config(self, agent_type: str, config: Dict[str, Any]):
|
|
41
|
+
"""Set the default configuration for Agent types"""
|
|
42
|
+
self._default_config[agent_type] = config
|
|
43
|
+
|
|
44
|
+
def get_default_config(self, agent_type: str) -> Dict[str, Any]:
|
|
45
|
+
"""Get the default configuration for the Agent type"""
|
|
46
|
+
return self._default_config.get(agent_type, {})
|
|
47
|
+
|
|
48
|
+
def create_agent(self, agent_type: str, name: str, **kwargs) -> BaseAgent:
|
|
49
|
+
"""Create an Agent instance
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
agent_type: Name of the Agent type
|
|
53
|
+
name: Name of the Agent instance
|
|
54
|
+
**kwargs: Initialization parameters for the Agent
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
Agent instance
|
|
58
|
+
|
|
59
|
+
Raises:
|
|
60
|
+
ValueError: Unknown Agent type
|
|
61
|
+
"""
|
|
62
|
+
if agent_type not in self._agent_types:
|
|
63
|
+
available_types = list(self._agent_types.keys())
|
|
64
|
+
raise ValueError(
|
|
65
|
+
f"Unknown agent type '{agent_type}'. Available types: {available_types}"
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
agent_class = self._agent_types[agent_type]
|
|
69
|
+
default_config = self._default_config.get(agent_type, {})
|
|
70
|
+
|
|
71
|
+
# Merge default configuration with the passed-in configuration
|
|
72
|
+
# Note: Remove config from kwargs to avoid duplicate passing
|
|
73
|
+
agent_kwargs = kwargs.copy()
|
|
74
|
+
config_from_kwargs = agent_kwargs.pop("global_config", {})
|
|
75
|
+
config_from_kwargs = agent_kwargs.pop("config", {})
|
|
76
|
+
if config_from_kwargs is not None:
|
|
77
|
+
merged_config = {**default_config, **config_from_kwargs}
|
|
78
|
+
else:
|
|
79
|
+
merged_config = default_config
|
|
80
|
+
try:
|
|
81
|
+
agent = agent_class(
|
|
82
|
+
name=name,
|
|
83
|
+
global_config=GlobalConfig.from_dict(merged_config),
|
|
84
|
+
**agent_kwargs,
|
|
85
|
+
)
|
|
86
|
+
self._logger.debug(f"Created {agent_type} agent: {name}")
|
|
87
|
+
return agent
|
|
88
|
+
except Exception as e:
|
|
89
|
+
raise RuntimeError(
|
|
90
|
+
f"Failed to create {agent_type} agent '{name}': {str(e)}"
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
def create_dolphin_agent(
|
|
94
|
+
self,
|
|
95
|
+
file_path: str,
|
|
96
|
+
global_config: GlobalConfig | None,
|
|
97
|
+
name: Optional[str] = None,
|
|
98
|
+
**kwargs,
|
|
99
|
+
) -> BaseAgent:
|
|
100
|
+
"""A convenient method to create a Dolphin Agent
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
file_path: DPH file path
|
|
104
|
+
global_config: Global configuration
|
|
105
|
+
name: Agent name
|
|
106
|
+
**kwargs: Additional parameters
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
DolphinAgent instance
|
|
110
|
+
"""
|
|
111
|
+
if name is None:
|
|
112
|
+
import os
|
|
113
|
+
|
|
114
|
+
name = os.path.splitext(os.path.basename(file_path))[0]
|
|
115
|
+
|
|
116
|
+
return self.create_agent(
|
|
117
|
+
agent_type="dolphin",
|
|
118
|
+
name=name,
|
|
119
|
+
file_path=file_path,
|
|
120
|
+
global_config=global_config,
|
|
121
|
+
**kwargs,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
def create_agent_from_config(self, config: Dict[str, Any]) -> BaseAgent:
|
|
125
|
+
"""Create an Agent from a configuration dictionary
|
|
126
|
+
|
|
127
|
+
Args:
|
|
128
|
+
config: Agent configuration dictionary
|
|
129
|
+
|
|
130
|
+
Returns:
|
|
131
|
+
Agent instance
|
|
132
|
+
"""
|
|
133
|
+
required_fields = ["type", "name"]
|
|
134
|
+
for field in required_fields:
|
|
135
|
+
if field not in config:
|
|
136
|
+
raise ValueError(f"Missing required field '{field}' in agent config")
|
|
137
|
+
|
|
138
|
+
return self.create_agent(
|
|
139
|
+
agent_type=config["type"],
|
|
140
|
+
name=config["name"],
|
|
141
|
+
**{k: v for k, v in config.items() if k not in ["type", "name"]},
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
@property
|
|
145
|
+
def _logger(self):
|
|
146
|
+
"""Get logger"""
|
|
147
|
+
|
|
148
|
+
return get_logger("agent.agent_factory")
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
# Global Agent Factory Instance
|
|
152
|
+
_global_agent_factory = AgentFactory()
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def get_agent_factory() -> AgentFactory:
|
|
156
|
+
"""Get the global Agent factory instance"""
|
|
157
|
+
return _global_agent_factory
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def create_agent(agent_type: str, name: str, **kwargs) -> BaseAgent:
|
|
161
|
+
"""Convenient Agent Creation Function"""
|
|
162
|
+
return get_agent_factory().create_agent(agent_type, name, **kwargs)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def create_dolphin_agent(
|
|
166
|
+
file_path: str,
|
|
167
|
+
global_config: GlobalConfig | None,
|
|
168
|
+
name: Optional[str] = None,
|
|
169
|
+
**kwargs,
|
|
170
|
+
) -> BaseAgent:
|
|
171
|
+
"""Convenient Dolphin Agent creation function"""
|
|
172
|
+
return get_agent_factory().create_dolphin_agent(
|
|
173
|
+
file_path, global_config, name, **kwargs
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
# Predefined Agent Configuration Templates
|
|
178
|
+
AGENT_TEMPLATES = {
|
|
179
|
+
"basic_dolphin": {
|
|
180
|
+
"type": "dolphin",
|
|
181
|
+
"global_config": {"enable_logging": True, "timeout": 300},
|
|
182
|
+
},
|
|
183
|
+
"analysis_dolphin": {
|
|
184
|
+
"type": "dolphin",
|
|
185
|
+
"global_config": {
|
|
186
|
+
"enable_logging": True,
|
|
187
|
+
"timeout": 600,
|
|
188
|
+
"enable_profiling": True,
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
"chat_dolphin": {
|
|
192
|
+
"type": "dolphin",
|
|
193
|
+
"global_config": {
|
|
194
|
+
"enable_logging": True,
|
|
195
|
+
"timeout": 180,
|
|
196
|
+
"enable_memory": True,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def create_agent_from_template(
|
|
203
|
+
template_name: str, name: str, **template_overrides
|
|
204
|
+
) -> BaseAgent:
|
|
205
|
+
"""Create Agent from template
|
|
206
|
+
|
|
207
|
+
Args:
|
|
208
|
+
template_name: Template name
|
|
209
|
+
name: Agent name
|
|
210
|
+
template_overrides: Template parameter overrides
|
|
211
|
+
|
|
212
|
+
Returns:
|
|
213
|
+
Agent instance
|
|
214
|
+
"""
|
|
215
|
+
if template_name not in AGENT_TEMPLATES:
|
|
216
|
+
available_templates = list(AGENT_TEMPLATES.keys())
|
|
217
|
+
raise ValueError(
|
|
218
|
+
f"Unknown template '{template_name}'. Available templates: {available_templates}"
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
template = AGENT_TEMPLATES[template_name].copy()
|
|
222
|
+
|
|
223
|
+
# Application Coverage Parameters
|
|
224
|
+
if (
|
|
225
|
+
"global_config" in template_overrides
|
|
226
|
+
and template_overrides.pop("global_config") is not None
|
|
227
|
+
):
|
|
228
|
+
template["global_config"] = {
|
|
229
|
+
**template.get("global_config", {}),
|
|
230
|
+
**template_overrides.pop("global_config"),
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
template.update(template_overrides)
|
|
234
|
+
template["name"] = name
|
|
235
|
+
|
|
236
|
+
return get_agent_factory().create_agent_from_config(template)
|