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.

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

effects

human_input_key

max_retries

preconditions

qos

read_only

require_human_approval

utility