ReAct#

class src.openCHA.planners.react.base.ReActPlanner(*, llm_model: BaseLLM = None, available_tasks: List[BaseTask] | None = [], use_previous_action: bool = False)[source]#

Description:

This class implements ReAct planner, which inherits from the BasePlanner base class. ReAct employs reasoning and action techniques to ascertain the essential actions to be undertaken. Paper

This code defines a base class called “BasePlanner” that inherits from the “BaseModel” class of the pydantic library. The BasePlanner class serves as a base for implementing specific planners.

parse(query: str, **kwargs: Any) List[Action | PlanFinish][source]#

Parse the output query into a list of actions or a final answer. It parses the output based on the following format:

Thought: though

Action: action

Action Inputs: inputs

or

Thought: though

Final Answer: final answer

Parameters:
  • query (str) – The planner output query to extract actions.

  • **kwargs (Any) – Additional keyword arguments.

Returns:

List of parsed actions or a finishing signal.

Return type:

List[Union[Action, PlanFinish]]

Raises:

ValueError – If parsing encounters an invalid format or unexpected content.

plan(query: str, history: str = '', meta: str = '', previous_actions: List[Action] = None, use_history: bool = False, **kwargs: Any) List[Action | PlanFinish][source]#

Generate a plan using ReAct

Parameters:
  • query (str) – Input query.

  • history (str) – History information.

  • meta (str) – meta information.

  • previous_actions (List[Action]) – List of previous actions.

  • use_history (bool) – Flag indicating whether to use history.

  • **kwargs (Any) – Additional keyword arguments.

Returns:

return action.

Return type:

Action