Update CtrlExMemFlow.py
Browse files- CtrlExMemFlow.py +43 -0
CtrlExMemFlow.py
CHANGED
|
@@ -10,11 +10,54 @@ log = logging.get_logger(__name__)
|
|
| 10 |
|
| 11 |
|
| 12 |
class CtrlExMemFlow(CircularFlow, ABC):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
@abstractmethod
|
| 14 |
def _on_reach_max_round(self):
|
|
|
|
| 15 |
pass
|
| 16 |
|
| 17 |
@abstractmethod
|
| 18 |
@CircularFlow.output_msg_payload_processor
|
| 19 |
def detect_finish_or_continue(self, output_payload: Dict[str, Any], src_flow) -> Dict[str, Any]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
pass
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
class CtrlExMemFlow(CircularFlow, ABC):
|
| 13 |
+
"""This class is the controller-executor agent with memory reading and memory writing, it will execute the plan
|
| 14 |
+
generated by the planner. This flow is, at a higher level, a circular flow, it runs until either max_round is
|
| 15 |
+
reached, or the controller decides to early exit (see: detect_finish_or_continue)
|
| 16 |
+
|
| 17 |
+
The brain of the flow is the controller, the controller decides what action (which branch of the branching flow)
|
| 18 |
+
to take next. The controller can also decide to early exit the flow, in which case the flow will stop. After the
|
| 19 |
+
controller decides what action to take, the controller will pass the action to the executor, the executor will
|
| 20 |
+
execute the action, yielding `result` and `summary`, which respectively will be passed to the controller and the
|
| 21 |
+
memory writer (into logs of the upper layer of flow). Depending on the `result`, the controller will decide what
|
| 22 |
+
action to take next.
|
| 23 |
+
|
| 24 |
+
*Configuration Parameters*:
|
| 25 |
+
- `name` (str): Name of the flow.
|
| 26 |
+
- `description` (str): Description of the flow.
|
| 27 |
+
- `max_round` (int): The maximum number of rounds the flow will run. Default: 30.
|
| 28 |
+
- `subflows_config` (dict): The configuration of the subflows.
|
| 29 |
+
- `Controller` (dict): The configuration of the controller. It is important that the target of the controller (instance customizable by the user) and the api information should be specified.
|
| 30 |
+
- `Executor` (dict): The executor of the flow, it is supposed to be a branching flow. To instantiate the executor, the user needs to specify the subflows of the executor (i.e. the actual tools that can be used by the agent, e.g. a flow for interpreting code)
|
| 31 |
+
- `MemoryWriting` (dict): The configuration of the memory writer. There is an existing memory writing flow implemented.
|
| 32 |
+
- 'MemoryReading' (dict): The configuration of the memory reader. There is an existing memory reading flow implemented.
|
| 33 |
+
- `topology` (List): The topology of the subflows, notice that the output interface of the Controller must be implemented and specified.
|
| 34 |
+
|
| 35 |
+
*Input Interface*:
|
| 36 |
+
- `plan` (str): The plan generated by the planner, the CtrlExMem flow should follow the plan.
|
| 37 |
+
- `memory_files` (dict): mem_name - memfile_path pairs, the memory files that the memory reader will read from.
|
| 38 |
+
- `goal` (str): The goal of the flow
|
| 39 |
+
- `logs` (str): Execution history of the flow, contains all actions taken by each subflow of the flow.
|
| 40 |
+
|
| 41 |
+
*Output Interface*:
|
| 42 |
+
- `result` (str): The result of the flow, will be returned to the controller of the caller flow.
|
| 43 |
+
- `summary` (str): The summary of the flow, will be written to the logs of the caller flow.
|
| 44 |
+
|
| 45 |
+
"""
|
| 46 |
@abstractmethod
|
| 47 |
def _on_reach_max_round(self):
|
| 48 |
+
"""This function will be called when the flow reaches the maximum number of rounds."""
|
| 49 |
pass
|
| 50 |
|
| 51 |
@abstractmethod
|
| 52 |
@CircularFlow.output_msg_payload_processor
|
| 53 |
def detect_finish_or_continue(self, output_payload: Dict[str, Any], src_flow) -> Dict[str, Any]:
|
| 54 |
+
"""This function is called after the Controller, it is used to:
|
| 55 |
+
1. Check if the Controller decides to early-exit, if so, implement necessary logics for exiting e.g. drafting result and summary, etc.
|
| 56 |
+
2. For other commands called by the controller, implement necessary logics for the flow to continue e.g. providing necessary information to the branching flow.
|
| 57 |
+
:param output_payload: The output payload of the Controller.
|
| 58 |
+
:type output_payload: Dict[str, Any]
|
| 59 |
+
:param src_flow: The source flow of the Controller.
|
| 60 |
+
:type src_flow: Flow
|
| 61 |
+
:return: The input payload of the Executor.
|
| 62 |
+
"""
|
| 63 |
pass
|