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,49 @@
1
+ """Feature Flags Definition
2
+
3
+ All flags are boolean type, representing the on/off status of features.
4
+ """
5
+
6
+ # ============ Code Block Related ============
7
+ EXPLORE_BLOCK_V2 = "explore_block_v2"
8
+ """Enable ExploreBlock V2 implementation
9
+ Scope: Executor, ExploreBlock
10
+ """
11
+
12
+ # ============ Debugging Related ============
13
+ DEBUG_MODE = "debug"
14
+ """Enable debug mode
15
+ Scope: Executor, DebugController
16
+ """
17
+
18
+ # =========== Disable LLM Cache ===========
19
+ DISABLE_LLM_CACHE = "disable_llm_cache"
20
+ """Disable LLM cache
21
+ Scope: LLMClient
22
+ """
23
+
24
+ # =========== Multiple Tool Calls Support ===========
25
+ ENABLE_PARALLEL_TOOL_CALLS = "enable_parallel_tool_calls"
26
+ """Enable multiple tool calls support
27
+
28
+ When enabled:
29
+ - LLM layer parses all tool calls from delta["tool_calls"], not just [0]
30
+ - StreamItem stores multiple tool calls in tool_calls list
31
+ - ExploreBlock executes all detected tool calls sequentially
32
+
33
+ Scope: LLMModelFactory, LLMOpenai, StreamItem, ExploreBlock, ExploreStrategy
34
+
35
+ Note: The flag name uses "parallel" to align with OpenAI's terminology
36
+ ("Parallel Function Calling"), but execution is sequential by default.
37
+ """
38
+
39
+ # Default Value Configuration
40
+ DEFAULT_VALUES = {
41
+ # Code block
42
+ EXPLORE_BLOCK_V2: True,
43
+ # Debugging
44
+ DEBUG_MODE: False,
45
+ # Disable LLM cache
46
+ DISABLE_LLM_CACHE: False,
47
+ # Multiple tool calls (enabled by default)
48
+ ENABLE_PARALLEL_TOOL_CALLS: True,
49
+ }
@@ -0,0 +1,113 @@
1
+ """Feature Flags Management Module (Lightweight + Strict + Concurrent Isolation)
2
+
3
+ Features:
4
+ - Constant Access (prohibits string literals; allows dynamically verified strings from configuration layer)
5
+ - Strict Validation for Unknown Flags (errors in test/development environments, configurable degradation)
6
+ - Scope Overriding Based on ContextVar, Thread/Coroutine Safe
7
+ """
8
+
9
+ from typing import Dict, Mapping
10
+ from contextlib import contextmanager
11
+ from contextvars import ContextVar
12
+ import logging
13
+ import os
14
+
15
+ # Module-level imports, avoid repeated imports inside function bodies
16
+ from .definitions import DEFAULT_VALUES as _DEFAULTS
17
+
18
+ logger = logging.getLogger(__name__)
19
+
20
+ # Known flags set
21
+ _KNOWN_FLAGS = frozenset(_DEFAULTS.keys())
22
+
23
+ # Concurrency context isolation: Maintain independent overrides for each thread/coroutine
24
+ _OVERRIDES: ContextVar[Dict[str, bool]] = ContextVar("DL_FLAGS_OVERRIDES", default={})
25
+
26
+
27
+ def _get_overrides() -> Dict[str, bool]:
28
+ """Get the overlay mapping of the current context (cannot be directly modified in-place)."""
29
+ return dict(_OVERRIDES.get()) # Return a copy to avoid direct shared references being modified
30
+
31
+
32
+ def _set_overrides(new_map: Dict[str, bool]):
33
+ _OVERRIDES.set(new_map)
34
+
35
+
36
+ def _strict_mode() -> bool:
37
+ # Default strict mode enabled (safer for development/testing); disable in production via DL_FLAGS_STRICT=0
38
+ return os.getenv("DL_FLAGS_STRICT", "1") not in {"0", "false", "False"}
39
+
40
+
41
+ def _ensure_known(name: str) -> bool:
42
+ if name in _KNOWN_FLAGS:
43
+ return True
44
+ msg = f"Unknown feature flag: {name}"
45
+ if _strict_mode():
46
+ raise KeyError(msg)
47
+ logger.warning(msg)
48
+ return False
49
+
50
+
51
+ class _FlagsManager:
52
+ """Flag Manager (Singleton)"""
53
+
54
+ def is_enabled(self, name: str) -> bool:
55
+ """Check whether the flag is enabled (string literals are prohibited and must be passed as constant values)."""
56
+ if not _ensure_known(name):
57
+ return False
58
+ overrides = _get_overrides()
59
+ if name in overrides:
60
+ return overrides[name]
61
+ return _DEFAULTS.get(name, False)
62
+
63
+ def set(self, name: str, value: bool) -> None:
64
+ """Set the override value for a single flag."""
65
+ if not _ensure_known(name):
66
+ return
67
+ overrides = _get_overrides()
68
+ overrides[name] = bool(value)
69
+ _set_overrides(overrides)
70
+
71
+ @contextmanager
72
+ def override(self, mapping: Mapping[str, bool]):
73
+ """Temporarily override flags (explicit mapping only).
74
+
75
+ Usage example: with flags.override({flags.EXPLORE_BLOCK_V2: True})
76
+ """
77
+ to_apply: Dict[str, bool] = {}
78
+
79
+ # Strict validation + normalization of boolean
80
+ for name, value in mapping.items():
81
+ if _ensure_known(name):
82
+ to_apply[name] = bool(value)
83
+
84
+ # Save and set new value (scope isolation)
85
+ saved = _get_overrides()
86
+ try:
87
+ new_map = saved.copy()
88
+ new_map.update(to_apply)
89
+ _set_overrides(new_map)
90
+ yield
91
+ finally:
92
+ _set_overrides(saved)
93
+
94
+ def reset(self) -> None:
95
+ """Clear the override values in the current context."""
96
+ _set_overrides({})
97
+
98
+ def get_all(self) -> Dict[str, bool]:
99
+ """Return the current values of all known flags (overrides > defaults)."""
100
+ cur = _get_overrides()
101
+ return {
102
+ name: cur.get(name, _DEFAULTS.get(name, False)) for name in _KNOWN_FLAGS
103
+ }
104
+
105
+
106
+ _manager = _FlagsManager()
107
+
108
+ # Functional facade (for reuse in __init__.py or direct export)
109
+ is_enabled = _manager.is_enabled
110
+ override = _manager.override
111
+ reset = _manager.reset
112
+ get_all = _manager.get_all
113
+ set_flag = _manager.set
@@ -0,0 +1,95 @@
1
+ """Hook Module - Hook-based Verify System
2
+
3
+ This module provides the Hook-based verify functionality for Dolphin Language.
4
+
5
+ Key Components:
6
+ - HookConfig: Configuration for Hook behavior
7
+ - OnStopContext: Context for on_stop hooks
8
+ - HookResult: Standardized verification result
9
+ - HookDispatcher: Core dispatching logic
10
+ - ExpressionEvaluator: Safe expression evaluation
11
+ - IsolatedVariablePool: Read-only variable pool for agents
12
+
13
+ Example Usage:
14
+ ```python
15
+ from dolphin.core.hook import (
16
+ HookConfig,
17
+ OnStopContext,
18
+ HookDispatcher,
19
+ parse_hook_config,
20
+ )
21
+
22
+ # Parse hook config from parameters
23
+ config = parse_hook_config("len($answer) > 100")
24
+
25
+ # Create context from explore output
26
+ context = OnStopContext(
27
+ attempt=1,
28
+ answer="Hello World",
29
+ think="...",
30
+ steps=3,
31
+ tool_calls=[],
32
+ )
33
+
34
+ # Dispatch and get result
35
+ dispatcher = HookDispatcher(config, context, variable_pool)
36
+ result = await dispatcher.dispatch()
37
+
38
+ if result.passed:
39
+ print(f"Verification passed with score: {result.score}")
40
+ else:
41
+ print(f"Verification failed: {result.feedback}")
42
+ ```
43
+ """
44
+
45
+ from dolphin.core.hook.hook_types import (
46
+ HookConfig,
47
+ OnStopContext,
48
+ HookResult,
49
+ HookContextProtocol,
50
+ AgentRef,
51
+ HookError,
52
+ HookValidationError,
53
+ parse_hook_config,
54
+ )
55
+
56
+ from dolphin.core.hook.hook_dispatcher import (
57
+ HookDispatcher,
58
+ FeedbackGenerator,
59
+ )
60
+
61
+ from dolphin.core.hook.expression_evaluator import (
62
+ ExpressionEvaluator,
63
+ ExpressionError,
64
+ )
65
+
66
+ from dolphin.core.hook.isolated_variable_pool import (
67
+ IsolatedVariablePool,
68
+ VariableAccessError,
69
+ )
70
+
71
+ __all__ = [
72
+ # Types
73
+ 'HookConfig',
74
+ 'OnStopContext',
75
+ 'HookResult',
76
+ 'HookContextProtocol',
77
+ 'AgentRef',
78
+ 'HookError',
79
+ 'HookValidationError',
80
+
81
+ # Functions
82
+ 'parse_hook_config',
83
+
84
+ # Dispatcher
85
+ 'HookDispatcher',
86
+ 'FeedbackGenerator',
87
+
88
+ # Expression
89
+ 'ExpressionEvaluator',
90
+ 'ExpressionError',
91
+
92
+ # Variable Pool
93
+ 'IsolatedVariablePool',
94
+ 'VariableAccessError',
95
+ ]