langgoap.GoapAction

langgoap.GoapAction#

class GoapAction[source]#

Base class for object-oriented GOAP action definitions.

Subclass and override preconditions, effects, cost(), and execute() to define an action.

Important: declare preconditions and effects as class attributes on your subclass, not on GoapAction itself, 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_rerun

duration

Wall-clock duration for CP-SAT temporal scheduling.

effect_keys

Keys a callable effects may write; required with callable effects.

effects

Static effects mapping, or a callable (world_state) -> effects (declare it as a @staticmethod and set effect_keys).

human_input_key

is_wait

True makes the action a wait (see ActionSpec.wait()): execute() prepares it and on_resume() runs on every resume.

max_retries

metadata

Free-form, JSON-serialisable metadata attached to the action.

observe

Extra state keys read from the sensors after the action (observed effects).

preconditions

qos

read_only

require_human_approval

resources

CSP resource consumption per run (e.g. {"cost_usd": 0.02}).

utility

wait_payload

Extra entries for a wait's interrupt payload.