langgoap.MultiGoal

langgoap.MultiGoal#

class MultiGoal(goals, mode='sequential', on_infeasible='fail')[source]#

A composite goal made up of one or more GoalSpec children.

Two execution modes are supported:

  • "sequential" (default) — the observer plans and executes goals[0] to completion, then uses the resulting world state as the starting state for goals[1], and so on. This is the right model when sub-goals represent successive stages of a workflow (e.g. “collect data → analyse → publish”). A sub-goal that is already satisfied is passed over without planning. A sub-goal that cannot be planned ends the run with no_plan (on_infeasible="fail", the default); with on_infeasible="skip" the planner moves on to the next sub-goal, records the index in GoapState.skipped_subgoals, and the run finishes with status="partial" instead of "goal_achieved" (issue #35).

  • "any" — the planner plans each sub-goal independently and the observer picks the lowest-Score feasible plan. Useful when several possible goals are acceptable and the system should chase the cheapest one.

Recursive (HTN-style) decomposition where a sub-goal is itself a Nested MultiGoal is out of scope — only flat composition is supported and __post_init__() rejects non-GoalSpec children with a clear ValueError.

In "any" mode, ties on plan cost are broken by list order: the first sub-goal whose plan has the lowest cost wins. This makes the order of goals semantically meaningful when several candidates are equally cheap.

Parameters:
  • goals (tuple[GoalSpec, ...]) – Non-empty sequence of GoalSpec children. Accepts tuples or lists; a list is coerced to a tuple.

  • mode (Literal['sequential', 'any', 'best_value']) – Either "sequential", "any" or "best_value".

  • on_infeasible (Literal['fail', 'skip']) – Sequential mode only. "fail" (default) stops with no_plan at the first sub-goal that cannot be planned; "skip" continues with the next one and reports partial.

__init__(goals, mode='sequential', on_infeasible='fail')#
Parameters:
  • goals (tuple[GoalSpec, ...])

  • mode (Literal['sequential', 'any', 'best_value'])

  • on_infeasible (Literal['fail', 'skip'])

Return type:

None

Methods

__init__(goals[, mode, on_infeasible])

from_dict(data)

Reconstruct from the dict produced by to_dict().

to_dict()

Serialise to a JSON-native dict (inverse of from_dict()).

Attributes

goals

mode

on_infeasible