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:
Reads
state[input_key]from the parent state.Invokes the sub-graph (
invokeunderparent.invoke,ainvokeunderparent.ainvoke) with a fresh JSON-native input carrying that world state and the configuredgoal, and with the parent’sRunnableConfig, so the parent’s checkpointer, callbacks, tags and thread reach the child. Aninterrupt()raised inside the child (human approval) pauses the parent run and resumes withCommand(resume=...)on the parent.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. Uselanggoap.rehydrate_state()to get typed objects back.
The parent graph must declare
input_keyandoutput_keyin its state schema (both are plaindict[str, Any]slots).- Parameters:
parent_builder (StateGraph) – The parent
StateGraphunder 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:
termination_policies (list[TerminationPolicy] | None) – Forwarded verbatim to
GoapGraph; see its docstring.executor (Literal['sequential', 'parallel']) – Forwarded verbatim to
GoapGraph; see its docstring.history_state (Literal['full', 'delta', 'planning']) – Forwarded verbatim to
GoapGraph; see its docstring.parent_builder (StateGraph)
name (str)
actions (list[ActionSpec])
goal (GoalSpec)
input_key (str)
output_key (str)
compile_kwargs (dict[str, Any] | None)
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)
- Return type:
None