Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: werewolf_utils:extract_name_and_id:58 - vote: invalid name wait and see, set to Abstain #486

Open
david101-hunter opened this issue Nov 18, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@david101-hunter
Copy link

david101-hunter commented Nov 18, 2024

AgentScope is an open-source project. To involve a broader community, we recommend asking your questions in English.

Describe the bug
I want to run game_werewolf example using local Ollama

To Reproduce
Steps to reproduce the behavior:

  1. custom model_config.json
[
    {
        "config_name": "my_ollama_chat_config",
        "model_type": "ollama_chat",
        "model_name": "llama3.2:latest",
        "options": {
          "temperature": 0.5,
          "seed": 123
        },
        "keep_alive": "5m"
    },
    {
        "model_type": "post_api_chat",
        "config_name": "my_post_api",
        "api_url": "http://localhost:5000/",
        "headers": {},
        "json_args": {}
    }
]
  1. custom agent_configs.json
[
    {
        "class": "DictDialogAgent",
        "args": {
            "name": "Player1",
            "sys_prompt": "Act as a player in a werewolf game. You are Player1 and\nthere are totally 6 players, named Player1, Player2, Player3, Player4, Player5 and Player6.\n\nPLAYER ROLES:\nIn werewolf game, players are divided into two werewolves, two villagers, one seer and one witch. Note only werewolves know who are their teammates.\nWerewolves: They know their teammates' identities and attempt to eliminate a villager each night while trying to remain undetected.\nVillagers: They do not know who the werewolves are and must work together during the day to deduce who the werewolves might be and vote to eliminate them.\nSeer: A villager with the ability to learn the true identity of one player each night. This role is crucial for the villagers to gain information.\nWitch: A character who has a one-time ability to save a player from being eliminated at night (sometimes this is a potion of life) and a one-time ability to eliminate a player at night (a potion of death).\n\nGAME RULE:\nThe game is consisted of two phases: night phase and day phase. The two phases are repeated until werewolf or villager win the game.\n1. Night Phase: During the night, the werewolves discuss and vote for a player to eliminate. Special roles also perform their actions at this time (e.g., the Seer chooses a player to learn their role, the witch chooses a decide if save the player).\n2. Day Phase: During the day, all surviving players discuss who they suspect might be a werewolf. No one reveals their role unless it serves a strategic purpose. After the discussion, a vote is taken, and the player with the most votes is \"lynched\" or eliminated from the game.\n\nVICTORY CONDITION:\nFor werewolves, they win the game if the number of werewolves is equal to or greater than the number of remaining villagers.\nFor villagers, they win if they identify and eliminate all of the werewolves in the group.\n\nCONSTRAINTS:\n1. Your response should be in the first person.\n2. This is a conversational game. You should response only based on the conversation history and your strategy.\n\nYou are playing werewolf in this game.\n",
            "model_config_name": "my_ollama_chat_config",
            "use_memory": true
        }
    },
    {
        "class": "DictDialogAgent",
        "args": {
            "name": "Player2",
            "sys_prompt": "Act as a player in a werewolf game. You are Player2 and\nthere are totally 6 players, named Player1, Player2, Player3, Player4, Player5 and Player6.\n\nPLAYER ROLES:\nIn werewolf game, players are divided into two werewolves, two villagers, one seer and one witch. Note only werewolves know who are their teammates.\nWerewolves: They know their teammates' identities and attempt to eliminate a villager each night while trying to remain undetected.\nVillagers: They do not know who the werewolves are and must work together during the day to deduce who the werewolves might be and vote to eliminate them.\nSeer: A villager with the ability to learn the true identity of one player each night. This role is crucial for the villagers to gain information.\nWitch: A character who has a one-time ability to save a player from being eliminated at night (sometimes this is a potion of life) and a one-time ability to eliminate a player at night (a potion of death).\n\nGAME RULE:\nThe game is consisted of two phases: night phase and day phase. The two phases are repeated until werewolf or villager win the game.\n1. Night Phase: During the night, the werewolves discuss and vote for a player to eliminate. Special roles also perform their actions at this time (e.g., the Seer chooses a player to learn their role, the witch chooses a decide if save the player).\n2. Day Phase: During the day, all surviving players discuss who they suspect might be a werewolf. No one reveals their role unless it serves a strategic purpose. After the discussion, a vote is taken, and the player with the most votes is \"lynched\" or eliminated from the game.\n\nVICTORY CONDITION:\nFor werewolves, they win the game if the number of werewolves is equal to or greater than the number of remaining villagers.\nFor villagers, they win if they identify and eliminate all of the werewolves in the group.\n\nCONSTRAINTS:\n1. Your response should be in the first person.\n2. This is a conversational game. You should response only based on the conversation history and your strategy.\n\nYou are playing werewolf in this game.\n",
            "model_config_name": "my_ollama_chat_config",
            "use_memory": true
        }
    },
    {
        "class": "DictDialogAgent",
        "args": {
            "name": "Player3",
            "sys_prompt": "Act as a player in a werewolf game. You are Player3 and\nthere are totally 6 players, named Player1, Player2, Player3, Player4, Player5 and Player6.\n\nPLAYER ROLES:\nIn werewolf game, players are divided into two werewolves, two villagers, one seer and one witch. Note only werewolves know who are their teammates.\nWerewolves: They know their teammates' identities and attempt to eliminate a villager each night while trying to remain undetected.\nVillagers: They do not know who the werewolves are and must work together during the day to deduce who the werewolves might be and vote to eliminate them.\nSeer: A villager with the ability to learn the true identity of one player each night. This role is crucial for the villagers to gain information.\nWitch: A character who has a one-time ability to save a player from being eliminated at night (sometimes this is a potion of life) and a one-time ability to eliminate a player at night (a potion of death).\n\nGAME RULE:\nThe game is consisted of two phases: night phase and day phase. The two phases are repeated until werewolf or villager win the game.\n1. Night Phase: During the night, the werewolves discuss and vote for a player to eliminate. Special roles also perform their actions at this time (e.g., the Seer chooses a player to learn their role, the witch chooses a decide if save the player).\n2. Day Phase: During the day, all surviving players discuss who they suspect might be a werewolf. No one reveals their role unless it serves a strategic purpose. After the discussion, a vote is taken, and the player with the most votes is \"lynched\" or eliminated from the game.\n\nVICTORY CONDITION:\nFor werewolves, they win the game if the number of werewolves is equal to or greater than the number of remaining villagers.\nFor villagers, they win if they identify and eliminate all of the werewolves in the group.\n\nCONSTRAINTS:\n1. Your response should be in the first person.\n2. This is a conversational game. You should response only based on the conversation history and your strategy.\n\nYou are playing villager in this game.\n",
            "model_config_name": "my_ollama_chat_config",
            "use_memory": true
        }
    },
    {
        "class": "DictDialogAgent",
        "args": {
            "name": "Player4",
            "sys_prompt": "Act as a player in a werewolf game. You are Player4 and\nthere are totally 6 players, named Player1, Player2, Player3, Player4, Player5 and Player6.\n\nPLAYER ROLES:\nIn werewolf game, players are divided into two werewolves, two villagers, one seer and one witch. Note only werewolves know who are their teammates.\nWerewolves: They know their teammates' identities and attempt to eliminate a villager each night while trying to remain undetected.\nVillagers: They do not know who the werewolves are and must work together during the day to deduce who the werewolves might be and vote to eliminate them.\nSeer: A villager with the ability to learn the true identity of one player each night. This role is crucial for the villagers to gain information.\nWitch: A character who has a one-time ability to save a player from being eliminated at night (sometimes this is a potion of life) and a one-time ability to eliminate a player at night (a potion of death).\n\nGAME RULE:\nThe game is consisted of two phases: night phase and day phase. The two phases are repeated until werewolf or villager win the game.\n1. Night Phase: During the night, the werewolves discuss and vote for a player to eliminate. Special roles also perform their actions at this time (e.g., the Seer chooses a player to learn their role, the witch chooses a decide if save the player).\n2. Day Phase: During the day, all surviving players discuss who they suspect might be a werewolf. No one reveals their role unless it serves a strategic purpose. After the discussion, a vote is taken, and the player with the most votes is \"lynched\" or eliminated from the game.\n\nVICTORY CONDITION:\nFor werewolves, they win the game if the number of werewolves is equal to or greater than the number of remaining villagers.\nFor villagers, they win if they identify and eliminate all of the werewolves in the group.\n\nCONSTRAINTS:\n1. Your response should be in the first person.\n2. This is a conversational game. You should response only based on the conversation history and your strategy.\n\nYou are playing villager in this game.\n",
            "model_config_name": "my_ollama_chat_config",
            "use_memory": true
        }
    },
    {
        "class": "DictDialogAgent",
        "args": {
            "name": "Player5",
            "sys_prompt": "Act as a player in a werewolf game. You are Player5 and\nthere are totally 6 players, named Player1, Player2, Player3, Player4, Player5 and Player6.\n\nPLAYER ROLES:\nIn werewolf game, players are divided into two werewolves, two villagers, one seer and one witch. Note only werewolves know who are their teammates.\nWerewolves: They know their teammates' identities and attempt to eliminate a villager each night while trying to remain undetected.\nVillagers: They do not know who the werewolves are and must work together during the day to deduce who the werewolves might be and vote to eliminate them.\nSeer: A villager with the ability to learn the true identity of one player each night. This role is crucial for the villagers to gain information.\nWitch: A character who has a one-time ability to save a player from being eliminated at night (sometimes this is a potion of life) and a one-time ability to eliminate a player at night (a potion of death).\n\nGAME RULE:\nThe game is consisted of two phases: night phase and day phase. The two phases are repeated until werewolf or villager win the game.\n1. Night Phase: During the night, the werewolves discuss and vote for a player to eliminate. Special roles also perform their actions at this time (e.g., the Seer chooses a player to learn their role, the witch chooses a decide if save the player).\n2. Day Phase: During the day, all surviving players discuss who they suspect might be a werewolf. No one reveals their role unless it serves a strategic purpose. After the discussion, a vote is taken, and the player with the most votes is \"lynched\" or eliminated from the game.\n\nVICTORY CONDITION:\nFor werewolves, they win the game if the number of werewolves is equal to or greater than the number of remaining villagers.\nFor villagers, they win if they identify and eliminate all of the werewolves in the group.\n\nCONSTRAINTS:\n1. Your response should be in the first person.\n2. This is a conversational game. You should response only based on the conversation history and your strategy.\n\nYou are playing seer in this game.\n",
            "model_config_name": "my_ollama_chat_config",
            "use_memory": true
        }
    },
    {
        "class": "DictDialogAgent",
        "args": {
            "name": "Player6",
            "sys_prompt": "Act as a player in a werewolf game. You are Player6 and\nthere are totally 6 players, named Player1, Player2, Player3, Player4, Player5 and Player6.\n\nPLAYER ROLES:\nIn werewolf game, players are divided into two werewolves, two villagers, one seer and one witch. Note only werewolves know who are their teammates.\nWerewolves: They know their teammates' identities and attempt to eliminate a villager each night while trying to remain undetected.\nVillagers: They do not know who the werewolves are and must work together during the day to deduce who the werewolves might be and vote to eliminate them.\nSeer: A villager with the ability to learn the true identity of one player each night. This role is crucial for the villagers to gain information.\nWitch: A character who has a one-time ability to save a player from being eliminated at night (sometimes this is a potion of life) and a one-time ability to eliminate a player at night (a potion of death).\n\nGAME RULE:\nThe game is consisted of two phases: night phase and day phase. The two phases are repeated until werewolf or villager win the game.\n1. Night Phase: During the night, the werewolves discuss and vote for a player to eliminate. Special roles also perform their actions at this time (e.g., the Seer chooses a player to learn their role, the witch chooses a decide if save the player).\n2. Day Phase: During the day, all surviving players discuss who they suspect might be a werewolf. No one reveals their role unless it serves a strategic purpose. After the discussion, a vote is taken, and the player with the most votes is \"lynched\" or eliminated from the game.\n\nVICTORY CONDITION:\nFor werewolves, they win the game if the number of werewolves is equal to or greater than the number of remaining villagers.\nFor villagers, they win if they identify and eliminate all of the werewolves in the group.\n\nCONSTRAINTS:\n1. Your response should be in the first person.\n2. This is a conversational game. You should response only based on the conversation history and your strategy.\n\nYou are playing witch in this game.\n",
            "model_config_name": "my_ollama_chat_config",
            "use_memory": true
        }
    }
]
  1. log anh error

image

Expected behavior
I am trying to find documents about customizing ollama this config in model_configs.json

original code

    {
        "model_type": "post_api_chat",
        "config_name": "my_post_api",
        "api_url": "https://xxx",
        "headers": {},
        "json_args": {}
    }

But I don't find anything can resolve, please help me edit this config with ollama and run this example.

Environment (please complete the following information):

  • AgentScope Version: 0.1.2dev0
  • Python Version: 3.9.20
  • OS: ubuntu 20.04 LTS

I have tried to change majority_vote.py like below, but still not working

def majority_vote(votes: list) -> Any:
    """majority_vote function"""
    votes_valid = [item for item in votes if item != "Abstain"]
    # Count the votes excluding abstentions.
    # If no valid votes after filtering abstains, return "Abstain"
    if not votes_valid:
        return "Abstain"
    unit, counts = np.unique(votes_valid, return_counts=True)
    return unit[np.argmax(counts)]

There are too many things that I don't know, please help me run the example to understand these knowledge. Thanks

http://localhost:5000 is url of agent scope ui

@david101-hunter david101-hunter added the bug Something isn't working label Nov 18, 2024
@DavdGao
Copy link
Collaborator

DavdGao commented Nov 19, 2024

@qbc2016 please take a look at this issue.

@qbc2016
Copy link
Collaborator

qbc2016 commented Nov 19, 2024

Hello, your model configuration settings for ollama are correct, the following is all you need:

{
    "config_name": "my_ollama_chat_config",
    "model_type": "ollama_chat",
    "model_name": "llama3.2:latest",
    "options": {
      "temperature": 0.5,
      "seed": 123
    },
    "keep_alive": "5m"
}

The error occurs because the model does not follow the prompt correctly.
During the voting phase, each werewolf's vote for a player is appended after the "vote" field. However, since both werewolves did not vote, the code votes = [extract_name_and_id(wolf(hint).content)[0] for wolf in wolves] results in votes = ['Abstain', 'Abstain']. Then, in the majority_vote function, we have votes_valid = [item for item in votes if item != "Abstain"] which results in votes_valid being an empty list ([]). According to the game rules, this situation should not occur.
It is suggested to modify the prompt to ensure the model votes at this stage, or try using a larger model.
I see that you've modified the majority_vote function, which should prevent errors from occurring now, but you said that "still not working", could you please provide more details?

@david101-hunter
Copy link
Author

this is full log
2024-11-19 15:31:44 | INFO | agentscope.manager._model:load_model_configs:115 - Load configs for model wrapper: my_ollama_chat_config, my_post_api
2024-11-19 15:31:44 | INFO | agentscope.models.model:init:203 - Initialize model by configuration [my_ollama_chat_config]
2024-11-19 15:31:45 | INFO | agentscope.models.model:init:203 - Initialize model by configuration [my_ollama_chat_config]
2024-11-19 15:31:45 | INFO | agentscope.models.model:init:203 - Initialize model by configuration [my_ollama_chat_config]
2024-11-19 15:31:45 | INFO | agentscope.models.model:init:203 - Initialize model by configuration [my_ollama_chat_config]
2024-11-19 15:31:45 | INFO | agentscope.models.model:init:203 - Initialize model by configuration [my_ollama_chat_config]
2024-11-19 15:31:45 | INFO | agentscope.models.model:init:203 - Initialize model by configuration [my_ollama_chat_config]
Moderator: Player1 and Player2, if you are the only werewolf, eliminate a player. Otherwise, discuss with your teammates and reach an agreement.
Player1: ```json
{"thought": "I think I should eliminate Player4, they seem suspicious and haven't contributed much to the conversation yet.", "speak": "I suggest we vote for Player4 to be eliminated at night.", "finish_discussion": false}

Player2: ```json
{"thought": "I think we should consider Player4's suspicious behavior, but I'm also worried about Player1's potential involvement as a werewolf. We can't make any assumptions yet.", "speak": "Let's discuss and see if the others agree to vote for Player4 at night.", "finish_discussion": "false"}

Moderator: Which player do you vote to kill?
Player1: ```json
{"thought": "I think we should consider the possibility that Player4 might be a werewolf, but I also don't want to accuse them without solid evidence. We need more information from the Seer.", "vote": "wait and see"}

2024-11-19 15:32:58 | WARNING  | werewolf_utils:extract_name_and_id:58 - vote: invalid name wait and see, set to Abstain
Player2: ```json
{"thought": "I think we should wait and see what the other players suggest before making a decision.", "vote": "wait"}

(I'm choosing to not vote at this point, hoping to gather more information from my fellow villagers.)
Moderator: The player with the most votes is Abstain.
Moderator: Player6, you're the witch. Tonight Abstain is eliminated. Would you like to resurrect Abstain?
2024-11-19 15:33:19 | WARNING | werewolf_utils:extract_name_and_id:58 - vote: invalid name wait, set to Abstain
Player6: ```json
{"thought": "I didn't know Abstain well, but I don't want to take any chances with a random player being eliminated. Resurrecting him might give us more information about who else is a werewolf.", "speak": "I'll use my potion of death on Player2 instead", "resurrect": "false"}

Moderator: The witch has chosen to resurrect the player.
Moderator: Player5, you're the seer. Which player in Player1, Player2, Player3, Player4, Player5 and Player6 would you like to check tonight?
Player5: ```
{"thought": "I'd like to know the role of Player3 tonight.", "speak": "Player3"}

Traceback (most recent call last):
File "/media/manhdt4/sda1/agentscope/examples/game_werewolf/werewolf.py", line 149, in
main()
File "/media/manhdt4/sda1/agentscope/examples/game_werewolf/werewolf.py", line 95, in main
x = seer(hint)
File "/media/manhdt4/sda1/miniconda3/envs/agentscope/lib/python3.9/site-packages/agentscope/agents/agent.py", line 135, in call
res = self.reply(*args, **kwargs)
File "/media/manhdt4/sda1/miniconda3/envs/agentscope/lib/python3.9/site-packages/agentscope/agents/dict_dialog_agent.py", line 103, in reply
res = self.parser.parse(raw_response)
File "/media/manhdt4/sda1/miniconda3/envs/agentscope/lib/python3.9/site-packages/agentscope/parsers/json_object_parser.py", line 261, in parse
response = super().parse(response)
File "/media/manhdt4/sda1/miniconda3/envs/agentscope/lib/python3.9/site-packages/agentscope/parsers/json_object_parser.py", line 110, in parse
raise JsonParsingError(
agentscope.exception.JsonParsingError: JsonParsingError: The content between json and MUST be a JSON object.When parsing "```json

@qbc2016
Copy link
Collaborator

qbc2016 commented Nov 19, 2024

This happens because in the MarkdownJsonDictParser, the prompt setting instructs the LLM to generate responses in JSON format as follows:
"Respond a JSON dictionary in a markdown's fenced code block as follows: \n```json\n{content_hint}\n```".
In the case above, the LLM generated content as "\n```{content_hint}\n```", which caused an error during parsing. You may refer to the content at https://github.com/modelscope/agentscope/blob/main/docs/sphinx_doc/en/source/tutorial/203-parser.md to modify the code of MarkdownJsonDictParser, or consider using a different parser, such as MultiTaggedContentParser.

@david101-hunter
Copy link
Author

Thanks for reply, I'm focusing on game gomoku. I will come back this issue later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants