langgoap.MultiGoal#
- class MultiGoal(goals, mode='sequential', on_infeasible='fail')[source]#
A composite goal made up of one or more
GoalSpecchildren.Two execution modes are supported:
"sequential"(default) — the observer plans and executesgoals[0]to completion, then uses the resulting world state as the starting state forgoals[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 withno_plan(on_infeasible="fail", the default); withon_infeasible="skip"the planner moves on to the next sub-goal, records the index inGoapState.skipped_subgoals, and the run finishes withstatus="partial"instead of"goal_achieved"(issue #35)."any"— the planner plans each sub-goal independently and the observer picks the lowest-Scorefeasible 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
MultiGoalis out of scope — only flat composition is supported and__post_init__()rejects non-GoalSpecchildren with a clearValueError.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 ofgoalssemantically meaningful when several candidates are equally cheap.- Parameters:
goals (tuple[GoalSpec, ...]) – Non-empty sequence of
GoalSpecchildren. 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 withno_planat the first sub-goal that cannot be planned;"skip"continues with the next one and reportspartial.
- __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
goalsmodeon_infeasible