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,82 @@
|
|
|
1
|
+
from typing import List, Dict, Optional
|
|
2
|
+
from dolphin.core.skill.skill_function import SkillFunction
|
|
3
|
+
from dolphin.core.skill.skillkit import Skillkit
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CognitiveSkillkit(Skillkit):
|
|
7
|
+
# Use Skillkit's generic compressor, override default rules for this kit
|
|
8
|
+
DEFAULT_COMPRESS_RULES: Dict[str, Dict[str, List[str]]] = {
|
|
9
|
+
"_cog_think": {"include": ["action"]},
|
|
10
|
+
"_cog_gen_sql": {"include": ["sql_generation"]},
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
def getName(self) -> str:
|
|
14
|
+
return "cognitive_skillkit"
|
|
15
|
+
|
|
16
|
+
def _cog_think(self, reflection: str, plan: str, action: str, **kwargs) -> str:
|
|
17
|
+
"""
|
|
18
|
+
A tool for structured reasoning and planning, enabling users to break down complex problems into reflection, planning, and actionable steps.
|
|
19
|
+
Stores thoughts in memory for complex reasoning. No need to plan every time, just plan every 2 steps.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
reflection (str): Analysis, assumptions, insights, or summary of prior steps. May contain errors, emphasizing deep reasoning.
|
|
23
|
+
plan (str): A plan breaking down the problem into executable steps.
|
|
24
|
+
action (str): Specific, executable, and verifiable next steps, potentially involving tool calls.
|
|
25
|
+
**kwargs: Additional properties passed to the tool.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
str: Formatted string of the reasoning step.
|
|
29
|
+
"""
|
|
30
|
+
return f"""
|
|
31
|
+
reflection: {reflection}
|
|
32
|
+
plan: {plan}
|
|
33
|
+
action: {action}
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def _cog_gen_sql(
|
|
37
|
+
self, reflection: str, schema_link: str, sql_generation: str, **kwargs
|
|
38
|
+
) -> str:
|
|
39
|
+
"""Tools for structured SQL generation, including reasoning steps that decompose complex SQL generation into reflection, schema analysis, and SQL construction.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
reflection (str): Problem analysis, understanding requirements, and reasoning about query structure.
|
|
43
|
+
schema_link (str): Database schema analysis, table relationships, and field mappings relevant to the query.
|
|
44
|
+
sql_generation (str): Actual SQL statement generation, including specific syntax and logical implementation.
|
|
45
|
+
**kwargs: Additional attributes passed to the tool.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
str: Formatted string of the SQL generation process.
|
|
49
|
+
"""
|
|
50
|
+
return f"""
|
|
51
|
+
reflection: {reflection}
|
|
52
|
+
schema_link: {schema_link}
|
|
53
|
+
sql_generation: {sql_generation}
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
def _createSkills(self) -> List[SkillFunction]:
|
|
57
|
+
return [
|
|
58
|
+
SkillFunction(self._cog_think),
|
|
59
|
+
SkillFunction(self._cog_gen_sql),
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
@staticmethod
|
|
63
|
+
def is_cognitive_skill(skillname: str) -> bool:
|
|
64
|
+
return skillname.startswith("_cog_think") or skillname.startswith(
|
|
65
|
+
"_cog_gen_sql"
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
@staticmethod
|
|
69
|
+
def compress_msg(
|
|
70
|
+
message: str, rules: Optional[Dict[str, Dict[str, List[str]]]] = None
|
|
71
|
+
) -> str:
|
|
72
|
+
"""Delegates to generic compressor in Skillkit, using this kit's default rules unless overridden."""
|
|
73
|
+
active_rules = rules or CognitiveSkillkit.DEFAULT_COMPRESS_RULES
|
|
74
|
+
# Reuse generic logic and regex-based scanning in base Skillkit
|
|
75
|
+
return Skillkit.compress_message_with_rules(
|
|
76
|
+
message, rules=active_rules, marker_prefix="=>#"
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
@staticmethod
|
|
80
|
+
def set_compress_rules(rules: Dict[str, Dict[str, List[str]]]):
|
|
81
|
+
"""Set default compression rules for cognitive messages at runtime."""
|
|
82
|
+
CognitiveSkillkit.DEFAULT_COMPRESS_RULES = rules or {}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Environment Skillkit - Unified execution environment for Python and Bash
|
|
4
|
+
|
|
5
|
+
This skillkit provides _python and _bash tools that execute in the
|
|
6
|
+
configured environment (local, VM, Docker, etc.). The execution
|
|
7
|
+
environment is determined by configuration, not by the tool name.
|
|
8
|
+
|
|
9
|
+
This replaces both vm_skillkit and local_skillkit with a unified interface.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from typing import List, Optional
|
|
13
|
+
|
|
14
|
+
from dolphin.core.skill.skill_function import SkillFunction
|
|
15
|
+
from dolphin.core.skill.skillkit import Skillkit
|
|
16
|
+
from dolphin.core.config.global_config import GlobalConfig
|
|
17
|
+
from dolphin.lib.vm.env_executor import EnvExecutor, LocalExecutor, create_executor
|
|
18
|
+
from dolphin.core.logging.logger import get_logger
|
|
19
|
+
from dolphin.core.skill.context_retention import context_retention
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
logger = get_logger("env_skillkit")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class EnvSkillkit(Skillkit):
|
|
26
|
+
"""
|
|
27
|
+
Unified skillkit for executing Python and Bash commands.
|
|
28
|
+
|
|
29
|
+
The execution environment (local, VM, Docker, etc.) is determined
|
|
30
|
+
by configuration. This provides a consistent API regardless of
|
|
31
|
+
where the code actually runs.
|
|
32
|
+
|
|
33
|
+
Configuration:
|
|
34
|
+
# For local execution (default)
|
|
35
|
+
env:
|
|
36
|
+
type: local
|
|
37
|
+
working_dir: /path/to/workdir # optional
|
|
38
|
+
|
|
39
|
+
# For VM execution
|
|
40
|
+
vm:
|
|
41
|
+
host: localhost
|
|
42
|
+
port: 22
|
|
43
|
+
username: user
|
|
44
|
+
# ...
|
|
45
|
+
|
|
46
|
+
Usage:
|
|
47
|
+
# Same tools work in any environment
|
|
48
|
+
_python("print('Hello')")
|
|
49
|
+
_bash("ls -la")
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
def __init__(self, executor: Optional[EnvExecutor] = None):
|
|
53
|
+
"""
|
|
54
|
+
Initialize the environment skillkit.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
executor: Optional executor to use. If not provided,
|
|
58
|
+
will be created from config when setGlobalConfig is called.
|
|
59
|
+
"""
|
|
60
|
+
super().__init__()
|
|
61
|
+
self._executor = executor
|
|
62
|
+
self._global_config: Optional[GlobalConfig] = None
|
|
63
|
+
|
|
64
|
+
def getName(self) -> str:
|
|
65
|
+
return "env_skillkit"
|
|
66
|
+
|
|
67
|
+
def setGlobalConfig(self, config: GlobalConfig):
|
|
68
|
+
"""
|
|
69
|
+
Set global config and initialize executor if needed.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
config: Global configuration object
|
|
73
|
+
"""
|
|
74
|
+
self._global_config = config
|
|
75
|
+
|
|
76
|
+
# Create executor from config if not already set
|
|
77
|
+
if self._executor is None:
|
|
78
|
+
try:
|
|
79
|
+
self._executor = create_executor(config)
|
|
80
|
+
logger.info(f"Created executor: {type(self._executor).__name__}")
|
|
81
|
+
except Exception as e:
|
|
82
|
+
logger.warning(f"Failed to create executor from config: {e}")
|
|
83
|
+
# Fallback to local executor
|
|
84
|
+
self._executor = LocalExecutor()
|
|
85
|
+
logger.info("Falling back to LocalExecutor")
|
|
86
|
+
|
|
87
|
+
def setExecutor(self, executor: EnvExecutor):
|
|
88
|
+
"""
|
|
89
|
+
Explicitly set the executor.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
executor: EnvExecutor instance to use
|
|
93
|
+
"""
|
|
94
|
+
self._executor = executor
|
|
95
|
+
|
|
96
|
+
def _get_executor(self) -> EnvExecutor:
|
|
97
|
+
"""Get the executor, creating a local one if needed."""
|
|
98
|
+
if self._executor is None:
|
|
99
|
+
self._executor = LocalExecutor()
|
|
100
|
+
return self._executor
|
|
101
|
+
|
|
102
|
+
@context_retention(mode="summary", max_length=500)
|
|
103
|
+
def _bash(self, cmd: str = "", **kwargs) -> str:
|
|
104
|
+
"""Execute a Bash command in the configured environment.
|
|
105
|
+
|
|
106
|
+
The command runs in the environment specified by configuration:
|
|
107
|
+
- Local machine (default)
|
|
108
|
+
- Remote VM (if vm config is present)
|
|
109
|
+
- Docker container (if docker config is present)
|
|
110
|
+
|
|
111
|
+
Note: Commands are executed non-interactively (stdin is closed).
|
|
112
|
+
You MUST use '-y', '--force', or similar flags for commands that normally prompt for confirmation.
|
|
113
|
+
|
|
114
|
+
Timeout Behavior:
|
|
115
|
+
- Default timeout is 60 seconds
|
|
116
|
+
- If a command exceeds the timeout, it returns a command_id
|
|
117
|
+
- Call _bash again with command_id to continue waiting or cancel
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
cmd (str): The Bash command to execute. Leave empty if using command_id.
|
|
121
|
+
timeout (int): Command timeout in seconds. Default is 60 seconds.
|
|
122
|
+
If exceeded, returns a command_id for continuation.
|
|
123
|
+
Maximum allowed is 3600 (1 hour).
|
|
124
|
+
command_id (str): ID of a previous timed-out command to continue waiting for.
|
|
125
|
+
cancel (bool): If True and command_id is provided, cancel the command.
|
|
126
|
+
background (bool): If True, run as a detached background process.
|
|
127
|
+
Use for long-running servers that should not block.
|
|
128
|
+
|
|
129
|
+
Returns:
|
|
130
|
+
str: The command output (stdout and stderr), or:
|
|
131
|
+
- Startup status for background commands
|
|
132
|
+
- Timeout message with command_id for long-running commands
|
|
133
|
+
|
|
134
|
+
Examples:
|
|
135
|
+
# Quick commands complete normally
|
|
136
|
+
_bash("ls -la")
|
|
137
|
+
|
|
138
|
+
# For potentially slow commands, increase timeout upfront
|
|
139
|
+
_bash("npm install", timeout=300)
|
|
140
|
+
|
|
141
|
+
# If a command times out, you get a command_id like "abc12345"
|
|
142
|
+
# Then continue waiting or cancel:
|
|
143
|
+
_bash(command_id="abc12345", timeout=60) # wait 60 more seconds
|
|
144
|
+
_bash(command_id="abc12345", cancel=True) # cancel the command
|
|
145
|
+
|
|
146
|
+
# For servers/daemons, use background mode
|
|
147
|
+
_bash("./server.sh", background=True)
|
|
148
|
+
"""
|
|
149
|
+
executor = self._get_executor()
|
|
150
|
+
|
|
151
|
+
# Handle command continuation/cancellation
|
|
152
|
+
command_id = kwargs.get("command_id")
|
|
153
|
+
cancel = kwargs.get("cancel", False)
|
|
154
|
+
|
|
155
|
+
if command_id:
|
|
156
|
+
if not hasattr(executor, "wait_command"):
|
|
157
|
+
return "Error: command continuation is only supported in local execution mode"
|
|
158
|
+
|
|
159
|
+
if cancel:
|
|
160
|
+
return executor.cancel_command(command_id)
|
|
161
|
+
else:
|
|
162
|
+
timeout = kwargs.get("timeout", 60)
|
|
163
|
+
return executor.wait_command(command_id, timeout=timeout)
|
|
164
|
+
|
|
165
|
+
# Regular command execution
|
|
166
|
+
if not cmd:
|
|
167
|
+
return "Error: cmd is required when not using command_id"
|
|
168
|
+
|
|
169
|
+
# Pass session ID from context if available
|
|
170
|
+
session_id = self.getSessionId(
|
|
171
|
+
session_id=kwargs.get("session_id"),
|
|
172
|
+
props=kwargs.get("props")
|
|
173
|
+
)
|
|
174
|
+
if session_id:
|
|
175
|
+
kwargs["session_id"] = session_id
|
|
176
|
+
|
|
177
|
+
return executor.exec_bash(cmd, **kwargs)
|
|
178
|
+
|
|
179
|
+
@context_retention(mode="summary", max_length=2000)
|
|
180
|
+
def _python(self, cmd: str, **kwargs) -> str:
|
|
181
|
+
"""Execute Python code in the configured environment.
|
|
182
|
+
|
|
183
|
+
The code runs in the environment specified by configuration:
|
|
184
|
+
- Local machine (default)
|
|
185
|
+
- Remote VM (if vm config is present)
|
|
186
|
+
- Docker container (if docker config is present)
|
|
187
|
+
|
|
188
|
+
Supports session state persistence, running like Jupyter notebooks.
|
|
189
|
+
|
|
190
|
+
Args:
|
|
191
|
+
cmd (str): The Python code to execute.
|
|
192
|
+
Assign results to 'return_value' for explicit returns.
|
|
193
|
+
**kwargs: Additional parameters:
|
|
194
|
+
- cwd: Working directory for execution
|
|
195
|
+
- session_id: Session identifier for state persistence
|
|
196
|
+
|
|
197
|
+
Returns:
|
|
198
|
+
str: Execution result including stdout and return_value if set
|
|
199
|
+
|
|
200
|
+
Examples:
|
|
201
|
+
# Simple calculation
|
|
202
|
+
_python("x = 1 + 2; print(x)")
|
|
203
|
+
|
|
204
|
+
# Using return_value
|
|
205
|
+
_python("return_value = [1, 2, 3]")
|
|
206
|
+
|
|
207
|
+
# Stateful execution (variables persist)
|
|
208
|
+
_python("data = load_data()")
|
|
209
|
+
_python("result = process(data)") # 'data' is available
|
|
210
|
+
"""
|
|
211
|
+
executor = self._get_executor()
|
|
212
|
+
|
|
213
|
+
# Pass session ID from context if available
|
|
214
|
+
session_id = self.getSessionId(
|
|
215
|
+
session_id=kwargs.get("session_id"),
|
|
216
|
+
props=kwargs.get("props")
|
|
217
|
+
)
|
|
218
|
+
if session_id:
|
|
219
|
+
kwargs["session_id"] = session_id
|
|
220
|
+
|
|
221
|
+
return executor.exec_python(cmd, **kwargs)
|
|
222
|
+
|
|
223
|
+
def _get_env_info(self) -> str:
|
|
224
|
+
"""Get information about the current execution environment.
|
|
225
|
+
|
|
226
|
+
Returns:
|
|
227
|
+
str: JSON string containing environment details:
|
|
228
|
+
- type: 'local' or 'vm'
|
|
229
|
+
- working_dir: Current working directory (if local)
|
|
230
|
+
- connected: Connection status
|
|
231
|
+
"""
|
|
232
|
+
import json
|
|
233
|
+
executor = self._get_executor()
|
|
234
|
+
|
|
235
|
+
info = {
|
|
236
|
+
"type": executor.env_type,
|
|
237
|
+
"connected": executor.is_connected()
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if executor.env_type == "local" and hasattr(executor, "working_dir"):
|
|
241
|
+
info["working_dir"] = getattr(executor, "working_dir")
|
|
242
|
+
|
|
243
|
+
return json.dumps(info, indent=2)
|
|
244
|
+
|
|
245
|
+
def _createSkills(self) -> List[SkillFunction]:
|
|
246
|
+
return [
|
|
247
|
+
SkillFunction(self._bash, block_as_parameter=("bash", "cmd")),
|
|
248
|
+
SkillFunction(self._python, block_as_parameter=("python", "cmd")),
|
|
249
|
+
SkillFunction(self._get_env_info),
|
|
250
|
+
]
|