🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
refine code
geekanc9e05a2186cd
diff --git a/metagpt/actions/action.py b/metagpt/actions/action.pyindex 9f045bbaa..cdedfcd64 100644--- a/metagpt/actions/action.py+++ b/metagpt/actions/action.py@@ -10,10 +10,11 @@ from __future__ import annotationsfrom typing import Optional, Union-from pydantic import ConfigDict, Field, model_validator+from pydantic import BaseModel, ConfigDict, Field, model_validatorimport metagptfrom metagpt.actions.action_node import ActionNode+from metagpt.config2 import ConfigMixinfrom metagpt.context import Contextfrom metagpt.llm import LLMfrom metagpt.provider.base_llm import BaseLLM@@ -27,7 +28,7 @@ from metagpt.schema import (from metagpt.utils.file_repository import FileRepository-class Action(SerializationMixin):+class Action(SerializationMixin, ConfigMixin, BaseModel):model_config = ConfigDict(arbitrary_types_allowed=True, exclude=["llm"])name: str = ""diff --git a/metagpt/roles/role.py b/metagpt/roles/role.pyindex 88bab72cb..75dff94f2 100644--- a/metagpt/roles/role.py+++ b/metagpt/roles/role.py@@ -146,6 +146,23 @@ class Role(SerializationMixin, ConfigMixin, BaseModel):__hash__ = object.__hash__ # support Role as hashable type in `Environment.members`+ def __init__(self, **data: Any):+ self.pydantic_rebuild_model()+ super().__init__(**data)++ self.llm.system_prompt = self._get_prefix()+ self._watch(data.get("watch") or [UserRequirement])++ if self.latest_observed_msg:+ self.recovered = True++ @staticmethod+ def pydantic_rebuild_model():+ from metagpt.environment import Environment++ Environment+ Role.model_rebuild()+@propertydef todo(self) -> Action:return self.rc.todo@@ -157,6 +174,9 @@ class Role(SerializationMixin, ConfigMixin, BaseModel):@propertydef config(self):+ """Role config: role config > context config"""+ if self._config:+ return self._configreturn self.context.config@property@@ -177,19 +197,19 @@ class Role(SerializationMixin, ConfigMixin, BaseModel):@propertydef prompt_schema(self):- return self.context.config.prompt_schema+ return self.config.prompt_schema@propertydef project_name(self):- return self.context.config.project_name+ return self.config.project_name@project_name.setterdef project_name(self, value):- self.context.config.project_name = value+ self.config.project_name = value@propertydef project_path(self):- return self.context.config.project_path+ return self.config.project_path@model_validator(mode="after")def check_addresses(self):@@ -197,21 +217,6 @@ class Role(SerializationMixin, ConfigMixin, BaseModel):self.addresses = {any_to_str(self), self.name} if self.name else {any_to_str(self)}return self- def __init__(self, **data: Any):- # --- avoid PydanticUndefinedAnnotation name 'Environment' is not defined #- from metagpt.environment import Environment-- Environment- # ------- Role.model_rebuild()- super().__init__(**data)-- self.llm.system_prompt = self._get_prefix()- self._watch(data.get("watch") or [UserRequirement])-- if self.latest_observed_msg:- self.recovered = True-def _reset(self):self.states = []self.actions = []