File size: 1,566 Bytes
01523b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from __future__ import annotations
import asyncio
from colorama import Fore

from typing import TYPE_CHECKING, List

from . import decision_maker_registry
from .base import BaseDecisionMaker
from agentverse.logging import typewriter_log, logger
from agentverse.message import Message

if TYPE_CHECKING:
    from agentverse.agents import BaseAgent, SolverAgent, CriticAgent
    from agentverse.message import SolverMessage


@decision_maker_registry.register("central")
class CentralDecisionMaker(BaseDecisionMaker):
    """
    Discuss in a central manner.
    """

    name: str = "central"

    async def astep(
        self,
        agents: List[BaseAgent],
        task_description: str,
        previous_plan: str = "No solution yet.",
        advice: str = "No advice yet.",
        *args,
        **kwargs,
    ) -> List[SolverMessage]:
        if advice != "No advice yet.":
            agents[1].add_message_to_memory(
                [Message(content=advice, sender="Evaluator")]
            )
        result = await agents[1].astep(
            previous_plan,
            advice,
            task_description,
            roles=", ".join(
                [
                    agent.role_description[0].lower() + agent.role_description[1:]
                    for agent in agents
                ]
            ),
        )
        agents[1].add_message_to_memory([result])
        result = agents[0].step(
            previous_plan, advice, task_description, chat_record=result.content
        )
        return [result]

    def reset(self):
        pass