modelscope / agentscope

Start building LLM-empowered multi-agent applications in an easier way.
https://doc.agentscope.io/
Apache License 2.0
5.32k stars 328 forks source link

[Question]: 新版的agentscope没了StateAgent,替换类是什么?如何使用register_state方法? #458

Closed frankiegu closed 1 month ago

frankiegu commented 1 month ago

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

Describe the question 新版的agentscope没了StateAgent,替换类是什么?如何使用register_state方法?

To Reproduce Steps to reproduce the behavior:

from agentscope.agents import StateAgent, DialogAgent
class Customer(StateAgent, DialogAgent):
    def __init__(self, game_config: dict, **kwargs: Any):
        self.uid = kwargs.pop("uid")
        super().__init__(**kwargs)
        self.retry_time = 3
        self.game_config = game_config
        self.max_itr_preorder = 5
        self.preorder_itr_count = 0

        avatar_path = self.config.get("avatar")
        # 检查路径是否存在且为文件
        if avatar_path is not None and os.path.isfile(avatar_path):
            self.avatar = avatar_path
        else:
            # 如果路径不存在或不是文件,则获取一个随机头像
            self.avatar = get_a_random_avatar()
        self.background = self.config["character_setting"]["background"]
        self.dialogue = self.config["character_setting"]["dialogue"]
        # self.friendship = int(self.config.get("friendship", 60))
        self.is_satisfied = False
        self.relationship = Relationship(
            self.config.get("relationship", "陌生"),
            MIN_BAR_RECEIVED_CONST,
        )
        self.preferred_info = ''
        self.cur_state = CustomerConv.WARMING_UP
        # TODO: A customer can be in at most one plot in the current version
        self.active_plots = []
        self.prev_active_plots = []

        self.register_state(
            state=CustomerConv.OPENING,
            handler=self._opening_chat,
        )

Environment (please complete the following information):