Skip to content

Commit

Permalink
change research assistant to experimenter
Browse files Browse the repository at this point in the history
  • Loading branch information
cyzus committed Oct 29, 2024
1 parent e0cbbf8 commit 25299e1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion metagpt/ext/sela/data.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
datasets_dir: "path/to/datasets" # path to the datasets directory
work_dir: ../../workspace # path to the workspace directory
work_dir: ../../../workspace # path to the workspace directory
role_dir: storage/SELA # path to the role directory
4 changes: 2 additions & 2 deletions metagpt/ext/sela/experimenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def wrapper(self, *args, **kwargs):
return decorator


class ResearchAssistant(DataInterpreter):
class Experimenter(DataInterpreter):
node_id: str = "0"
start_task_id: int = 1
state_saved: bool = False
Expand All @@ -78,7 +78,7 @@ def change_next_instruction(self, new_instruction):
self.planner.plan.task_map[str(self.start_task_id)].instruction = new_instruction
self.remap_tasks()

def update_til_start_task(self, role: ResearchAssistant, backward: bool = True):
def update_til_start_task(self, role: Experimenter, backward: bool = True):
if backward:
# make sure the previous task instructions are matched
assert (
Expand Down
6 changes: 2 additions & 4 deletions metagpt/ext/sela/runner/random_search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from metagpt.ext.sela.experimenter import ResearchAssistant
from metagpt.ext.sela.experimenter import Experimenter
from metagpt.ext.sela.insights.instruction_generator import InstructionGenerator
from metagpt.ext.sela.runner.runner import Runner
from metagpt.ext.sela.utils import get_exp_pool_path
Expand Down Expand Up @@ -34,9 +34,7 @@ async def run_experiment(self):

results = []
for i in range(self.args.num_experiments):
di = ResearchAssistant(
node_id=str(i), use_reflection=self.args.reflection, role_timeout=self.args.role_timeout
)
di = Experimenter(node_id=str(i), use_reflection=self.args.reflection, role_timeout=self.args.role_timeout)
di.role_dir = f"{di.role_dir}_{self.args.task}"
requirement = user_requirement + EXPS_PROMPT.format(experience=exps[i])
print(requirement)
Expand Down
6 changes: 2 additions & 4 deletions metagpt/ext/sela/runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pandas as pd

from metagpt.ext.sela.evaluation.evaluation import evaluate_score
from metagpt.ext.sela.experimenter import ResearchAssistant
from metagpt.ext.sela.experimenter import Experimenter
from metagpt.ext.sela.search.tree_search import create_initial_state
from metagpt.ext.sela.utils import DATA_CONFIG, save_notebook

Expand Down Expand Up @@ -83,9 +83,7 @@ async def run_experiment(self):
results = []

for i in range(self.args.num_experiments):
di = ResearchAssistant(
node_id="0", use_reflection=self.args.reflection, role_timeout=self.args.role_timeout
)
di = Experimenter(node_id="0", use_reflection=self.args.reflection, role_timeout=self.args.role_timeout)
score_dict = await self.run_di(di, user_requirement, run_idx=i)
results.append(
{"idx": i, "score_dict": score_dict, "user_requirement": user_requirement, "args": vars(self.args)}
Expand Down
12 changes: 6 additions & 6 deletions metagpt/ext/sela/search/tree_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
get_split_dataset_path,
)
from metagpt.ext.sela.evaluation.evaluation import evaluate_score
from metagpt.ext.sela.experimenter import ResearchAssistant, TimeoutException
from metagpt.ext.sela.experimenter import Experimenter, TimeoutException
from metagpt.ext.sela.insights.instruction_generator import InstructionGenerator
from metagpt.ext.sela.utils import get_exp_pool_path, load_execute_notebook, mcts_logger
from metagpt.tools.tool_recommend import ToolRecommender
Expand Down Expand Up @@ -44,9 +44,9 @@ def initialize_di_root_node(state: dict, reflection: bool = True):
reflection (bool, optional): Whether to use reflection. Defaults to True.
Returns:
tuple: A tuple containing the ResearchAssistant role and the root Node.
tuple: A tuple containing the Experimenter role and the root Node.
"""
role = ResearchAssistant(
role = Experimenter(
node_id="0",
start_task_id=state["start_task_id"],
use_reflection=reflection,
Expand Down Expand Up @@ -204,14 +204,14 @@ def load_role(self):
role_dict["tool_recommender"] = ToolRecommender()
elif isinstance(role_dict.get("tool_recommender", {}).get("tools"), dict):
role_dict["tool_recommender"]["tools"] = list(role_dict["tool_recommender"]["tools"].keys())
role = ResearchAssistant(**role_dict)
role = Experimenter(**role_dict)
if self.parent is not None: # TODO: Check this
parent_role = self.parent.load_role()
role.update_til_start_task(parent_role, backward=False)
role.remap_tasks()
return role

def save_new_role(self, role: ResearchAssistant):
def save_new_role(self, role: Experimenter):
role.node_id = self.id
role.start_task_id = self.state["start_task_id"]
role.state_saved = False
Expand Down Expand Up @@ -268,7 +268,7 @@ def evaluate_simulation(self, score_dict):
self.get_and_move_predictions("test")
return score_dict

async def run_node(self, role: ResearchAssistant = None):
async def run_node(self, role: Experimenter = None):
if self.is_terminal() and role is not None:
if role.state_saved:
return self.raw_reward
Expand Down

0 comments on commit 25299e1

Please sign in to comment.