feat: enable to inject diversity cross async multi-trace#1173
Merged
xuangu-fang merged 7 commits intomainfrom Aug 18, 2025
Merged
feat: enable to inject diversity cross async multi-trace#1173xuangu-fang merged 7 commits intomainfrom
xuangu-fang merged 7 commits intomainfrom
Conversation
…iversity injection
… handling in experiment generation
licong01-cloud
pushed a commit
to licong01-cloud/RD-Agent
that referenced
this pull request
Dec 13, 2025
) * init multi_trace_async_ diversity inject * lint * add task in context for diversity injection, add abstract class for diversity injection * lint * feat: update diversity injection strategy and enhance sibling context handling in experiment generation * add always inject --------- Co-authored-by: Xu Yang <peteryang@vip.qq.com>
yongbin4
pushed a commit
to yongbin4/RD-Agent
that referenced
this pull request
Mar 8, 2026
) * init multi_trace_async_ diversity inject * lint * add task in context for diversity injection, add abstract class for diversity injection * lint * feat: update diversity injection strategy and enhance sibling context handling in experiment generation * add always inject --------- Co-authored-by: Xu Yang <peteryang@vip.qq.com>
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.
1. 目标
在
trace_scheduler决定开启一个新的探索分支(trace)时,系统应能参考其他已存在分支(包括正在进行但未提交的分支)的探索方向(即Hypothesis),并基于这些信息生成一个具有多样性、避免重复的新探索方向。此功能应可通过配置开启或关闭。2. 核心设计思想的演进
核心思想如下:
**kwargs或修改gen()方法的签名来传递上下文。DSTrace对象将作为信息传递的核心载体。在生成新假说之前,相关的多样性上下文信息会被临时注入到DSTrace实例中。DSProposalV2ExpGen在执行时直接从DSTrace对象中读取这些上下文,执行完毕后,上下文将被清理。inject_diverse逻辑明确区分开,使用新的配置项和变量名,避免混淆。3. 模块化设计与修改计划
3.1. 配置 (
rdagent/app/data_science/conf.py)DataScienceBasePropSetting类中增加一个新的布尔型标志位,用于控制此功能的开关。enable_cross_trace_diversity: bool = Trueenable_inject_diverse。3.2.
TraceScheduler模块 (rdagent/scenarios/data_science/proposal/exp_gen/trace_scheduler.py)TraceScheduler的核心职责不变,但其与router的交互方式将简化。BaseScheduler:self.uncommitted_experiments: dict[int, DSExperiment] = {}来追踪那些由async_gen创建但尚未被record方法提交的实验。register_uncommitted_exp和deregister_uncommitted_exp方法。新增get_uncommitted_hypotheses()方法,用于返回所有未提交实验的Hypothesis列表。next()方法 (签名简化): 返回签名恢复为tuple[int, ...]。它不再需要返回context字典,只负责选择下一个节点。3.3.
DSTrace模块 (rdagent/scenarios/data_science/proposal/exp_gen/base.py)DSTrace将变得更加智能,能够提供多样性分析所需的上下文。contextual_hypotheses: list[DSHypothesis] | None = None: 一个临时属性,用于存储需要用于多样性生成的其他分支的假说。set_contextual_hypotheses(self, hypotheses: list[DSHypothesis] | None) -> None: 用于设置和清理contextual_hypotheses。get_committed_root_hypotheses(self) -> list[DSHypothesis]: (实现细节澄清) 此方法将遍历self.dag_parent,找到所有父节点为self.NEW_ROOT(()) 的条目,这些条目对应的索引就是每个分支的根节点实验。然后从self.hist中获取这些实验并提取其Hypothesis。这个方法提供了已提交分支的探索起点。3.4. Router 模块 (
rdagent/scenarios/data_science/proposal/exp_gen/router/__init__.py)ParallelMultiTraceExpGen将成为协调者,负责组装上下文并注入DSTrace。ParallelMultiTraceExpGen.async_gen():DS_RD_SETTING.enable_cross_trace_diversity是否为True。如果不是,则跳过所有多样性注入逻辑。self.trace_scheduler.next()返回一个新分支选择(trace.NEW_ROOT)时:self.trace_scheduler.get_uncommitted_hypotheses()获取所有正在进行的实验假说。trace.get_committed_root_hypotheses()获取所有已提交分支的根假说。all_hypotheses。trace.set_contextual_hypotheses(all_hypotheses),将上下文注入trace对象。gen与清理:try...finally结构来确保上下文在之后被清理。exp对象成功创建后,立即调用self.trace_scheduler.register_uncommitted_exp(exp, loop.loop_idx)。3.5. Proposal 模块 (
rdagent/scenarios/data_science/proposal/exp_gen/proposal.py)DSProposalV2ExpGen现在可以从trace中直接获取所需信息。DSProposalV2ExpGen.gen():trace.contextual_hypotheses获取用于多样性注入的假说列表。cross_trace_hypotheses以区别于现有的inject_diverse逻辑。cross_trace_hypotheses存在,则将其格式化并整合到传递给identify_problem方法的上下文中。identify_problem()及相关 prompt:identify_problem中,将cross_trace_hypotheses的信息格式化为一个字符串。.prompts_v2:scenario_problem.system(位于prompts_v2.yaml),增加一个新的输入字段,用于接收其他分支的假说信息,并明确指示 LLM 基于这些信息提出不同于已有方向的新挑战。📚 Documentation preview 📚: https://RDAgent--1173.org.readthedocs.build/en/1173/