langgoap.GoapAction#
- class GoapAction[source]#
Base class for object-oriented GOAP action definitions.
Subclass and override
preconditions,effects,cost(), andexecute()to define an action.Important: declare
preconditionsandeffectsas class attributes on your subclass, not onGoapActionitself, to avoid the shared-mutable-dict antipattern:class GatherData(GoapAction): preconditions = {"has_source": True} effects = {"has_data": True} def cost(self, world_state: dict[str, Any]) -> float: return 1.5 def execute(self, state: dict[str, Any]) -> dict[str, Any]: return {"has_data": True}
- __init__()#
Methods
__init__()aexecute(state)Async execute.
cost(world_state)Return the cost of this action.
execute(state)Execute the action.
to_spec()Convert this action instance to an ActionSpec.
validate_effects(pre_state, post_state)Verify that execution produced the expected effects.
Attributes
can_reruneffectshuman_input_keymax_retriespreconditionsqosread_onlyrequire_human_approvalutility