6
@File : test_environment.py
9
from pathlib import Path
13
from metagpt.actions import UserRequirement
14
from metagpt.environment import Environment
15
from metagpt.logs import logger
16
from metagpt.roles import Architect, ProductManager, Role
17
from metagpt.schema import Message
19
serdeser_path = Path(__file__).absolute().parent.joinpath("../data/serdeser_storage")
27
def test_add_role(env: Environment):
28
role = ProductManager(
29
name="Alice", profile="product manager", goal="create a new product", constraints="limited resources"
32
assert env.get_role(str(role._setting)) == role
35
def test_get_roles(env: Environment):
36
role1 = Role(name="Alice", profile="product manager", goal="create a new product", constraints="limited resources")
37
role2 = Role(name="Bob", profile="engineer", goal="develop the new product", constraints="short deadline")
40
roles = env.get_roles()
41
assert roles == {role1.profile: role1, role2.profile: role2}
45
async def test_publish_and_process_message(env: Environment):
46
if env.context.git_repo:
47
env.context.git_repo.delete_repository()
48
env.context.git_repo = None
50
product_manager = ProductManager(name="Alice", profile="Product Manager", goal="做AI Native产品", constraints="资源有限")
51
architect = Architect(
52
name="Bob", profile="Architect", goal="设计一个可用、高效、较低成本的系统,包括数据结构与接口", constraints="资源有限,需要节省成本"
55
env.add_roles([product_manager, architect])
57
env.publish_message(Message(role="User", content="需要一个基于LLM做总结的搜索引擎", cause_by=UserRequirement))
59
logger.info(f"{env.history=}")
60
assert len(env.history) > 10
63
if __name__ == "__main__":
64
pytest.main([__file__, "-s"])