mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-17 15:35:21 +02:00
init st_game structure
This commit is contained in:
parent
7da710eaaf
commit
075e250f14
17 changed files with 188 additions and 0 deletions
5
examples/st_game/README.md
Normal file
5
examples/st_game/README.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
## Stanford Town Game
|
||||
|
||||
执行入口为:`python3 run_st_game.py "Host a activity"`
|
||||
|
||||
`idea`为用户给第一个Agent的用户心声,并通过这个心声进行传播,看最后多智能体是否达到举办、参加活动的目标。
|
||||
12
examples/st_game/actions/summarize_conv.py
Normal file
12
examples/st_game/actions/summarize_conv.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : summarize the content of agents' conversation
|
||||
|
||||
from metagpt.actions.action import Action
|
||||
from metagpt.schema import Message
|
||||
|
||||
|
||||
class SummarizeConv(Action):
|
||||
|
||||
def __init__(self, name="SummarizeConv", context: list[Message] = None, llm=None):
|
||||
super().__init__(name, context, llm)
|
||||
11
examples/st_game/actions/user_requirement.py
Normal file
11
examples/st_game/actions/user_requirement.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc :
|
||||
|
||||
from metagpt.actions import Action
|
||||
|
||||
|
||||
class UserRequirement(Action):
|
||||
|
||||
async def run(self, *args, **kwargs):
|
||||
raise NotImplementedError
|
||||
10
examples/st_game/maze_environment.py
Normal file
10
examples/st_game/maze_environment.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : maze environment
|
||||
|
||||
from metagpt.environment import Environment
|
||||
|
||||
|
||||
class MazeEnvironment(Environment):
|
||||
|
||||
pass
|
||||
9
examples/st_game/memory/associative_memory.py
Normal file
9
examples/st_game/memory/associative_memory.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : associative_memory to store conversation、plan detail、reflection result and so on.
|
||||
|
||||
from metagpt.memory.memory import Memory
|
||||
|
||||
|
||||
class AssociativeMemory(Memory):
|
||||
pass
|
||||
3
examples/st_game/plan/st_plan.py
Normal file
3
examples/st_game/plan/st_plan.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : st' planning execution
|
||||
3
examples/st_game/reflect/st_reflect.py
Normal file
3
examples/st_game/reflect/st_reflect.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : st's reflection execution
|
||||
44
examples/st_game/roles/st_role.py
Normal file
44
examples/st_game/roles/st_role.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : Stanford Town role
|
||||
|
||||
"""
|
||||
Do the steps following:
|
||||
- perceive, receive environment(Maze) info
|
||||
- retrieve, retrieve memories
|
||||
- plan, do plan like long-term plan and interact with Maze
|
||||
- reflect, do the High-level thinking based on memories and re-add into the memory
|
||||
- execute, move or else in the Maze
|
||||
"""
|
||||
|
||||
from pydantic import Field
|
||||
from pathlib import Path
|
||||
|
||||
from metagpt.roles.role import Role, RoleContext
|
||||
|
||||
from ..memory.associative_memory import AssociativeMemory
|
||||
|
||||
|
||||
class STRoleContext(RoleContext):
|
||||
|
||||
memory: AssociativeMemory = Field(default=AssociativeMemory)
|
||||
|
||||
|
||||
class STRole(Role):
|
||||
|
||||
# add a role's property structure to store role's age and so on like GA's Scratch.
|
||||
|
||||
def __init__(self, name="", profile=""):
|
||||
self._rc = STRoleContext()
|
||||
|
||||
def load_from(self, folder: Path):
|
||||
"""
|
||||
load role data from `storage/{simulation_name}/personas/{role_name}
|
||||
"""
|
||||
pass
|
||||
|
||||
def save_into(self, folder: Path):
|
||||
"""
|
||||
save role data from `storage/{simulation_name}/personas/{role_name}
|
||||
"""
|
||||
pass
|
||||
42
examples/st_game/run_st_game.py
Normal file
42
examples/st_game/run_st_game.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : entry of Stanford Town(ST/st) game
|
||||
|
||||
import asyncio
|
||||
import fire
|
||||
|
||||
from stanford_town import StanfordTown
|
||||
from roles.st_role import STRole
|
||||
|
||||
|
||||
async def startup(idea: str,
|
||||
investment: float = 30.0,
|
||||
n_round: int = 500):
|
||||
|
||||
# get role names from `storage/{simulation_name}/reverie/meta.json` and then init roles
|
||||
roles = []
|
||||
# TODO
|
||||
|
||||
town = StanfordTown()
|
||||
town.wakeup_roles(roles)
|
||||
|
||||
town.invest(investment)
|
||||
town.start_project()
|
||||
|
||||
await town.run(n_round)
|
||||
|
||||
|
||||
def main(idea: str,
|
||||
investment: float = 30.0,
|
||||
n_round: int = 500):
|
||||
"""
|
||||
idea works as an `inner voice` to the first agent.
|
||||
"""
|
||||
|
||||
asyncio.run(startup(idea=idea,
|
||||
investment=investment,
|
||||
n_round=n_round))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
fire.Fire(main)
|
||||
25
examples/st_game/stanford_town.py
Normal file
25
examples/st_game/stanford_town.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : StanfordTown to works like SoftwareCompany
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from metagpt.software_company import SoftwareCompany
|
||||
from metagpt.roles.role import Role
|
||||
from metagpt.schema import Message
|
||||
|
||||
from maze_environment import MazeEnvironment
|
||||
from actions.user_requirement import UserRequirement
|
||||
|
||||
|
||||
class StanfordTown(SoftwareCompany):
|
||||
|
||||
environment: MazeEnvironment = Field(default_factory=MazeEnvironment)
|
||||
|
||||
def wakeup_roles(self, roles: list[Role]):
|
||||
self.environment.add_roles(roles)
|
||||
|
||||
def start_project(self, idea):
|
||||
self.environment.publish_message(
|
||||
Message(role="User", content=idea, cause_by=UserRequirement)
|
||||
)
|
||||
1
examples/st_game/storage/.gitignore
vendored
Normal file
1
examples/st_game/storage/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
# path to store simulation data
|
||||
8
examples/st_game/utils/const.py
Normal file
8
examples/st_game/utils/const.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc :
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
ROOT_PATH = Path(__file__).parent.parent
|
||||
STORAGE_PATH = ROOT_PATH.joinpath("storage")
|
||||
3
examples/st_game/utils/mg_ga_transform.py
Normal file
3
examples/st_game/utils/mg_ga_transform.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : data transform of mg <-> ga under storage
|
||||
3
metagpt/plan/__init__.py
Normal file
3
metagpt/plan/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : plan module
|
||||
3
metagpt/plan/plan.py
Normal file
3
metagpt/plan/plan.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : base class of planning
|
||||
3
metagpt/reflect/__init__.py
Normal file
3
metagpt/reflect/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : reflection module
|
||||
3
metagpt/reflect/reflect.py
Normal file
3
metagpt/reflect/reflect.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : base class of reflection
|
||||
Loading…
Add table
Add a link
Reference in a new issue