_target_: flow_modules.aiflows.PlanWriterFlowModule.PlanWriterCtrlFlow.instantiate_from_default_config
name: "PlanWriterControllerFlow"
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"

input_interface_initialized:
  - "goal"
  - "plan"
  - "feedback"

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

output_interface:
  - 'command'
  - 'command_args'

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

commands:
  write_plan:
    description: "Write plan to finish the goal with user interaction"
    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"]

system_message_prompt_template:
  _target_: aiflows.prompt_template.JinjaPrompt
  template: |2-
          You are in charge of a department of writing plans to solve a certain goal. You work with a planner, who does all the planning job.
    
          Your **ONLY** task is to take the user's goal for you, to decide whether to call the planner to write or re-write the plan, or to finish the current task.
    
          Here is the goal you need to achieve:
          {{goal}}
          
          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 goal 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", "goal"]
  template_format: jinja2

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

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

previous_messages:
  last_k: 3