region:us
### Structure of Coder

```
     goal, memory_files (dict)
             |
             v
    +-------------------+
    |  MemoryReading    |  Reads in the content of the memory files
    |    Flow           |
    +-------------------+
             |
             | (memory_content)
             |
             v
    +-------------------+
    |    PlanWriter     |  Writes a step-by-step plan to achieve the goal
    +-------------------+
             |
             | (plan)
             |
             v
    +-------------------+
    |   CtrlExMemFlow   |  Illustrated below. Carries out the plan in an controller-executor fashion,
    |                   |  with memory management mechanisms.
    +-------------------+
             |
    (summary, result)

```

Here is the structure of the `CtrlExMemFlow`:
```
    plan, memory_files, memory_content, goal
                |
                v
        +---------------+
        |  Controller   | --------<<<<-----------+
        +---------------+                        |
                |                                |
                | (command, command args)        |
                |                                |
                v                                |
        +------------------+                     |
        |   Executor       |  Each branch is an  |
        | (Tree Structure) |  executor           |
        +------------------+                     |
                |                                ^
                | (execution results)            ^
                |                                ^
                v                                ^
        +---------------+                        ^
        | MemWriteFlow  |  Updates memory files  ^
        +---------------+                        ^
                |                                ^
                | (summary)                      |
                |                                |
                v                                |
        +---------------+                        |
        | MemReadFlow   |  Reads updated memory  |
        +---------------+                        |
                |                                |
                | (updated memory content)       |
                |                                |
                +-> goes back to the Controller>-+

```
Structure of the Executors:
```
                 +-------------------+
                 |   Branching       |
                 |    Executor       |
                 +-------------------+
        /          |       |       |         \
       /           |       |       |          \
      /            |       |       |           \
     /             |       |       |            \
Extend_library  ask_user re_plan update_plan   run_code

```

Memory files of Coder:
- plan_coder.txt
- logs_coder.txt
- library.py

About the branches:
- [ExtendLibrary](https://huggingface.co/Tachi67/ExtendLibraryFlowModule): Writes and tests code functions in an interactive fashion, finally saves the written function to the code library.
- [ask_user](https://huggingface.co/Tachi67/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py): Ask user for info / confirmation, etc.
- [re_plan](https://huggingface.co/Tachi67/ReplanningFlowModule): One branch of the executors, when something goes wrong, re-draft the plan.
- [update_plan](https://huggingface.co/Tachi67/JarvisFlowModule/blob/main/UpdatePlanAtomicFlow.py): One branch of the executors, when the controller realizes that one (or some, depending on the LLM's response) step of the plan is (are) done, it generates a new plan that marks the step(s) as done.
- [run_code](https://huggingface.co/Tachi67/RunCodeFlowModule): Runs the code written by the Controller, will first open up a temp file with the code for user confirmation and editing, then the code is passed to the [InterpreterFlow](https://huggingface.co/Tachi67/InterpreterFlowModule).
  



# Table of Contents

* [CtrlExMem\_CoderFlow](#CtrlExMem_CoderFlow)
  * [CtrlExMem\_CoderFlow](#CtrlExMem_CoderFlow.CtrlExMem_CoderFlow)
* [run\_coder](#run_coder)
* [Planner\_CoderFlow](#Planner_CoderFlow)
  * [Planner\_CoderFlow](#Planner_CoderFlow.Planner_CoderFlow)
* [Controller\_CoderFlow](#Controller_CoderFlow)
  * [Controller\_CoderFlow](#Controller_CoderFlow.Controller_CoderFlow)
* [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow)
  * [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow)
* [CoderFlow](#CoderFlow)
  * [CoderFlow](#CoderFlow.CoderFlow)
    * [run](#CoderFlow.CoderFlow.run)
* [\_\_init\_\_](#__init__)

<a id="CtrlExMem_CoderFlow"></a>

# CtrlExMem\_CoderFlow

<a id="CtrlExMem_CoderFlow.CtrlExMem_CoderFlow"></a>

## CtrlExMem\_CoderFlow Objects

```python
class CtrlExMem_CoderFlow(CtrlExMemFlow)
```

This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule.
See: https://huggingface.co/Tachi67/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py

*Input Interface*:
- `plan`
- `logs`
- `code_library`: the signatures and docstring of the functions in the code library.
- `memory_files`
- `goal`

*Output Interface*
- `result` (str): The result of the flow, the result will be returned to the caller.
- `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow.

<a id="run_coder"></a>

# run\_coder

<a id="Planner_CoderFlow"></a>

# Planner\_CoderFlow

<a id="Planner_CoderFlow.Planner_CoderFlow"></a>

## Planner\_CoderFlow Objects

```python
class Planner_CoderFlow(PlanWriterFlow)
```

Planner of the coder flow, it inherits from PlanWriterFlow, see: https://huggingface.co/Tachi67/PlanWriterFlowModule

<a id="Controller_CoderFlow"></a>

# Controller\_CoderFlow

<a id="Controller_CoderFlow.Controller_CoderFlow"></a>

## Controller\_CoderFlow Objects

```python
class Controller_CoderFlow(ChatAtomicFlow)
```

Refer to: https://huggingface.co/Tachi67/JarvisFlowModule/blob/main/Controller_JarvisFlow.py

<a id="UpdatePlanAtomicFlow"></a>

# UpdatePlanAtomicFlow

<a id="UpdatePlanAtomicFlow.UpdatePlanAtomicFlow"></a>

## UpdatePlanAtomicFlow Objects

```python
class UpdatePlanAtomicFlow(AtomicFlow)
```

This flow updates the plan file with the updated plan. The controller should pass the updated plan to this flow.
This design (controller reflect on the existing plan--update plan) is intended to let the controller more aware of the
plan it has. However one setback is that this process in then not deterministic.

*Input Interface*
- `updated_plan`: the updated plan in string format

*Output Interface*
- `result`: the result of the update plan operation

<a id="CoderFlow"></a>

# CoderFlow

<a id="CoderFlow.CoderFlow"></a>

## CoderFlow Objects

```python
class CoderFlow(AbstractBossFlow)
```

Coder flow is one executor branch of the Jarvis flow. At a higher level, it is a flow that
writes and runs code given a goal. In the Jarvis flow, the Coder flow in invoked by the controller,
The Coder flow receives the goal generated by the controller, writes and runs code in an interactive fashion.

The Coder flow has the similar structure as the Jarvis flow (inherited from AbstractBossFlow).


*Input Interface (expected input)*
- `goal` (str): The goal from the caller (source flow, i.e. JarvisFlow)


*Output Interface (expected output)*
- `result` (str): The result of the flow, the result will be returned to the caller (i.e. JarvisFlow).
- `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow (i.e. JarvisFlow).

Typical workflow of Coder:
0. JarvisFlow calls Coder with a goal.
1. MemoryReading reads plans, logs and code library.
2. Planner makes plan based on goal.
3. Extend library with the goal given by the controller.
4. Run code with code (possibly calls the newly written function) given by the controller.
5. Finish and give an answer.

<a id="CoderFlow.CoderFlow.run"></a>

#### run

```python
def run(input_data: Dict[str, Any]) -> Dict[str, Any]
```

The run function of the Coder flow.

**Arguments**:

- `input_data` (`Dict[str, Any]`): The input data of the flow.

**Returns**:

`Dict[str, Any]`: The output data of the flow.

<a id="__init__"></a>

# \_\_init\_\_

