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

Can you release some examples about how to use RoleReactMode #1667

Open
GitEasonXu opened this issue Jan 15, 2025 · 1 comment
Open

Can you release some examples about how to use RoleReactMode #1667

GitEasonXu opened this issue Jan 15, 2025 · 1 comment

Comments

@GitEasonXu
Copy link

Feature description

All examples is react_mode = BY_ORDER.
I know MetaGPT supporting REACT or PLAN_AND_ACT model, so could you release more example how to use REACT or PLAN_AND_ACT.

@iorisa
Copy link
Collaborator

iorisa commented Jan 16, 2025

The Data Interpreter utilizes the PLAN_AND_ACT mode.
You can find the detailed code in metagpt/roles/di/data_interpreter.py.
You can also find relevant demos at Data Interpreter (DI) | MetaGPT.

Regarding REACT, it consists of three actions: observe, think, and act. You can see these three operations (_observe(.), _think(.), _act(.)) in the base class Role in metagpt/roles/role.py:

    @role_raise_decorator
    async def run(self, with_message=None) -> Message | None:
        """Observe, and think and act based on the results of the observation"""
        ......
        if not await self._observe():
            ......
            return

        rsp = await self.react()

        .......
        return rsp
    async def react(self) -> Message:
        """Entry to one of three strategies by which Role reacts to the observed Message"""
        if self.rc.react_mode == RoleReactMode.REACT or self.rc.react_mode == RoleReactMode.BY_ORDER:
            rsp = await self._react()
        elif ......
        return rsp
    async def _react(self) -> Message:
        ......
        while actions_taken < self.rc.max_react_loop:
            # think
            todo = await self._think()
            if not todo:
                break
            # act
            rsp = await self._act()
            actions_taken += 1
        return rsp  # return output from the last action

When self.rc.max_react_loop of the _react is greater than 1, it is the BY_ORDER mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants