Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Opt Code #1720

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Update Opt Code #1720

wants to merge 5 commits into from

Conversation

MoshiQAQ
Copy link
Contributor

@MoshiQAQ MoshiQAQ commented Feb 26, 2025

Features

  • AFlow 代码重构,目前还是 ActionNode 版本
  • 只整理 HotpotQA,其他数据集代码类似还未上传
  • 目前无详细 log 信息

Feature Docs
python -m metagpt.ext.opt_code.main 运行

Update 03.21
更新内容:

  • 外层的 MetaAgent 负责控制整个流程,为了将 Agent 划分成搜索过程中的独立主体,整个搜索逻辑如下:
class MetaAgent(Role):
    async def run(self, kwargs):
        # Loop start
        if not self.started_search:
            node = await self.initialize(kwargs)
        else:
            node = self.search_algorithm.select_with_strategy(self.search_memory, "greedy")

        trial_node, context = await self.search_algorithm.expand_and_prepare(node, self.search_memory)
        results = await self.experimenter.run(trial_node, context, kwargs["instruction"]) # 由 Agent 生成代码
        self.search_algorithm.update(trial_node, results)
        self.search_memory.update_from_child(trial_node, results)
  • search_algorithm/tree_search.py 中的 TreeSearch 类派生出 AFlowSearchSelaSearch,子类中主要实现 select_prepare_expand_update_global_context 四种方法,其中 _prepare 为 Agent 提供被实验的节点和上下文信息。只变动父类的 select_with_strategy 方法可以实现简单的搜索策略的变更。
  • memory/tree.py 中的 TreeNode 类派生出 AFlowNodeSelaNode,子类中主要实现 update_from_childupdate_from_results(从 Agent 输出结果更新节点)、extend_child(针对 SELA,先有 action 后再 expand 节点)方法。Tree 类派生出的 AFlowMemorySelaMemory 只需要实现 init_root_node 方法即可。
  • opt_roles/experimenter.py 中的 Experimenter 类派生出 AFlowRoleSelaRole,前者用 ActionNode 实现代码的生成,而后者利用 DataInterpreter 进行多步决策来生成完整的 notebook 代码,二者逻辑很难统一。

需要补充的内容:

  • 将代码执行过程从 Agent 中抽离出来,换成由一个 Evaluator 类负责。
  • 抽象后代码在不同数据集上的复现结果。

def _get_file_path(self, id):
return os.path.join(self.root_path, f"round_{id}")

def select_node(self, k=3):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

search module should take care of node selection

还有 bug,有一些路径问题需要修改
@@ -0,0 +1,558 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

execution output should not be committed

pass

@abstractmethod
def select(self) -> TreeNode:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

select method should belong to search algorithm?

Move 'select' to search module, and fix some directory bugs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants