File size: 7,707 Bytes
d4a9b53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f14a540
d4a9b53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6146371
d4a9b53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f14a540
 
 
 
d4a9b53
 
 
 
 
 
 
 
 
 
 
6146371
d4a9b53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6146371
d4a9b53
 
 
6146371
d4a9b53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f14a540
d4a9b53
 
 
d06f4f1
d4a9b53
 
 
 
 
 
 
 
d06f4f1
d4a9b53
 
 
 
 
e75262a
 
 
f14a540
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
_target_: Tachi67.JarvisFlowModule.Controller_JarvisFlow.instantiate_from_default_config
name: "ControllerFlow_JarvisFlow"
description: "Proposes the next action to take towards achieving the goal, and prepares the input for the branching flow"
enable_cache: True

#######################################################
# Input keys
#######################################################

input_interface_non_initialized: # initial input keys
  - "goal"
  - "memory_files"
  - "plan"
  - "logs"

input_interface_initialized:
  - "goal"
  - "result"
  - "memory_files"
  - "plan"
  - "logs"

#######################################################
# Output keys
#######################################################

output_interface:
  - 'command'
  - 'command_args'

backend:
  api_infos: ???
  model_name:
    openai: gpt-4
    azure: azure/gpt-4

commands:
  Coder:
    description: "Instruct the coder to write and run code to finish your given goal."
    input_args: [ "goal" ]
  re_plan:
    description: "When something is wrong with current plan, draft another plan based on the old plan and information about why it's bad or how to refine it."
    input_args: [ "goal" ]
  finish:
    description: "Signal that the objective has been satisfied, return the summary of what was done"
    input_args: [ "summary" ]
  manual_finish:
    description: "The user demands to quit and terminate the current process"
    input_args: [ ]
  ask_user:
    description: "Ask user a question for confirmation or assistance"
    input_args: [ "question" ]
  update_plan:
    description: "When one step of the plan is done, pass the updated plan to edit plan file and override current plan"
    input_args: [ "updated_plan" ]
  intermediate_answer:
    description: "When one step of the plan is done, pass the result from the step as an intermediate answer to the user"
    input_args: [ "answer" ]
  final_answer:
    description: "When the goal is achieved, pass the result from the goal as a final answer to the user"
    input_args: [ "answer" ]


system_message_prompt_template:
  _target_: langchain.PromptTemplate
  template: |2-
          Your department is in charge of achieving a particular goal by writing and running code. You are the leader of the department.
    
          Here is the goal you need to achieve:
            {{goal}}
          
          You work with several subordinates, they will be in charge of the specific tasks, including writing and running code to achieve a goal given specifically by you, re-planning, etc.
          
          To call one of the subordinates, you need to call the corresponding command with necessary arguments, here are the commands and their descriptions:
            {{commands}}
          
          You are given a step-by-step plan to finish the goal, **make sure you follow the plan**, **notice that, if you are informed that the plan is overriden, this plan is the new plan you should stick to.** The plan is stored at {{plan_file_location}}. Here is the plan:
            {{plan}}
              
          You should execute the plan step-by-step, for each step, you should do the following workflows:
          0.1 Whenever the user demands to quit or terminate the current process, call `manual_finish` command.
          0.2 Whenever in doubt, or you have something to ask, or confirm to the user, call `ask_user` with your question.
          0.3 During the execution of the plan, if something goes wrong, call the `re_plan` with detailed information about what was wrong.
          1. If the current step of plan can be achieved by writing and running code, call `Coder` with the goal of the current step of plan.
          2. Whenever you have done one step of the plan, do the following:
            2.1 Reflect on what plan you are having right now.
            2.2 Reflect on which step of the plan you just finished.
            2.3 Generate a plan, **it is exactly the same as the plan you have now, but with the current step of plan marked as done**
            2.4 Call `update_plan` with the plan you just generated.
          3. After you finish one step of the plan and have called `update_plan`, call `intermediate_answer` with the result of the step you just finished.
          4. The user will provide you with feedback on the last step executed, react accordingly.
          5. If the user is happy with the intermediate result, proceed to the next step of the plan, go back to workflow 1.
          5. When every step of the plan is done:
            5.1 Call `final_answer` with the result of the goal.
            5.2 React to the user's feedback, if the user is not happy, you may want to re-plan or give new instructions to the coder.
            5.3 If the user is happy, call `finish` with a summary of what was done throughout the process.

          **You MUST call `update_plan` whenever you realize one step of the plan is done.**
          **You MUST call `finish` whenever everything is done and the user is happy.**
          
          Here is an example of execution:  
          ### Beginning of an example execution: ###
          Plan: 1. Download the weather data from Paris on 19. Dec. 2021. 2. Send the weather data to an email address. 3. Give a final answer.
          Your actions:
          1. Call `Coder` with the goal of the first step of the plan. Code is written and run, the weather data is downloaded.
          2. You call `update_plan` with the plan you just generated, it is exactly the same as the plan you have now, but with the current step of plan marked as done.
          3. You call `intermediate_answer` with the result of the step you just finished.
          4. The user is happy with the intermediate result, you proceed to the next step of the plan.
          5. Call `Coder` with the goal of the second step of the plan. Code is written and run, the weather data is sent to an email address.
          6. You call `update_plan` with the plan you just generated, it is exactly the same as the plan you have now, but with the current step of plan marked as done.
          7. You call `intermediate_answer` with the result of the step you just finished.
          8. The user is happy with the intermediate result, you proceed to the next step of the plan.
          9. Call `final_answer` with the result of the goal.
          10. The user is happy with the final result, you call `finish` with a summary of what was done throughout the process.
          ### End of an example of execution ###
    
          Here is a list of history actions you have taken, for your reference:
            {{logs}}
    
          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 one of the subordinates",
              "command_args": {
                  "arg name": "value"
                  }
              }
          Ensure your responses can be parsed by Python json.loads

  input_variables: ["commands", "plan", "logs", "plan_file_location", "goal"]
  template_format: jinja2

human_message_prompt_template:
  _target_: aiflows.prompt_template.JinjaPrompt
  template: |2-
    Here is the result of your previous action:
    {{result}}
  input_variables:
    - "result"
  template_format: jinja2

init_human_message_prompt_template:
  _target_: aiflows.prompt_template.JinjaPrompt
  template: |2-
    Here is the goal you need to achieve, follow your plan to finish the goal:
    {{goal}}
  input_variables:
    - "goal"
  template_format: jinja2

previous_messages:
  last_k: 3