myagent-ai 1.23.44 → 1.23.45
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.
- package/core/context_builder.py +30 -0
- package/package.json +1 -1
package/core/context_builder.py
CHANGED
|
@@ -171,6 +171,7 @@ class ContextBuilder:
|
|
|
171
171
|
self._build_task_plan(task_plan),
|
|
172
172
|
self._build_tools(self.skill_registry),
|
|
173
173
|
self._build_skill_prompts(self.skill_registry),
|
|
174
|
+
self._build_exec_warnings(),
|
|
174
175
|
]
|
|
175
176
|
|
|
176
177
|
context_body = "\n".join(sections)
|
|
@@ -799,6 +800,35 @@ class ContextBuilder:
|
|
|
799
800
|
"""
|
|
800
801
|
return ""
|
|
801
802
|
|
|
803
|
+
def _build_exec_warnings(self) -> str:
|
|
804
|
+
"""[v1.23.44] 构建执行环境警告段落,提醒 Agent 避免常见错误。"""
|
|
805
|
+
import os
|
|
806
|
+
# 检测当前是否运行在 myagent 安装目录下
|
|
807
|
+
_myagent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
808
|
+
_is_in_myagent = (
|
|
809
|
+
os.path.isfile(os.path.join(_myagent_dir, "main.py"))
|
|
810
|
+
and (
|
|
811
|
+
os.path.isfile(os.path.join(_myagent_dir, "start.sh"))
|
|
812
|
+
or os.path.isfile(os.path.join(_myagent_dir, "start.js"))
|
|
813
|
+
)
|
|
814
|
+
)
|
|
815
|
+
|
|
816
|
+
if not _is_in_myagent:
|
|
817
|
+
return ""
|
|
818
|
+
|
|
819
|
+
lines = [
|
|
820
|
+
"<exec_warnings>",
|
|
821
|
+
"【执行环境提醒】你当前运行在 myagent 项目内部。请注意以下限制:",
|
|
822
|
+
"- 禁止执行: python main.py / python3 main.py (这会启动 myagent 服务本身,导致冲突)",
|
|
823
|
+
"- 禁止执行: bash start.sh / ./start.sh (同上,启动脚本)",
|
|
824
|
+
"- 禁止执行: myagent-ai start / myagent-ai run (重复启动服务)",
|
|
825
|
+
"- 如需测试 myagent 模块,请直接 import: python -c 'from agents.main_agent import MainAgent; ...'",
|
|
826
|
+
"- 如需搜索项目代码,请使用: myagent-ai grep <关键词> <路径> (注意: 不支持 -n/-i/-r 等系统 grep 参数)",
|
|
827
|
+
"- 如需操作文件,请使用: myagent-ai file-read / file-write / file-search 等 CLI 命令",
|
|
828
|
+
"</exec_warnings>",
|
|
829
|
+
]
|
|
830
|
+
return "\n".join(lines)
|
|
831
|
+
|
|
802
832
|
# =========================================================================
|
|
803
833
|
# Token 预算管理
|
|
804
834
|
# =========================================================================
|