Methods

Methods define prompting mechanisms used to query the agent in Agent. Accompanied by prompt templates, they define the sequence of prompts submitted to the LLM. They are responsible for the agent’s ‘strategy’, defining the series of Commandsintrinsic functions the agent should execute before taking actions in a given task.

Flows and Intrinsic Functions form a core part of methods, and are essentially the building blocks. As such, it is strongly recommended to read the Flows and Intrinsic Functions documentation along with this page, especially if you are interested in building your own methods.

Method Structure

Methods define the agent’s high-level flows. There are several of these, which define all actions the agent should take, or at least consider, at different stages. We explain the following high-level agent flows:

  • run_on_init_flow() : Defines any actions the agent should take upon initialization, before the first episode even starts.

  • run_on_episode_start_flow() : Defines any actions the agent should take at the start of each episode.

  • run_pre_action_flow() : Defines any actions the agent should take before submitting an action to the environment.

  • run_post_action_flow() : Defines any actions the agent should take after submitting an action to the environment.

  • run_on_episode_end_flow() : Defines any actions the agent should take at the end of each episode.

Each of these can be as complex as required, made up of multiple flows and intrinsic functions of various types.

Most methods will likely only need to define the run_pre_action_flow(), which is actually charged with generating the action to submit to the environment. In fact, run_pre_action_flow() is the only one which must be defined by a new method, the others are optional. Moreover, run_pre_action_flow() must include the Act extrinsic function (or a composite command including Act) to ensure the agent submits an action to the environment.

Method Configs

While they depend on defined flows and intrinsic functions, methods themselves are defined exclusively through a yaml configuration file, under configs/method/. The configuration filename should match the method name, and the configuration defines the various high-level flows mentioned above, as well as any method-specifc variables the prompt builder should have access to. An example config for the direct method is given below:

# @package _global_
agent:
  pre_action_flow:
    _target_: agent.commands.SequentialFlow
    sequence:
      - _target_: agent.commands.Act
  prompt_builder:
    default_kwargs:
      cot_type: zero_shot

Here, the method defines only the agent.pre_action_flow, composed of a single seuqnetial flow with a single Act command. This is the bare minimum a method should define. It also defines agent.prompt_builder.default_kwargs.cot_type, which sets a variable the prompt builder will be able to use to decide whether to include a request for chain-of-thought (CoT) in the prompt.

Existing Methods

Agent comes packaged with several core inbuilt reasoning methods. The core methods included are:

  • direct : Prompts the agent to directly output an action for the environment.

  • zs-cot : Prompts the agent to generate thoughts before giving an action.

  • fs : Prompts the agent to directly output an action for the environment, with in-context examples provided in the prompt.

  • fs-cot : Prompts the agent to generate thoughts before giving an action, with in-context examples provided in the prompt.

  • fs-cot-react : Prompts the agent to first only generate a thought, and then an action in the subsequent reasoning step.

  • fs-cot-reflect : Prompts the agent to first reflect on past trajectory, and then generate an action in the subsequent reasoning step.

  • fs-cot-zerostep-reflect : Prompts the agent to give an action, and then immediately reflect on whether that action is the best choice.

  • fs-cot-sc : Runs fs-cot several times and selects most consistent action.

  • fs-least2most : Prompts the agent to decompose the problem into sub-problems, and then to solve the subproblems before generating an action.

Most methods are available for all types of tasks. However, a few are specific to single-step or multi-step tasks. fs-cot-reflect reflects on past trajectory and is therefore only suitable for multi-step tasks, while fs-cot-zerostep-reflect is the approximate equivalent for single-step tasks. Furthermore, fs-least2most is only suitable for single-step tasks, requiring all subproblems to be solved in a single step.

Custom Methods

In addition to all existing methods, you can easily create your own methods by writing new method configuration file. If you require new Flows or Intrinsic Functions, these should also be defined in the appropriate fashion.

Please see the Creating a New Method tutorial for a guided example on creating and using a new method.