Agenda 方向硬约束:生成 prompt 注入方向原话 + 出域结果确定性拦截#47
Merged
Conversation
#41 只圈了信号消费侧,Tier1/Tier2 的生成 prompt 完全不知道 agenda 存在, taxonomy 匹配不上还会回退全库扫描,实测一个粗差检测方向的 agenda 产出的 5 条 Tier2 idea 全部跑题(RAG/代码生成等)。 - 两个 agent 的全部生成环节(结构检测、形式化、问题提炼、方法设计、实验 设计)在带 agenda 时把方向原话 + focus/prefer 关键词作为硬约束段注入 prompt;不带 agenda 时 prompt 逐字节不变 - 新增 agents/agenda_relevance.py:生成后的规则关键词闸,命中任一范围词 即保留(阈值 AGENDA_SCOPE_MIN_TERM_HITS 可配,默认 1,0 关闭),出域 insight 不入库,计入 dropped_out_of_scope 并记日志 - discover_paradigm_insights / discover_paper_ideas 返回值改为 {insights, dropped_out_of_scope},调度器解包并写入 tier*_done 事件
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
#41 的范围过滤只圈了信号消费侧(taxonomy 节点匹配不上还会回退全库扫描),Tier1(paradigm_agent)和 Tier2(paper_idea_agent)的生成 prompt 完全不知道 agenda 的存在。生产实测:agenda 为「特征对应图上的粗差检测(outlier rejection / correspondence pruning / SfM)」时,产出的 5 条 Tier2 idea 全是 RAG、代码生成、图表达力等无关主题。
改法
两层,生成前约束 + 生成后把关:
1. Prompt 注入(约束生成)
带 agenda 时,把 agenda 的 description(用户方向原话)+ focus / prefer.keywords 作为硬约束段(
# RESEARCH DIRECTION CONSTRAINT)追加到所有生成 prompt 末尾,明确要求只产出落在方向内的内容、忽略无关信号、宁可少产不跑题。注入点:agents/paradigm_agent.py_build_structure_prompt(结构检测)、_build_formalization_prompt(形式化)agents/paper_idea_agent.py_build_problem_prompt(问题提炼)、_build_method_prompt(方法设计)、_build_experiment_prompt(实验设计)Tier1 的第三步对抗评审是裁判不是生成方,不注入。不带 agenda 时所有 prompt 逐字节与现状一致(向后兼容)。
2. 生成后确定性闸(规则,不走 LLM)
新增
agents/agenda_relevance.py:对生成 insight 的文本字段(title / problem_statement / proposed_method,Tier1 另含 formal_structure / transformation)拼接小写后,与 agenda 范围词做子串匹配。范围词 = focus + prefer.keywords 原话短语 + 短语拆词 + description 里的英文词(剔除 model/method/learning 这类万能词)。AGENDA_SCOPE_MIN_TERM_HITS,envDEEPGRAPH_AGENDA_SCOPE_MIN_TERM_HITS,默认 1,设 0 关闭),宁可漏拦不错杀discover_paradigm_insights/discover_paper_ideas返回值改为{"insights": [...], "dropped_out_of_scope": n},调度器解包后把计数写进tier1_done/tier2_done事件和控制台输出,不静默测试
新增
tests/test_agenda_prompt_scoping.py(15 个用例):dropped_out_of_scope == 1、入库 1 条、首个生成 prompt 带约束段全套 pytest:15 failed / 521 passed,失败清单与 master(e98acec,15 failed / 506 passed)逐条相同,无新增失败。