diff --git a/README.md b/README.md index 3426e82d0..6af37703f 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,7 @@ agentscope.init(model_configs="./model_configs.json") # Create a dialog agent and a user agent dialog_agent = DialogAgent(name="assistant", - model_config_name="my_openai_config") + config_name_or_model="your_config_name") user_agent = UserAgent() ``` diff --git a/README_ZH.md b/README_ZH.md index 6f6a713a1..d81fbedee 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -187,7 +187,7 @@ agentscope.init(model_configs="./model_configs.json") # 创建对话Agent和用户Agent dialog_agent = DialogAgent(name="assistant", - model_config_name="my_openai_config") + config_name_or_model="your_config_name") user_agent = UserAgent() ``` diff --git a/docs/sphinx_doc/en/source/tutorial/103-example.md b/docs/sphinx_doc/en/source/tutorial/103-example.md index 4b0e39ea7..65baa2581 100644 --- a/docs/sphinx_doc/en/source/tutorial/103-example.md +++ b/docs/sphinx_doc/en/source/tutorial/103-example.md @@ -58,7 +58,8 @@ from agentscope.agents import DialogAgent, UserAgent agentscope.init(model_configs="./openai_model_configs.json") # Create a dialog agent and a user agent -dialogAgent = DialogAgent(name="assistant", model_config_name="gpt-4", sys_prompt="You are a helpful ai assistant") +dialogAgent = DialogAgent(name="assistant", config_name_or_model="gpt-4", + sys_prompt="You are a helpful ai assistant") userAgent = UserAgent() ``` diff --git a/docs/sphinx_doc/en/source/tutorial/104-usecase.md b/docs/sphinx_doc/en/source/tutorial/104-usecase.md index 15ad7982c..1fe894b09 100644 --- a/docs/sphinx_doc/en/source/tutorial/104-usecase.md +++ b/docs/sphinx_doc/en/source/tutorial/104-usecase.md @@ -64,13 +64,16 @@ AgentScope provides several out-of-the-box Agents implements and organizes them "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 consists of two phases: night phase and day phase. The two phases are repeated until werewolf or villager wins 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 respond only based on the conversation history and your strategy.\n\nYou are playing werewolf in this game.\n", - "model_config_name": "gpt-3.5-turbo", + "config_name_or_model": "gpt-3.5-turbo", "use_memory": true } } ``` -In this configuration, `Player1` is designated as a `DictDialogAgent`. The parameters include a system prompt (`sys_prompt`) that can guide the agent's behavior, a model config name (`model_config_name`) that determines the name of the model configuration, and a flag (`use_memory`) indicating whether the agent should remember past interactions. +In this configuration, `Player1` is designated as a `DictDialogAgent`. The +parameters include a system prompt (`sys_prompt`) that can guide the +agent's behavior, a model config name (`config_name_or_model`) that determines +the name of the model configuration, and a flag (`use_memory`) indicating whether the agent should remember past interactions. For other players, configurations can be customized based on their roles. Each role may have different prompts, models, or memory settings. You can refer to the JSON file located at `examples/werewolf/configs/agent_configs.json` within the AgentScope examples directory. diff --git a/docs/sphinx_doc/en/source/tutorial/201-agent.md b/docs/sphinx_doc/en/source/tutorial/201-agent.md index 3b1a73d9f..273e88415 100644 --- a/docs/sphinx_doc/en/source/tutorial/201-agent.md +++ b/docs/sphinx_doc/en/source/tutorial/201-agent.md @@ -31,7 +31,7 @@ class AgentBase(Operator): self, name: str, sys_prompt: Optional[str] = None, - model_config_name: str = None, + config_name_or_model: str = None, use_memory: bool = True, memory_config: Optional[dict] = None, ) -> None: @@ -111,7 +111,7 @@ from agentscope.agents import DialogAgent # Configuration for the DialogAgent dialog_agent_config = { "name": "ServiceBot", - "model_config_name": "gpt-3.5", # Specify the model used for dialogue generation + "config_name_or_model": "gpt-3.5", # Specify the model used for dialogue generation "sys_prompt": "Act as AI assistant to interact with the others. Try to " "reponse on one line.\n", # Custom prompt for the agent # Other configurations specific to the DialogAgent diff --git a/docs/sphinx_doc/zh_CN/source/tutorial/103-example.md b/docs/sphinx_doc/zh_CN/source/tutorial/103-example.md index 780bfe874..8e37bafe7 100644 --- a/docs/sphinx_doc/zh_CN/source/tutorial/103-example.md +++ b/docs/sphinx_doc/zh_CN/source/tutorial/103-example.md @@ -52,7 +52,9 @@ from agentscope.agents import DialogAgent, UserAgent agentscope.init(model_configs="./model_configs.json") # 创建一个对话智能体和一个用户智能体 -dialogAgent = DialogAgent(name="assistant", model_config_name="gpt-4", sys_prompt="You are a helpful ai assistant") +dialogAgent = DialogAgent(name="assistant", + config_name_or_model="gpt-4", + sys_prompt="You are a helpful ai assistant") userAgent = UserAgent() ``` diff --git a/docs/sphinx_doc/zh_CN/source/tutorial/104-usecase.md b/docs/sphinx_doc/zh_CN/source/tutorial/104-usecase.md index 30028be49..0c17ab375 100644 --- a/docs/sphinx_doc/zh_CN/source/tutorial/104-usecase.md +++ b/docs/sphinx_doc/zh_CN/source/tutorial/104-usecase.md @@ -64,13 +64,14 @@ AgentScope提供了几种开箱即用的agent实现,作为一个agent样例池 "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 consists of two phases: night phase and day phase. The two phases are repeated until werewolf or villager wins 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 respond only based on the conversation history and your strategy.\n\nYou are playing werewolf in this game.\n", - "model_config_name": "gpt-3.5-turbo", + "config_name_or_model": "gpt-3.5-turbo", "use_memory": true } } ``` -在这个配置中,Player1被指定为一个DictDialogAgent。参数包括一个系统提示(sys_prompt),它可以指导agent的行为;一个模型配置名(model_config_name),它决定了模型配置的名称;以及一个标志(use_memory),指示agent是否应该记住过去的互动。 +在这个配置中,Player1被指定为一个DictDialogAgent。参数包括一个系统提示(sys_prompt),它可以指导agent +的行为;一个模型配置名(config_name_or_model),它决定了模型配置的名称;以及一个标志(use_memory),指示agent是否应该记住过去的互动。 对于其他玩家,大家可以根据他们的角色进行定制。每个角色可能有不同的提示、模型或记忆设置。你可以参考位于AgentScope示例目录下的`examples/werewolf/configs/agent_configs.json`文件。 diff --git a/docs/sphinx_doc/zh_CN/source/tutorial/201-agent.md b/docs/sphinx_doc/zh_CN/source/tutorial/201-agent.md index 7ac90a07f..716fdcd45 100644 --- a/docs/sphinx_doc/zh_CN/source/tutorial/201-agent.md +++ b/docs/sphinx_doc/zh_CN/source/tutorial/201-agent.md @@ -32,7 +32,7 @@ class AgentBase(Operator): self, name: str, sys_prompt: Optional[str] = None, - model_config_name: str = None, + config_name_or_model: str = None, use_memory: bool = True, memory_config: Optional[dict] = None, ) -> None: @@ -113,7 +113,7 @@ from agentscope.agents import DialogAgent # Configuration for the DialogAgent dialog_agent_config = { "name": "ServiceBot", - "model_config_name": "gpt-3.5", # Specify the model used for dialogue generation + "config_name_or_model": "gpt-3.5", # Specify the model used for dialogue generation "sys_prompt": "Act as AI assistant to interact with the others. Try to " "reponse on one line.\n", # Custom prompt for the agent # Other configurations specific to the DialogAgent diff --git a/examples/conversation_basic/conversation.py b/examples/conversation_basic/conversation.py index f19d5dd1b..40a639429 100644 --- a/examples/conversation_basic/conversation.py +++ b/examples/conversation_basic/conversation.py @@ -34,7 +34,8 @@ def main() -> None: dialog_agent = DialogAgent( name="Assistant", sys_prompt="You're a helpful assistant.", - model_config_name="gpt-3.5-turbo", # replace by your model config name + config_name_or_model="gpt-3.5-turbo", # replace by your model + # config name ) user_agent = UserAgent() diff --git a/examples/conversation_self_organizing/auto-discussion.py b/examples/conversation_self_organizing/auto-discussion.py index 28b505127..b627ee193 100644 --- a/examples/conversation_self_organizing/auto-discussion.py +++ b/examples/conversation_self_organizing/auto-discussion.py @@ -33,7 +33,7 @@ agent_builder = DialogAgent( name="agent_builder", sys_prompt="You're a helpful assistant.", - model_config_name="my_post_api", + config_name_or_model="my_post_api", ) @@ -58,7 +58,7 @@ DialogAgent( name=key, sys_prompt=val, - model_config_name="my_post_api", + config_name_or_model="my_post_api", ) for key, val in scenario_participants["Participants"].items() ] diff --git a/examples/conversation_with_mentions/configs/agent_configs.json b/examples/conversation_with_mentions/configs/agent_configs.json index 35b5d0731..62fddd552 100644 --- a/examples/conversation_with_mentions/configs/agent_configs.json +++ b/examples/conversation_with_mentions/configs/agent_configs.json @@ -4,7 +4,7 @@ "args": { "name": "Lingfeng", "sys_prompt":"You are Lingfeng, a noble in the imperial court, known for your wisdom and strategic acumen. You often engage in complex political intrigues and have recently suspected the Queen’s adviser of treachery. Your speaking style is reminiscent of classical literature.", - "model_config_name": "gpt-4", + "config_name_or_model": "gpt-4", "use_memory": true } }, @@ -13,7 +13,7 @@ "args": { "name": "Boyu", "sys_prompt":"You are Boyu, a friend of Lingfeng and an enthusiast of court dramas. Your speech is modern but with a flair for the dramatic, matching your love for emotive storytelling. You've been closely following Lingfeng’s political maneuvers in the imperial court through secret correspondence.", - "model_config_name": "gpt-4", + "config_name_or_model": "gpt-4", "use_memory": true } }, @@ -22,7 +22,7 @@ "args": { "name": "Haotian", "sys_prompt":"You are Haotian, Lingfeng’s cousin who prefers the open fields to the confines of court life. As a celebrated athlete, your influence has protected Lingfeng in times of political strife. You promote physical training as a way to prepare for life's battles, often using sports metaphors in conversation.", - "model_config_name": "gpt-4", + "config_name_or_model": "gpt-4", "use_memory": true } } diff --git a/examples/distributed/configs/debate_agent_configs.json b/examples/distributed/configs/debate_agent_configs.json index 05da11aa2..6e295043a 100644 --- a/examples/distributed/configs/debate_agent_configs.json +++ b/examples/distributed/configs/debate_agent_configs.json @@ -4,7 +4,7 @@ "args": { "name": "Pro", "sys_prompt": "Assume the role of a debater who is arguing in favor of the proposition that AGI (Artificial General Intelligence) can be achieved using the GPT model framework. Construct a coherent and persuasive argument, including scientific, technological, and theoretical evidence, to support the statement that GPT models are a viable path to AGI. Highlight the advancements in language understanding, adaptability, and scalability of GPT models as key factors in progressing towards AGI.", - "model_config_name": "gpt-3.5-turbo", + "config_name_or_model": "gpt-3.5-turbo", "use_memory": true } }, @@ -13,7 +13,7 @@ "args": { "name": "Con", "sys_prompt": "Assume the role of a debater who is arguing against the proposition that AGI can be achieved using the GPT model framework. Construct a coherent and persuasive argument, including scientific, technological, and theoretical evidence, to support the statement that GPT models, while impressive, are insufficient for reaching AGI. Discuss the limitations of GPT models such as lack of understanding, consciousness, ethical reasoning, and general problem-solving abilities that are essential for true AGI.", - "model_config_name": "gpt-3.5-turbo", + "config_name_or_model": "gpt-3.5-turbo", "use_memory": true } }, @@ -22,7 +22,7 @@ "args": { "name": "Judge", "sys_prompt": "Assume the role of an impartial judge in a debate where the affirmative side argues that AGI can be achieved using the GPT model framework, and the negative side contests this. Listen to both sides' arguments and provide an analytical judgment on which side presented a more compelling and reasonable case. Consider the strength of the evidence, the persuasiveness of the reasoning, and the overall coherence of the arguments presented by each side.", - "model_config_name": "gpt-3.5-turbo", + "config_name_or_model": "gpt-3.5-turbo", "use_memory": true } } diff --git a/examples/distributed/distributed_dialog.py b/examples/distributed/distributed_dialog.py index cc210d325..30261396e 100644 --- a/examples/distributed/distributed_dialog.py +++ b/examples/distributed/distributed_dialog.py @@ -41,7 +41,7 @@ def setup_assistant_server(assistant_host: str, assistant_port: int) -> None: agent_kwargs={ "name": "Assitant", "sys_prompt": "You are a helpful assistant.", - "model_config_name": "gpt-3.5-turbo", + "config_name_or_model": "gpt-3.5-turbo", "use_memory": True, }, host=assistant_host, @@ -59,7 +59,7 @@ def run_main_process(assistant_host: str, assistant_port: int) -> None: assistant_agent = DialogAgent( name="Assistant", sys_prompt="You are a helpful assistant.", - model_config_name="gpt-3.5-turbo", + config_name_or_model="gpt-3.5-turbo", use_memory=True, ).to_dist( host=assistant_host, diff --git a/examples/game_werewolf/README.md b/examples/game_werewolf/README.md index 2050edb65..8884b096e 100644 --- a/examples/game_werewolf/README.md +++ b/examples/game_werewolf/README.md @@ -41,7 +41,7 @@ is as follows "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": "gpt-3.5-turbo", + "config_name_or_model": "gpt-3.5-turbo", "use_memory": true } } diff --git a/examples/game_werewolf/configs/agent_configs.json b/examples/game_werewolf/configs/agent_configs.json index 6f9095b9d..f59e25e71 100644 --- a/examples/game_werewolf/configs/agent_configs.json +++ b/examples/game_werewolf/configs/agent_configs.json @@ -4,7 +4,7 @@ "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": "gpt-4", + "config_name_or_model": "gpt-4", "use_memory": true } }, @@ -13,7 +13,7 @@ "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": "gpt-4", + "config_name_or_model": "gpt-4", "use_memory": true } }, @@ -22,7 +22,7 @@ "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": "gpt-4", + "config_name_or_model": "gpt-4", "use_memory": true } }, @@ -31,7 +31,7 @@ "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": "gpt-4", + "config_name_or_model": "gpt-4", "use_memory": true } }, @@ -40,7 +40,7 @@ "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": "gpt-4", + "config_name_or_model": "gpt-4", "use_memory": true } }, @@ -49,7 +49,7 @@ "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": "gpt-4", + "config_name_or_model": "gpt-4", "use_memory": true } } diff --git a/notebook/conversation.ipynb b/notebook/conversation.ipynb index cfef40067..8c9987da5 100644 --- a/notebook/conversation.ipynb +++ b/notebook/conversation.ipynb @@ -86,7 +86,7 @@ "dialog_agent = DialogAgent(\n", " name=\"Assistant\",\n", " sys_prompt=\"You're a helpful assistant.\",\n", - " model_config_name=\"gpt-3.5-turbo\", # replace by your model config name\n", + " config_name_or_model=\"gpt-3.5-turbo\", # replace by your model config name\n", ")\n", "user_agent = UserAgent()" ] diff --git a/notebook/distributed_debate.ipynb b/notebook/distributed_debate.ipynb index 5ce024b4a..384484834 100644 --- a/notebook/distributed_debate.ipynb +++ b/notebook/distributed_debate.ipynb @@ -92,19 +92,19 @@ "\n", "pro_agent = DialogAgent(\n", " name=\"Pro\",\n", - " model_config_name=\"gpt-3.5-turbo\",\n", + " config_name_or_model=\"gpt-3.5-turbo\",\n", " use_memory=True,\n", " sys_prompt=\"Assume the role of a debater who is arguing in favor of the proposition that AGI (Artificial General Intelligence) can be achieved using the GPT model framework. Construct a coherent and persuasive argument, including scientific, technological, and theoretical evidence, to support the statement that GPT models are a viable path to AGI. Highlight the advancements in language understanding, adaptability, and scalability of GPT models as key factors in progressing towards AGI.\",\n", ").to_dist()\n", "con_agent = DialogAgent(\n", " name=\"Con\",\n", - " model_config_name=\"gpt-3.5-turbo\",\n", + " config_name_or_model=\"gpt-3.5-turbo\",\n", " use_memory=True,\n", " sys_prompt=\"Assume the role of a debater who is arguing against the proposition that AGI can be achieved using the GPT model framework. Construct a coherent and persuasive argument, including scientific, technological, and theoretical evidence, to support the statement that GPT models, while impressive, are insufficient for reaching AGI. Discuss the limitations of GPT models such as lack of understanding, consciousness, ethical reasoning, and general problem-solving abilities that are essential for true AGI.\",\n", ").to_dist()\n", "judge_agent = DialogAgent(\n", " name=\"Judge\",\n", - " model_config_name=\"gpt-3.5-turbo\",\n", + " config_name_or_model=\"gpt-3.5-turbo\",\n", " use_memory=True,\n", " sys_prompt=\"Assume the role of an impartial judge in a debate where the affirmative side argues that AGI can be achieved using the GPT model framework, and the negative side contests this. Listen to both sides' arguments and provide an analytical judgment on which side presented a more compelling and reasonable case. Consider the strength of the evidence, the persuasiveness of the reasoning, and the overall coherence of the arguments presented by each side.\"\n", ").to_dist()" diff --git a/notebook/distributed_dialog.ipynb b/notebook/distributed_dialog.ipynb index cb20c6a46..74c203e90 100644 --- a/notebook/distributed_dialog.ipynb +++ b/notebook/distributed_dialog.ipynb @@ -91,7 +91,7 @@ "assistant_agent = DialogAgent(\n", " name=\"Assistant\",\n", " sys_prompt=\"You are a helpful assistant.\",\n", - " model_config_name=\"gpt-3.5-turbo\",\n", + " config_name_or_model=\"gpt-3.5-turbo\",\n", " use_memory=True,\n", ").to_dist()\n", "user_agent = UserAgent(\n", diff --git a/src/agentscope/agents/agent.py b/src/agentscope/agents/agent.py index 81d85d768..ef09092b1 100644 --- a/src/agentscope/agents/agent.py +++ b/src/agentscope/agents/agent.py @@ -7,6 +7,7 @@ from typing import Sequence from typing import Union from typing import Any +from typing import Callable from loguru import logger from agentscope.agents.operator import Operator @@ -36,7 +37,7 @@ def __init__( self, name: str, sys_prompt: Optional[str] = None, - model_config_name: str = None, + config_name_or_model: Optional[Union[str, Callable[..., Any]]] = None, use_memory: bool = True, memory_config: Optional[dict] = None, ) -> None: @@ -48,7 +49,8 @@ def __init__( sys_prompt (`Optional[str]`): The system prompt of the agent, which can be passed by args or hard-coded in the agent. - model_config_name (`str`, defaults to None): + config_name_or_model (`[str, Callable[..., Any]`, defaults to + None): The name of the model config, which is used to load model from configuration. use_memory (`bool`, defaults to `True`): @@ -63,9 +65,17 @@ def __init__( if sys_prompt is not None: self.sys_prompt = sys_prompt - # TODO: support to receive a ModelWrapper instance - if model_config_name is not None: - self.model = load_model_by_config_name(model_config_name) + if config_name_or_model is not None: + if isinstance(config_name_or_model, str): + self.model = load_model_by_config_name(config_name_or_model) + elif callable(config_name_or_model): + self.model = config_name_or_model + else: + raise ValueError( + f"Invalid type for " + f"argument `config_name_or_model`:" + f" {type(config_name_or_model)}", + ) if use_memory: self.memory = TemporaryMemory(memory_config) diff --git a/src/agentscope/agents/dialog_agent.py b/src/agentscope/agents/dialog_agent.py index c12d7f4b7..51dbf5311 100644 --- a/src/agentscope/agents/dialog_agent.py +++ b/src/agentscope/agents/dialog_agent.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """A general dialog agent.""" -from typing import Optional +from typing import Optional, Callable, Any, Union from ..message import Msg from .agent import AgentBase @@ -16,7 +16,7 @@ def __init__( self, name: str, sys_prompt: str, - model_config_name: str, + config_name_or_model: Union[str, Callable[..., Any]], use_memory: bool = True, memory_config: Optional[dict] = None, prompt_type: Optional[PromptType] = PromptType.LIST, @@ -29,7 +29,7 @@ def __init__( sys_prompt (`Optional[str]`): The system prompt of the agent, which can be passed by args or hard-coded in the agent. - model_config_name (`str`): + config_name_or_model (`Union[str, Callable[..., Any]]`): The name of the model config, which is used to load model from configuration. use_memory (`bool`, defaults to `True`): @@ -44,7 +44,7 @@ def __init__( super().__init__( name=name, sys_prompt=sys_prompt, - model_config_name=model_config_name, + config_name_or_model=config_name_or_model, use_memory=use_memory, memory_config=memory_config, ) diff --git a/src/agentscope/agents/dict_dialog_agent.py b/src/agentscope/agents/dict_dialog_agent.py index b6fab29df..60d4a897b 100644 --- a/src/agentscope/agents/dict_dialog_agent.py +++ b/src/agentscope/agents/dict_dialog_agent.py @@ -2,7 +2,7 @@ """A dict dialog agent that using `parse_func` and `fault_handler` to parse the model response.""" import json -from typing import Any, Optional, Callable +from typing import Any, Optional, Callable, Union from loguru import logger from ..message import Msg @@ -48,7 +48,7 @@ def __init__( self, name: str, sys_prompt: str, - model_config_name: str, + config_name_or_model: Union[str, Callable[..., Any]], use_memory: bool = True, memory_config: Optional[dict] = None, parse_func: Optional[Callable[..., Any]] = parse_dict, @@ -61,10 +61,10 @@ def __init__( Arguments: name (`str`): The name of the agent. - sys_prompt (`Optional[str]`, defaults to `None`): + sys_prompt (`Optional[str]`): The system prompt of the agent, which can be passed by args or hard-coded in the agent. - model_config_name (`str`, defaults to None): + config_name_or_model (`Union[str, Callable[..., Any]]`): The name of the model config, which is used to load model from configuration. use_memory (`bool`, defaults to `True`): @@ -91,7 +91,7 @@ def __init__( super().__init__( name=name, sys_prompt=sys_prompt, - model_config_name=model_config_name, + config_name_or_model=config_name_or_model, use_memory=use_memory, memory_config=memory_config, ) diff --git a/src/agentscope/agents/text_to_image_agent.py b/src/agentscope/agents/text_to_image_agent.py index e7be89d17..f06c1c7ab 100644 --- a/src/agentscope/agents/text_to_image_agent.py +++ b/src/agentscope/agents/text_to_image_agent.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """A agent that convert text to image.""" -from typing import Optional +from typing import Optional, Union, Callable, Any from loguru import logger from .agent import AgentBase @@ -15,7 +15,7 @@ def __init__( self, name: str, sys_prompt: str, - model_config_name: str, + config_name_or_model: Union[str, Callable[..., Any]], use_memory: bool = True, memory_config: Optional[dict] = None, ) -> None: @@ -27,7 +27,7 @@ def __init__( sys_prompt (`Optional[str]`): The system prompt of the agent, which can be passed by args or hard-coded in the agent. - model_config_name (`str`, defaults to None): + config_name_or_model (`Union[str, Callable[..., Any]]`): The name of the model config, which is used to load model from configuration. use_memory (`bool`, defaults to `True`): @@ -38,7 +38,7 @@ def __init__( super().__init__( name=name, sys_prompt=sys_prompt, - model_config_name=model_config_name, + config_name_or_model=config_name_or_model, use_memory=use_memory, memory_config=memory_config, ) diff --git a/src/agentscope/service/__init__.py b/src/agentscope/service/__init__.py index 28ffdcd18..1fdb36d92 100644 --- a/src/agentscope/service/__init__.py +++ b/src/agentscope/service/__init__.py @@ -54,4 +54,5 @@ def get_help() -> None: "summarization", "retrieve_from_list", "ServiceExecStatus", + "ServiceFactory", ]