Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

update to pydantic v2 and fix conflicts

better629e7c7c88c4776
diff --cc metagpt/actions/action.py
index 576990a83,5dbb36332..4136d7599
--- a/metagpt/actions/action.py
+++ b/metagpt/actions/action.py
@@@ -22,23 -23,17 +23,17 @@@ from metagpt.schema import
TestingContext,
)
- action_subclass_registry = {}
+ class Action(SerDeserMixin, is_polymorphic_base=True):
+ model_config = ConfigDict(arbitrary_types_allowed=True, exclude=["llm"])
- class Action(BaseModel):
name: str = ""
- llm: BaseGPTAPI = Field(default_factory=LLM, exclude=True)
+ llm: BaseLLM = Field(default_factory=LLM, exclude=True)
context: Union[dict, CodingContext, CodeSummarizeContext, TestingContext, RunCodeContext, str, None] = ""
- prefix = "" # aask*时会加上prefix,作为system_message
- desc = "" # for skill manager
+ prefix: str = "" # aask*时会加上prefix,作为system_message
+ desc: str = "" # for skill manager
node: ActionNode = Field(default=None, exclude=True)
- # builtin variables
- builtin_class_name: str = ""
-
- class Config:
- arbitrary_types_allowed = True
-
def __init_with_instruction(self, instruction: str):
"""Initialize action with instruction"""
self.node = ActionNode(key=self.name, expected_type=str, instruction=instruction, example="", schema="raw")
diff --cc metagpt/actions/research.py
index a6cc7cc22,e0669297b..a1535a723
--- a/metagpt/actions/research.py
+++ b/metagpt/actions/research.py
@@@ -82,8 -82,8 +82,9 @@@ class CollectLinks(Action)
name: str = "CollectLinks"
context: Optional[str] = None
+ llm: BaseLLM = Field(default_factory=LLM)
desc: str = "Collect links from a search engine."
+
search_engine: SearchEngine = Field(default_factory=SearchEngine)
rank_func: Union[Callable[[list[str]], None], None] = None
diff --cc metagpt/actions/write_prd_review.py
index 0241f192f,2babe38db..9199e7536
--- a/metagpt/actions/write_prd_review.py
+++ b/metagpt/actions/write_prd_review.py
@@@ -18,7 -14,7 +18,8 @@@ from metagpt.provider.base_llm import B
class WritePRDReview(Action):
name: str = ""
context: Optional[str] = None
+ llm: BaseLLM = Field(default_factory=LLM)
+
prd: Optional[str] = None
desc: str = "Based on the PRD, conduct a PRD Review, providing clear and detailed feedback"
prd_review_prompt_template: str = """
diff --cc metagpt/roles/role.py
index d6e874ffe,623832083..2b8209758
--- a/metagpt/roles/role.py
+++ b/metagpt/roles/role.py
@@@ -36,8 -35,8 +35,8 @@@ from metagpt.const import SERDESER_PAT
from metagpt.llm import LLM, HumanProvider
from metagpt.logs import logger
from metagpt.memory import Memory
-from metagpt.provider.base_gpt_api import BaseGPTAPI
+from metagpt.provider.base_llm import BaseLLM
- from metagpt.schema import Message, MessageQueue
+ from metagpt.schema import Message, MessageQueue, SerDeserMixin
from metagpt.utils.common import (
any_to_name,
any_to_str,
@@@ -141,11 -138,13 +138,11 @@@ class Role(SerDeserMixin, is_polymorphi
desc: str = ""
is_human: bool = False
- _llm: BaseLLM = Field(default_factory=LLM) # Each role has its own LLM, use different system message
- _role_id: str = ""
- _states: list[str] = []
- _actions: list[Action] = []
- _rc: RoleContext = Field(default_factory=RoleContext)
- llm: BaseGPTAPI = Field(
- default_factory=LLM, exclude=True
- ) # Each role has its own LLM, use different system message
++ llm: BaseLLM = Field(default_factory=LLM, exclude=True) # Each role has its own LLM, use different system message
+ role_id: str = ""
+ states: list[str] = []
+ actions: list[SerializeAsAny[Action]] = Field(default=[], validate_default=True)
+ rc: RoleContext = Field(default_factory=RoleContext)
subscription: set[str] = set()
# builtin variables
diff --cc metagpt/roles/sk_agent.py
index d982ebb68,2bfe019fe..f7d229adb
--- a/metagpt/roles/sk_agent.py
+++ b/metagpt/roles/sk_agent.py
@@@ -41,17 -39,17 +41,17 @@@ class SkAgent(Role)
goal: str = "Execute task based on passed in task description"
constraints: str = ""
- plan: Any = None
+ plan: Plan = None
planner_cls: Any = None
- planner: Any = None
+ planner: Union[BasicPlanner, SequentialPlanner, ActionPlanner] = None
-
+ llm: BaseLLM = Field(default_factory=LLM)
kernel: Kernel = Field(default_factory=Kernel)
- import_semantic_skill_from_directory: Type[Kernel.import_semantic_skill_from_directory] = None
- import_skill: Type[Kernel.import_skill] = None
+ import_semantic_skill_from_directory: Callable = None
+ import_skill: Callable = None
- def __init__(self, **kwargs) -> None:
+ def __init__(self, **data: Any) -> None:
"""Initializes the Engineer role with given attributes."""
- super().__init__(**kwargs)
+ super().__init__(**data)
self._init_actions([ExecuteTask()])
self._watch([UserRequirement])
self.kernel = make_sk_kernel()
diff --cc requirements.txt
index a65e1f5b1,b75fc0fa6..81d81ba9c
--- a/requirements.txt
+++ b/requirements.txt
@@@ -9,8 -9,8 +9,8 @@@ faiss_cpu==1.7.
fire==0.4.0
typer
# godot==0.1.1
-# google_api_python_client==2.93.0
+# google_api_python_client==2.93.0 # Used by search_engine.py
- lancedb==0.1.16
+ lancedb==0.4.0
langchain==0.0.352
loguru==0.6.0
meilisearch==0.21.0
@@@ -33,21 -33,20 +33,20 @@@ tqdm==4.64.
#unstructured[local-inference]
# selenium>4
# webdriver_manager<3.9
- anthropic==0.3.6
+ anthropic==0.8.1
typing-inspect==0.8.0
- aiofiles
- typing_extensions==4.7.0
+ typing_extensions==4.9.0
libcst==1.0.1
- qdrant-client==1.4.0
+ qdrant-client==1.7.0
pytest-mock==3.11.1
-# open-interpreter==0.1.7; python_version>"3.9"
+# open-interpreter==0.1.7; python_version>"3.9" # Conflict with openai 1.x
ta==0.10.2
- semantic-kernel==0.4.0.dev0
+ semantic-kernel==0.4.3.dev0
wrapt==1.15.0
#aiohttp_jinja2
-#azure-cognitiveservices-speech~=1.31.0
-#aioboto3~=11.3.0
-#redis==4.3.5
+# azure-cognitiveservices-speech~=1.31.0 # Used by metagpt/tools/azure_tts.py
+#aioboto3~=11.3.0 # Used by metagpt/utils/s3.py
+aioredis~=2.0.1 # Used by metagpt/utils/redis.py
websocket-client==1.6.2
aiofiles==23.2.1
gitpython==3.1.40