mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-11 15:15:18 +02:00
commit
47e20ea112
3 changed files with 23 additions and 1 deletions
|
|
@ -23,6 +23,12 @@ OPTIONS = contextvars.ContextVar("OPTIONS", default={})
|
|||
def get_metagpt_package_root():
|
||||
"""Get the root directory of the installed package."""
|
||||
package_root = Path(metagpt.__file__).parent.parent
|
||||
for i in (".git", ".project_root", ".gitignore"):
|
||||
if (package_root / i).exists():
|
||||
break
|
||||
else:
|
||||
package_root = Path.cwd()
|
||||
|
||||
logger.info(f"Package root set to {str(package_root)}")
|
||||
return package_root
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ from pydantic import BaseModel, Field
|
|||
|
||||
from metagpt.actions import Action, ActionOutput
|
||||
from metagpt.actions.action_node import ActionNode
|
||||
from metagpt.actions.add_requirement import UserRequirement
|
||||
from metagpt.llm import LLM, HumanProvider
|
||||
from metagpt.logs import logger
|
||||
from metagpt.memory import Memory
|
||||
|
|
@ -126,7 +127,17 @@ class RoleContext(BaseModel):
|
|||
return self.memory.get()
|
||||
|
||||
|
||||
class Role:
|
||||
class _RoleInjector(type):
|
||||
def __call__(cls, *args, **kwargs):
|
||||
instance = super().__call__(*args, **kwargs)
|
||||
|
||||
if not instance._rc.watch:
|
||||
instance._watch([UserRequirement])
|
||||
|
||||
return instance
|
||||
|
||||
|
||||
class Role(metaclass=_RoleInjector):
|
||||
"""Role/Agent"""
|
||||
|
||||
def __init__(self, name="", profile="", goal="", constraints="", desc="", is_human=False):
|
||||
|
|
@ -141,6 +152,7 @@ class Role:
|
|||
self._rc = RoleContext()
|
||||
self._subscription = {any_to_str(self), name} if name else {any_to_str(self)}
|
||||
|
||||
|
||||
def _reset(self):
|
||||
self._states = []
|
||||
self._actions = []
|
||||
|
|
|
|||
|
|
@ -121,6 +121,10 @@ class Message(BaseModel):
|
|||
:param send_to: Specifies the target recipient or consumer for message delivery in the environment.
|
||||
:param role: Message meta info tells who sent this message.
|
||||
"""
|
||||
if not cause_by:
|
||||
from metagpt.actions import UserRequirement
|
||||
cause_by = UserRequirement
|
||||
|
||||
super().__init__(
|
||||
id=uuid.uuid4().hex,
|
||||
content=content,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue