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.
on_resume(state)For a wait (
is_wait = True): called after every resume, before the sensors are asked.to_spec()Convert this action instance to an ActionSpec.
validate_effects(pre_state, post_state)Verify that execution produced the expected effects.
Attributes
can_rerundurationWall-clock duration for CP-SAT temporal scheduling.
effect_keysKeys a callable
effectsmay write; required with callable effects.effectsStatic effects mapping, or a callable
(world_state) -> effects(declare it as a@staticmethodand seteffect_keys).human_input_keyis_waitTruemakes the action a wait (seeActionSpec.wait()):execute()prepares it andon_resume()runs on every resume.max_retriesmetadataFree-form, JSON-serialisable metadata attached to the action.
observeExtra state keys read from the sensors after the action (observed effects).
preconditionsqosread_onlyrequire_human_approvalresourcesCSP resource consumption per run (e.g.
{"cost_usd": 0.02}).utilitywait_payloadExtra entries for a wait's interrupt payload.