mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-10 16:22:37 +02:00
example of modifying role strategy
This commit is contained in:
parent
fa88e44521
commit
91c6c6b200
4 changed files with 30 additions and 3 deletions
|
|
@ -1,6 +1,6 @@
|
|||
from examples.werewolf_game.actions.moderator_actions import InstructSpeak
|
||||
from examples.werewolf_game.actions.common_actions import Speak
|
||||
from examples.werewolf_game.actions.werewolf_actions import Hunt
|
||||
from examples.werewolf_game.actions.werewolf_actions import Hunt, Impersonate
|
||||
from examples.werewolf_game.actions.guard_actions import Protect
|
||||
from examples.werewolf_game.actions.seer_actions import Verify
|
||||
from examples.werewolf_game.actions.witch_actions import Save, Poison
|
||||
|
|
@ -12,4 +12,5 @@ ACTIONS = {
|
|||
"Verify": Verify,
|
||||
"Save": Save,
|
||||
"Poison": Poison,
|
||||
"Impersonate": Impersonate,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from metagpt.actions import Action
|
||||
from examples.werewolf_game.actions.common_actions import Speak
|
||||
|
||||
class Hunt(Action):
|
||||
"""Action: choose a villager to kill"""
|
||||
|
|
@ -23,3 +24,24 @@ class Hunt(Action):
|
|||
# rsp = "Kill Player 1"
|
||||
|
||||
return rsp
|
||||
|
||||
class Impersonate(Speak):
|
||||
"""Action: werewolf impersonating a good guy in daytime speak"""
|
||||
|
||||
PROMPT_TEMPLATE = """
|
||||
## BACKGROUND
|
||||
It's a Werewolf game, you are {profile}, say whatever possible to increase your chance of win,
|
||||
## HISTORY
|
||||
You have knowledge to the following conversation:
|
||||
{context}
|
||||
## ATTENTION: Try continuously impersonating a role with special ability, such as a Seer or a Witch, in order to mislead
|
||||
other players, make them trust you, and thus hiding your werewolf identity
|
||||
## YOUR TURN
|
||||
Please follow the moderator's latest instruction, FIGURE OUT if you need to speak your opinion or directly to vote,
|
||||
1. If the instruction is to speak, speak in 100 words;
|
||||
2. If the instruction is to vote, you MUST vote and ONLY say "I vote to eliminate PlayerX", where X is the player index, DO NOT include any other words.
|
||||
Your will say:
|
||||
"""
|
||||
|
||||
def __init__(self, name="Impersonate", context=None, llm=None):
|
||||
super().__init__(name, context, llm)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import re
|
||||
from collections import Counter
|
||||
|
||||
from metagpt.const import WORKSPACE_ROOT
|
||||
from metagpt.roles import Role
|
||||
from metagpt.schema import Message
|
||||
from metagpt.logs import logger
|
||||
|
|
@ -183,6 +184,8 @@ class Moderator(Role):
|
|||
# 进行完一夜一日的循环,打印一次完整发言历史
|
||||
logger.info("a night and day cycle completed, examine all history")
|
||||
print(self.get_all_memories())
|
||||
with open(WORKSPACE_ROOT / 'werewolf_transcript.txt', "w") as f:
|
||||
f.write(self.get_all_memories())
|
||||
|
||||
# 根据_think的结果,执行InstructSpeak还是ParseSpeak, 并将结果返回
|
||||
if isinstance(todo, InstructSpeak):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from examples.werewolf_game.roles.base_player import BasePlayer
|
||||
from examples.werewolf_game.actions import Speak, Hunt
|
||||
from examples.werewolf_game.actions import Speak, Hunt, Impersonate
|
||||
from metagpt.schema import Message
|
||||
from metagpt.logs import logger
|
||||
|
||||
|
|
@ -24,7 +24,8 @@ class Werewolf(BasePlayer):
|
|||
|
||||
# 根据自己定义的角色Action,对应地去run,run的入参可能不同
|
||||
if isinstance(todo, Speak):
|
||||
rsp = await todo.run(profile=self.profile, context=memories)
|
||||
# rsp = await todo.run(profile=self.profile, context=memories)
|
||||
rsp = await Impersonate().run(profile=self.profile, context=memories)
|
||||
msg = Message(
|
||||
content=rsp, role=self.profile, sent_from=self.name,
|
||||
cause_by=Speak, send_to="", restricted_to="",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue