File size: 7,572 Bytes
d6eb336
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
424f6b7
d6eb336
 
 
 
 
 
 
 
 
 
 
424f6b7
d6eb336
 
 
 
 
 
 
 
424f6b7
d6eb336
 
 
dee299f
 
 
 
d6eb336
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dee299f
 
 
424f6b7
dee299f
424f6b7
dee299f
 
 
 
 
424f6b7
dee299f
424f6b7
dee299f
 
 
 
 
424f6b7
dee299f
424f6b7
dee299f
 
424f6b7
dee299f
 
 
 
d6eb336
 
 
 
 
 
 
 
 
424f6b7
d6eb336
424f6b7
d6eb336
 
 
 
 
 
 
424f6b7
d6eb336
 
 
 
 
 
424f6b7
14a2c9a
 
 
 
 
d6eb336
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
name: "ReplanningFlow"
description: "Re-plan given old plan and new information"

_target_: Tachi67.ReplanningFlowModule.ReplanningFlow.instantiate_from_default_config

input_interface:
  - "goal" # info on the old plan
  - "plan" # the old plan
  - "plan_file_location"

output_interface:
  - "plan"
  - "status"
  - "summary"
  - "result"

### Subflows specification
subflows_config:
  Controller:
    _target_: Tachi67.PlanWriterFlowModule.PlanWriterCtrlFlow.instantiate_from_default_config
    backend:
      api_infos: ???
      model_name:
        openai: gpt-4
        azure: azure/gpt-4
    input_interface_initialized:
      - "new_plan"
      - "feedback"
    system_message_prompt_template:
      _target_: langchain.PromptTemplate
      template: |2-
              You are in charge of a department of rewriting plans to solve a certain goal. You work with a re-planner, who does all the re-planning job.

              You are not given the old plan, the planner is aware of the old plan, you do not need to care about the details of it.
             
              Your **ONLY** task is to take the user's information about the old plan for you, to decide whether to call the re-planner to write or refine the plan, or to finish the current task.

              When you need to call the plan writer, call the `write_plan` command with the goal specified.
              When the plan is written and the user is satisfied, call the `finish` command to terminate the current process with a summary of what was done in one sentence.
              Whenever you are in doubt, or need to confirm something to the user, call `ask_user` with the question.

              You **must not** write plans yourself. You only decide whether to call the planner with specified goals or to finish.

              Your workflow:
              0. Whenever the user demands to quit or terminate the current process, call `manual_finish` command.
              1. Upon user request, call the `write_plan` with the information given.
              2. The planner will write the plan. The user will examine the plan, and provide feedback.
              3. Depending on the feedback of the user:
                3.1. The user provides feedback on how to change the plan, **call the planner with user's specific requirements again, to ask the planner to refine the plan**. Go back to step 2.
                3.2. The user does not provide details about refining the plan, for example, just stating the fact that the user has updated the plan, **this means the user is satisfied with the plan written, call the `finish` command.**
                3.3. The user is satisfied with the plan, **call the `finish` command with a summary of what was done**

              If you have completed all your tasks, make sure to use the "finish" command, with a summary of what was done.

              Constraints:
              1. Exclusively use the commands listed in double quotes e.g. "command name"

              Your response **MUST** be in the following format:
                  Response Format:
                  {
                  "command": "call plan writer, or to finish",
                  "command_args": {
                      "arg name": "value"
                      }
                  }
              Ensure your responses can be parsed by Python json.loads


              Available Functions:
              {{commands}}
      input_variables: [ "commands" ]
      template_format: jinja2

    human_message_prompt_template:
      _target_: aiflows.prompt_template.JinjaPrompt
      template: |2-
        Here is the new plan written by the planner, it might have been updated by the user, depending on the user's feedback:
        {{new_plan}}
        Here is the feedback from the user:
        {{feedback}}
      input_variables:
        - "new_plan"
        - "feedback"
      template_format: jinja2

    init_human_message_prompt_template:
      _target_: aiflows.prompt_template.JinjaPrompt
      template: |2-
        Here is the information about the old plan:
        {{goal}}
      input_variables:
        - "goal"
      template_format: jinja2

  Executor:
    _target_: aiflows.base_flows.BranchingFlow.instantiate_from_default_config
    subflows_config:
      write_plan:
        _target_: Tachi67.InteractivePlanGenFlowModule.InteractivePlanGenFlow.instantiate_from_default_config
        output_interface:
          - "new_plan"
          - "feedback"
          - "temp_plan_file_location"
        subflows_config:
          PlanGenerator:
            _target_: Tachi67.ReplanningFlowModule.NewPlanGenFlow.instantiate_from_default_config
            backend:
              api_infos: ???
              model_name:
                openai: gpt-4
                azure: azure/gpt-4
          PlanFileEditor:
            _target_: Tachi67.PlanFileEditFlowModule.PlanFileEditAtomicFlow.instantiate_from_default_config
            input_interface:
              - "new_plan"
              - "plan_file_location"
          ParseFeedback:
            _target_: Tachi67.ParseFeedbackFlowModule.ParseFeedbackAtomicFlow.instantiate_from_default_config
            input_interface:
              - "temp_plan_file_location"
            output_interface:
              - "new_plan"
              - "feedback"

        topology:
          - goal: "Generate plan to achieve the task."
            input_interface:
              _target_: aiflows.interfaces.KeyInterface
              additional_transformations:
                - _target_: aiflows.data_transformations.KeyMatchInput
            flow: PlanGenerator
            reset: false

          - goal: "Write the plan generated to a temp file with instructions to the user"
            input_interface:
              _target_: aiflows.interfaces.KeyInterface
              additional_transformations:
                - _target_: aiflows.data_transformations.KeyMatchInput
            flow: PlanFileEditor
            reset: false

          - goal: "Parse user feedback from the temp file"
            input_interface:
              _target_: aiflows.interfaces.KeyInterface
              additional_transformations:
                - _target_: aiflows.data_transformations.KeyMatchInput
            flow: ParseFeedback
            output_interface:
              _target_: aiflows.interfaces.KeyInterface
              keys_to_rename:
                plan: new_plan
            reset: false

      ask_user:
        _target_: Tachi67.ReplanningFlowModule.ReplanningAskUserFlow.instantiate_from_default_config


early_exit_key: "EARLY_EXIT"

topology:
  - goal: "Select the next action and prepare the input for the executor."
    input_interface:
      _target_: aiflows.interfaces.KeyInterface
      additional_transformations:
        - _target_: aiflows.data_transformations.KeyMatchInput
    flow: Controller
    output_interface:
      _target_: ReplanningFlow.detect_finish_or_continue
    reset: false

  - goal: "Execute the action specified by the Controller."
    input_interface:
      _target_: aiflows.interfaces.KeyInterface
      keys_to_rename:
        command: branch
        command_args: branch_input_data
      keys_to_select: ["branch", "branch_input_data"]
    flow: Executor
    output_interface:
      _target_: aiflows.interfaces.KeyInterface
    keys_to_rename:
      branch_output_data.new_plan: new_plan
      branch_output_data.feedback: feedback
      branch_output_data.temp_plan_file_location: temp_plan_file_location
    keys_to_delete: ["branch_output_data"]
    reset: false