langgoap.add_goap_subgraph

langgoap.add_goap_subgraph#

add_goap_subgraph(parent_builder, *, name, actions, goal, input_key='world_state', output_key='plan_result', compile_kwargs=None, strategy=None, tracer=None, history=None, sensors=None, guards=None, resolvers=None, record_expansions=False, transition_model=None, rng=None, stuck_handlers=None, max_stuck_iterations=3, termination_policies=None, executor='sequential', history_state='full')[source]#

Attach a GOAP sub-graph as a node inside a parent StateGraph.

The sub-graph is compiled and registered as a node with sync and async variants. Each variant:

  1. Reads state[input_key] from the parent state.

  2. Invokes the sub-graph (invoke under parent.invoke, ainvoke under parent.ainvoke) with a fresh JSON-native input carrying that world state and the configured goal, and with the parent’s RunnableConfig, so the parent’s checkpointer, callbacks, tags and thread reach the child. An interrupt() raised inside the child (human approval) pauses the parent run and resumes with Command(resume=...) on the parent.

  3. Writes the final sub-graph state into state[output_key] as the plain JSON dict LangGraph produced, so the parent schema stays decoupled from the GOAP state and any parent checkpointer can persist it. Use langgoap.rehydrate_state() to get typed objects back.

The parent graph must declare input_key and output_key in its state schema (both are plain dict[str, Any] slots).

Parameters:
  • parent_builder (StateGraph) – The parent StateGraph under construction.

  • name (str) – Node name to register in the parent graph.

  • actions (list[ActionSpec]) – Actions for the sub-graph’s planner.

  • goal (GoalSpec) – Goal specification for the sub-graph.

  • input_key (str) – Parent-state key providing the initial world state. Defaults to "world_state".

  • output_key (str) – Parent-state key where the sub-graph’s final state will be stored. Defaults to "plan_result".

  • compile_kwargs (dict[str, Any] | None) – Optional GoapGraph.compile() options for the child (interrupt_before / interrupt_after; a checkpointer is normally inherited from the parent).

  • strategy (PlanningStrategy | None)

  • tracer (PlanningTracer | None)

  • history (StoreExecutionHistory | None)

  • sensors (list[Sensor | AsyncSensor] | None)

  • guards (list[ActionGuard | AsyncActionGuard] | None)

  • resolvers (list[ConditionResolver | AsyncConditionResolver] | None)

  • record_expansions (bool)

  • transition_model (TransitionModel | None)

  • rng (random.Random | None)

  • stuck_handlers (list[StuckHandler] | None)

  • max_stuck_iterations (int)

  • termination_policies (list[TerminationPolicy] | None)

  • executor (Literal['sequential', 'parallel'])

  • history_state (Literal['full', 'delta', 'planning'])

Return type:

None

:param : :param record_expansions: :param transition_model: :param rng: :param stuck_handlers: :param : :param max_stuck_iterations: Forwarded verbatim to

GoapGraph; see its docstring.

Parameters:
Return type:

None