Skip to content

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

add guard

kevin-meng02cc5c274d3d
diff --git a/examples/werewolf_game/actions/guard_actions.py b/examples/werewolf_game/actions/guard_actions.py
index 419bd0330..98dfc3b32 100644
--- a/examples/werewolf_game/actions/guard_actions.py
+++ b/examples/werewolf_game/actions/guard_actions.py
@@ -5,9 +5,10 @@ class Protect(Action):
PROMPT_TEMPLATE = """
It's a werewolf game and you are a guard,
+ you can choose to protect a player, including yourself, then the protected player will not be killed by the Werewolves this night.
this is game history:
{context}.
- Attention: you can not protect the same player in a row.
+ Attention: you can not protect the same player two nights in a row.
Now, choose one to portect, you will:
"""
@@ -21,4 +22,4 @@ class Protect(Action):
rsp = await self._aask(prompt)
# rsp = "Protect Player 1"
- return rsp
+ return rsp
\ No newline at end of file
diff --git a/examples/werewolf_game/roles/guard.py b/examples/werewolf_game/roles/guard.py
index 5a3bc55ff..94b5b46dc 100644
--- a/examples/werewolf_game/roles/guard.py
+++ b/examples/werewolf_game/roles/guard.py
@@ -1,21 +1,21 @@
from examples.werewolf_game.roles.base_player import BasePlayer
-from examples.werewolf_game.actions import Speak, Hunt
+from examples.werewolf_game.actions import Speak, Protect
from metagpt.schema import Message
from metagpt.logs import logger
-class Werewolf(BasePlayer):
+class Guard(BasePlayer):
def __init__(
self,
name: str = "",
- profile: str = "Werewolf",
- team: str = "werewolves",
- special_action_names: list[str] = ["Hunt"],
+ profile: str = "Guard",
+ team: str = "good guys",
+ special_action_names: list[str] = ["Protect"],
**kwargs,
):
super().__init__(name, profile, team, special_action_names, **kwargs)
async def _act(self):
- # todo为_think时确定的,有两种情况,Speak或Hunt
+ # todo为_think时确定的,有两种情况,Speak或Protect
todo = self._rc.todo
logger.info(f"{self._setting}: ready to {str(todo)}")
@@ -31,14 +31,16 @@ class Werewolf(BasePlayer):
cause_by=Speak, send_to="", restricted_to="",
)
- elif isinstance(todo, Hunt):
+ elif isinstance(todo, Protect):
rsp = await todo.run(context=memories)
msg = Message(
content=rsp, role=self.profile, sent_from=self.name,
- cause_by=Hunt, send_to="",
- restricted_to=f"Moderator,{self.profile}", # 给Moderator及狼阵营发送要杀的人的加密消息
+ cause_by=Protect, send_to="",
+ restricted_to=f"Moderator,{self.profile}", # 给Moderator发送守卫要保护的人加密消息
)
logger.info(f"{self._setting}: {rsp}")
return msg
+
+