feat: archive

This commit is contained in:
莘权 马 2023-11-21 15:05:23 +08:00
parent d9a2626fde
commit 27c731d11a
4 changed files with 33 additions and 3 deletions

View file

@ -12,4 +12,14 @@ from metagpt.actions import Action
class PrepareDocuments(Action):
def __init__(self, name="", context=None, llm=None):
pass
super().__init__(name, context, llm)
async def run(self, with_message, **kwargs):
parent = self.context.get("parent")
if not parent:
raise ValueError("Invalid owner")
env = parent.get_env()
if env.git_repository:
return
env.git_repository = GitRepository()
env.git_repository.open(WORKS)

View file

@ -12,7 +12,7 @@
functionality is to be consolidated into the `Environment` class.
"""
import asyncio
from typing import Iterable, Set
from typing import Iterable, Optional, Set
from pydantic import BaseModel, Field
@ -20,6 +20,7 @@ from metagpt.logs import logger
from metagpt.roles import Role
from metagpt.schema import Message
from metagpt.utils.common import is_subscribed
from metagpt.utils.git_repository import GitRepository
class Environment(BaseModel):
@ -31,6 +32,7 @@ class Environment(BaseModel):
roles: dict[str, Role] = Field(default_factory=dict)
consumers: dict[Role, Set] = Field(default_factory=dict)
history: str = Field(default="") # For debug
git_repository: Optional[GitRepository] = None
class Config:
arbitrary_types_allowed = True
@ -111,3 +113,8 @@ class Environment(BaseModel):
def set_subscription(self, obj, tags):
"""Set the labels for message to be consumed by the object"""
self.consumers[obj] = tags
def dict(self, *args, **kwargs):
"""Generate a dictionary representation of the model, optionally specifying which fields to include or
exclude."""
return super(Environment, self).dict(exclude={"git_repository"})

View file

@ -6,6 +6,7 @@
@File : product_manager.py
"""
from metagpt.actions import BossRequirement, WritePRD
from metagpt.actions.prepare_documents import PrepareDocuments
from metagpt.roles import Role
@ -37,5 +38,13 @@ class ProductManager(Role):
constraints (str): Constraints or limitations for the product manager.
"""
super().__init__(name, profile, goal, constraints)
self._init_actions([WritePRD])
self._init_actions([PrepareDocuments(context={"parent": self}), WritePRD])
self._watch([BossRequirement])
async def _think(self) -> None:
"""Decide what to do"""
if self._rc.env.git_repository:
self._set_state(1)
else:
self._set_state(0)
return self._rc.todo

View file

@ -164,6 +164,10 @@ class Role:
if env:
env.set_subscription(self, self._subscription)
def get_env(self):
"""Return the environment in which the role works."""
return self._rc.env
@property
def profile(self):
"""Get the role description (position)"""