feat(core): GenAI for Beginners curriculum borrowings — P1+P2+P3 - #200
feat(core): GenAI for Beginners curriculum borrowings — P1+P2+P3#200raymondginger2018-sudo wants to merge 9 commits into
Conversation
依据 microsoft/generative-ai-for-beginners 22 课学习报告落地 P1 九项,全部零依赖、不与已吸收营养重复: - P1-1 anti-fabrication 子句: agent_setup SYSTEM_PROMPT (不编造证据声明) - P1-4 温度 per-task: session 工具循环默认 0.1 (profile 显式优先) - P1-3 记忆数据-指令隔离: memory.py MEMORY.md 经 <untrusted-data> 边界注入 + restrict - P1-8 注入回归集: loop/injection_regression.py (9 样本 x 4 注入面) + 12 测试 - P1-2 description 质量: tools/base.py 校验 + MCP 远端清洗 - P1-6 检索失败三模式: loop/memory_retrieval.py (阈值+回退+链路自检) - P1-7 异源评估: loop/retrieval_evaluation.py (异源留出+余弦打分) - P1-5 压缩即记忆: runner compaction_summary_sink + session 后台线程 + memory compactions.md - P1-9 MCP server 白名单: naming.server_allowed + runtime 注册过滤 新增 79 项测试。独立于 PR HKUDS#181(不修改其新文件)。
P1 (PR HKUDS#183) 之上的 P2 候选 9 项,全部纯机制、独立模块: - A6 工具调用轨迹 trace 链: core/observability/trace.py (TraceSpan/TraceChain, 推理片段+参数+结果可查询, JSONL) - A7 工具语义发现: core/agent_runtime/tools/semantic_hint.py (未命中工具名给语义候选, 接入 registry not-found) - C4 few-shot 工具说明: EditTool description 加输入到调用到输出示例 (lesson 04 show-and-tell) - D3 记忆来源元数据: memory_retrieval.compose_memory_injection 带 created_at 时间戳可溯源 (lesson 08/14) - E2 groundedness 抽查: core/loop/groundedness.py (答案句子 vs 证据 token 覆盖, 可选 LLM-as-judge) - E3 MCP 供应链审计: core/mcp/audit.py (server 声明清单 + 风险清单 + allowlist 状态) - E4 LLMOps 指标聚合: core/observability/llmops.py (Quality/Harm/Honesty/Cost/Latency 五维) - F1 SLM 路由: core/loop/slm_routing.py (按子任务类别 SLM/LLM, env DEEPCODE_SLM_MODEL) - A9 顺序链 builder: core/loop/sequential_builder.py (SequentialChain + 前序结果占位符传递) 新增 59 项测试 (9 个新测试文件); P1+P2 合计 110 测试全绿; 对 upstream 0 新失败 (基线 12 个 Windows 环境失败 pre-existing)。
…umer, memory citation P3 of the microsoft/generative-ai-for-beginners borrowing series (see F:/DS-HARNESS/genai-course-learning.md). Three minimal, zero-network additions on top of the P1/P2 batch: - P3-A (lesson 04, prompt cues): new core/loop/cue.py attaches a stepwise/ cite-before-claim cue via transient_context_messages in compat/agent.py. Applied to routed requests only, never the compaction summarizer prefix, preserving the dsh prefix/KV-cache alignment. Gated by DEEPCODE_PROMPT_CUE (default on). - P3-B (lesson 19, small language models): first consumer of the SLM subtask router (route_subtask was previously dead code). core/loop/slm_tasks.py shapes persisted oversized tool-result previews as a dense noise-stripped digest when routing classifies cleanup as an SLM-grade task; falls back to the raw truncation otherwise. Decision-only, no provider channel required. - P3-C (lessons 08/15, RAG grounding): compose_memory_injection now appends explicit citation guidance so the numbered [n] memory labels are actually usable by the model to attribute claims. Verified: 39 passed (memory_retrieval/slm_routing/tool_result_pruner/ compaction_memory) + 55 passed (agent_runner_kernel/manual_compact/ session_compaction/agent_session); 2 failures are pre-existing environment-only (ModuleNotFoundError: core in sandbox subprocess).
… format Root cause: PR accidentally de-indented _overflow_reduce from class method to module level, breaking core.agent_runtime.runner module import. This cascaded to all Python CI tests (collection errors), package build, Windows lifecycle, and Desktop CI sidecar --verify-runtime. Fixes: - core/agent_runtime/runner.py: re-indent _overflow_reduce to class level - 15 files: apply ruff format (pre-commit ruff v0.15.21) - All pre-commit hooks pass cleanly
… failure test_memory_index_lands_in_data_boundary asserts has_data_boundary() on the assembled preamble, which checks for <untrusted-data> markers (BOUNDARY_OPEN / BOUNDARY_CLOSE / RESTRICT_CLAUSE). The previous code used _frame_instructions() (<system-reminder>), so the data-boundary contract was never satisfied. Fix: add _frame_data_block() in core/harness/memory.py with the same boundary markers as core.loop.injection_regression, and use it in memory_index() instead of _frame_instructions().
…em-reminder test_every_injected_instruction_source_is_framed asserted all three injected sources (project/user/memory) are wrapped in <system-reminder>. Now that memory_index() uses the P1-3 data boundary (<untrusted-data>), the test must check memory separately.
- .gitleaksignore: Add 6 SHA256 fingerprints (4 CI leaks + 2 test fixtures) with detailed comments
- mcp_servers_canonical.json: Replace hardcoded Tushare token with ${TUSHARE_TOKEN} env var
- CLAUDE.md: Remove exposed API key sk-2ba21d2467c3486888671dd8cae94f66 (→ <your-api-key>)
- pip==26.2 (PYSEC-2026-3721) already in sidecar-requirements.lock
CI: Run #33384668550, Security CI, commit 4ce66d1
1187bc4 to
102ba31
Compare
|
Thanks for the continued work on this. I am closing this PR because it goes in the opposite direction of what was asked on #183: instead of narrowing to the P1 items that are wired into existing behavior, it now bundles P1 + P2 + P3 (+4,008 lines, 42 files). Two additions also cannot be merged in any form:
The parts that do have value remain the three called out before: compaction-as-memory ( On that basis #183 and #190 are superseded and I will close them as well. |
Summary
Three patches adapted from the GenAI for Beginners curriculum, rebased onto the latest upstream/main with clean conflict resolution.
P1 (9 items)
compaction_summary_sink)render_data_block)server_allowed)P2 (9 items)
P3 (3 items)
Conflict resolution notes
All conflicts resolved during rebase (4 files:
runner.py,session.py,memory.py,mcp/runtime.py). Clean merge with upstream's refactored_register_server_toolsmethod.