DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(code-execution): preserve deliverable scope and retry discipline
XZH7615e36bb854
diff --git a/deeptutor/agents/chat/prompts/en/agentic_chat.yaml b/deeptutor/agents/chat/prompts/en/agentic_chat.yamlindex f20d85bf7..6de49a0d8 100644--- a/deeptutor/agents/chat/prompts/en/agentic_chat.yaml+++ b/deeptutor/agents/chat/prompts/en/agentic_chat.yaml@@ -84,6 +84,12 @@ loop:without that list, do not claim a file was created. If an extended tool islisted but not loaded, call load_tools first with the exact tool name.+ Preserve explicit user quantities and other scope constraints exactly. If+ code fails, exits nonzero, or an expected artifact is missing, diagnose the+ stderr or root cause and change strategy; never resubmit identical code.+ After repeated failures with the same cause, stop and report the failure+ honestly instead of reducing scope or claiming success.+Tool names, parameter names, source ids, knowledge-base names, notebookids, and skill names must be copied verbatim from the prompt blocks ortool schemas — never invent them. Arguments must be concrete anddiff --git a/deeptutor/agents/chat/prompts/zh/agentic_chat.yaml b/deeptutor/agents/chat/prompts/zh/agentic_chat.yamlindex 12e9bd130..a525970c0 100644--- a/deeptutor/agents/chat/prompts/zh/agentic_chat.yaml+++ b/deeptutor/agents/chat/prompts/zh/agentic_chat.yaml@@ -60,6 +60,10 @@ loop:没有这个清单就不要宣称已创建文件。如果 Extended Tools 里列出的工具尚未加载,先用精确工具名调用 load_tools。+ 必须完整保留用户明确给出的数量和其他范围约束。代码失败、退出码非零或预期产物缺失时,+ 先诊断 stderr 或根因并更换策略;绝不原样重复提交同一份代码。同一原因多次失败后,+ 停止执行并如实报告失败,不要缩小范围或宣称成功。+工具名、参数名、source id、知识库名、笔记本 id 和 skill 名必须从提示词块或工具 schema 中逐字复制,不要编造。参数必须具体、可执行;空查询和占位符无效。user: |-diff --git a/deeptutor/skills/builtin/pdf/SKILL.md b/deeptutor/skills/builtin/pdf/SKILL.mdindex 30c596f5b..792c2a661 100644--- a/deeptutor/skills/builtin/pdf/SKILL.md+++ b/deeptutor/skills/builtin/pdf/SKILL.md@@ -21,6 +21,7 @@ Work PDFs in the sandbox with preinstalled Python libs. Pick the library by taskWrite complete Python source and run it via `code_execution`. Save outputs to the workspace dir.After execution, refer to the PDF exactly as the Generated artifacts list names it. Use `exec` only for a genuinely shell-only command; never put this source in `python -c` or a heredoc.+Preserve an explicitly requested quantity (such as 500 words) and verify the count in the output before finishing. If execution fails or the artifact is missing, diagnose stderr/root cause and change strategy; do not retry identical code or reduce the requested scope without asking.## Extract text and tables (pdfplumber)diff --git a/deeptutor/tools/builtin/__init__.py b/deeptutor/tools/builtin/__init__.pyindex 00373249b..f8e0b181e 100644--- a/deeptutor/tools/builtin/__init__.py+++ b/deeptutor/tools/builtin/__init__.py@@ -347,7 +347,10 @@ class CodeExecutionTool(_PromptHintsMixin, BaseTool):"complete, ready-to-run source in `code` and pick `language` ""(python, c, or cpp). Use it for calculation, data processing, ""and code-generated deliverables instead of embedding source in "- "an exec command. Print concise results to stdout."+ "an exec command. Preserve explicit quantities and scope; after "+ "failure or a missing artifact, diagnose the cause and change "+ "strategy rather than retrying identical code. Print concise "+ "results to stdout."),parameters=[ToolParameter(diff --git a/deeptutor/tools/prompting/hints/en/code_execution.yaml b/deeptutor/tools/prompting/hints/en/code_execution.yamlindex 0ab1f6d24..bd7396cf8 100644--- a/deeptutor/tools/prompting/hints/en/code_execution.yaml+++ b/deeptutor/tools/prompting/hints/en/code_execution.yaml@@ -1,7 +1,7 @@short_description: "Run a code snippet (python/c/cpp) in an isolated sandbox; returns stdout/stderr and generated files."when_to_use: "Use for computation, verification, data processing, or creating a file with Python instead of embedding source in a shell command."input_format: "`language` (python, c, or cpp) + `code` — the complete, ready-to-run source. Optional `stdin` and `timeout` (seconds, default 30)."-guideline: "Write complete source yourself, save output files to the working directory, and print a concise completion message. Never run this source through exec with `python -c` or a heredoc; use exec only for a command that is genuinely shell-only."+guideline: "Write complete source yourself, save output files to the working directory, and print a concise completion message. Never run this source through exec with `python -c` or a heredoc; use exec only for a command that is genuinely shell-only. Preserve explicit quantities and scope; diagnose stderr or the root cause after failure or a missing artifact, change strategy, and never resubmit identical code."note: "Runs in this turn's workspace under the same OS-isolated sandbox as `exec`; unavailable when no sandbox backend is configured. Save generated files to the working directory to surface them as artifacts."phase: "verification"aliases:diff --git a/deeptutor/tools/prompting/hints/zh/code_execution.yaml b/deeptutor/tools/prompting/hints/zh/code_execution.yamlindex 6693ab887..0457924f7 100644--- a/deeptutor/tools/prompting/hints/zh/code_execution.yaml+++ b/deeptutor/tools/prompting/hints/zh/code_execution.yaml@@ -1,7 +1,7 @@short_description: "在隔离沙箱中运行一段代码(python/c/cpp),返回 stdout/stderr 和生成文件。"when_to_use: "用于计算、校验、数据处理,或用 Python 生成文件,而不是把源码嵌进 shell 命令。"input_format: "`language`(python、c 或 cpp)+ `code`——完整、可直接运行的源码。可选 `stdin` 与 `timeout`(秒,默认 30)。"-guideline: "自行写出完整源码,把输出文件保存到当前工作目录,并打印简短完成信息。绝不要通过 exec 的 `python -c` 或 heredoc 运行这段源码;exec 只用于真正必须使用 shell 的命令。"+guideline: "自行写出完整源码,把输出文件保存到当前工作目录,并打印简短完成信息。绝不要通过 exec 的 `python -c` 或 heredoc 运行这段源码;exec 只用于真正必须使用 shell 的命令。完整保留明确的数量和范围;失败或产物缺失时先诊断 stderr 或根因,更换策略,绝不原样重复提交代码。"note: "在本回合 workspace 内运行,与 `exec` 共用同一套 OS 级隔离沙箱;未配置沙箱后端时不可用。把生成文件保存到工作目录即可作为产物输出。"phase: "verification"aliases:diff --git a/tests/tools/test_code_execution_guidance.py b/tests/tools/test_code_execution_guidance.pyindex 13559fac6..9f6f10922 100644--- a/tests/tools/test_code_execution_guidance.py+++ b/tests/tools/test_code_execution_guidance.py@@ -19,9 +19,20 @@ def test_code_execution_schema_and_hints_cover_file_generation() -> None:assert "python -c" in hint.guidelineassert "heredoc" in hint.guidelineassert "code_execution" in exec_hint.guideline+ assert "Preserve explicit quantities and scope" in definition.description+ assert "never resubmit identical code" in hint.guidelinedef test_code_execution_guidance_is_bilingual() -> None:+ scope_rules = {+ "en": "Preserve explicit quantities and scope",+ "zh": "完整保留明确的数量和范围",+ }+ retry_rules = {+ "en": "never resubmit identical code",+ "zh": "绝不原样重复提交代码",+ }+for language in ("en", "zh"):hint = load_prompt_hints("code_execution", language=language)exec_hint = load_prompt_hints("exec", language=language)@@ -32,6 +43,8 @@ def test_code_execution_guidance_is_bilingual() -> None:assert "code_execution" in exec_hint.guidelineassert "python -c" in exec_hint.guidelineassert "heredoc" in exec_hint.guideline+ assert scope_rules[language] in hint.guideline+ assert retry_rules[language] in hint.guidelinedef test_chat_prompts_prefer_code_execution_for_python_files() -> None:@@ -40,6 +53,14 @@ def test_chat_prompts_prefer_code_execution_for_python_files() -> None:"en": "without that list, do not claim a file was created","zh": "没有这个清单就不要宣称已创建文件",}+ scope_rules = {+ "en": "Preserve explicit user quantities and other scope constraints exactly",+ "zh": "必须完整保留用户明确给出的数量和其他范围约束",+ }+ retry_rules = {+ "en": "never resubmit identical code",+ "zh": "绝不原样重复提交同一份代码",+ }for language in ("en", "zh"):data = yaml.safe_load((root / language / "agentic_chat.yaml").read_text())@@ -48,6 +69,8 @@ def test_chat_prompts_prefer_code_execution_for_python_files() -> None:assert "python -c" in promptassert "heredoc" in promptassert missing_artifact_warnings[language] in prompt+ assert scope_rules[language] in prompt+ assert retry_rules[language] in promptdef test_solve_prompts_route_python_files_to_code_execution() -> None:@@ -72,3 +95,13 @@ def test_office_skills_use_code_execution_for_python_deliverables() -> None:assert "code_execution" in documentassert "python -c" in documentassert "heredoc" in document+++def test_pdf_skill_preserves_requested_scope_and_requires_changed_retries() -> None:+ root = Path(__file__).parents[2] / "deeptutor" / "skills" / "builtin"+ document = (root / "pdf" / "SKILL.md").read_text()++ assert "such as 500 words" in document+ assert "verify the count in the output before finishing" in document+ assert "do not retry identical code" in document+ assert "reduce the requested scope without asking" in document