API Reference#

Every symbol below is re-exported from the top-level langgoap package (langgoap.__all__) and is the supported public surface. Anything not listed here is internal and may change without notice. langgoap.__version__ is the installed version string.

This page is generated by docs/generate_api_index.py from the grouping comments in langgoap/__init__.py; tests/test_docs_api_index.py fails when the two drift apart.

Package#

langgoap.set_log_level

Set the log level for all langgoap loggers.

Actions#

langgoap.ActionSpec

Specification of a GOAP action for planning.

langgoap.EffectFunction

langgoap.GoapAction

Base class for object-oriented GOAP action definitions.

langgoap.goap_action

Decorator that converts a function into an ActionSpec.

Conditions (three-valued logic + LLM-evaluated conditions)#

langgoap.AsyncConditionResolver

Asynchronous condition resolver — duck-typed protocol.

langgoap.ConditionResolver

Synchronous condition resolver — duck-typed protocol.

langgoap.ConditionStatus

Three-valued truth value for runtime condition resolution.

langgoap.FunctionalConditionResolver

Wrap a plain callable into a ConditionResolver.

langgoap.PromptConditionResolver

Resolve a condition key by querying an LLM.

langgoap.aresolve_conditions

Async variant of resolve_conditions().

langgoap.resolve_conditions

Run all resolvers against keys and return an updated world-state copy.

Goals#

langgoap.ConstraintSpec

A resource/budget constraint for CSP optimization.

langgoap.Goal

langgoap.GoalSpec

Specification of a GOAP goal.

langgoap.GoalPolicy

Replanning + multi-goal-priority policy for a GoalSpec.

langgoap.MultiGoal

A composite goal made up of one or more GoalSpec children.

langgoap.SoftGoal

An optional goal condition with a utility weight (oversubscription planning).

Constraint builder#

langgoap.BuilderOutput

Tagged bundle returned by ConstraintBuilder.build().

langgoap.ChainOutput

Output of a single terminated builder chain.

langgoap.ConstraintBuilder

Factory and aggregator for ConstraintChain instances.

langgoap.ConstraintChain

A single in-progress fluent chain.

Integrations (low-code LangGraph on-ramp)#

langgoap.EffectValidator

langgoap.create_goap_agent

Create a compiled GOAP agent from a list of LangChain tools and a goal.

langgoap.create_goap_tool

Create a LangChain BaseTool that runs a GOAP planning loop.

langgoap.create_goap_subagent

Create a CompiledSubAgent-compatible dict for DeepAgents.

langgoap.format_goap_result

Format a GoapState result dict as a compact human-readable report.

langgoap.goapify_tool

Wrap a LangChain BaseTool into a LangGOAP ActionSpec.

langgoap.GoapSubgraph

A GOAP planner packaged as a reusable sub-graph.

langgoap.add_goap_subgraph

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

langgoap.scaffold_deployment

Emit a deployable LangGraph directory for a LangGOAP agent.

Interpreter#

langgoap.GoalInterpreter

Converts natural language requests into GoalSpec objects via LLM.

langgoap.InterpretedConstraint

A resource constraint extracted from natural language.

langgoap.InterpretedGoal

Structured goal extracted from a natural language request.

langgoap.InterpretedObjective

An optimization objective extracted from natural language.

Graph#

langgoap.async_execute_action

Resolve and await the best async callable for action.

langgoap.GoapGraph

Builder that produces a compiled LangGraph for GOAP execution.

langgoap.GoapPlanner

LangGraph node that invokes the planner.

langgoap.GoapExecutor

LangGraph node that executes the current action in the plan.

langgoap.GoapObserver

LangGraph node that decides the next step via Command routing.

langgoap.ParallelGoapExecutor

LangGraph node that executes independent plan actions in parallel.

langgoap.GoapState

The GOAP execution state as Python objects.

langgoap.GoapResult

The state a run stopped in, with the questions people ask of it (issue #101).

langgoap.GoapStateChannels

LangGraph channel schema for the GOAP loop: the JSON-native state.

langgoap.ActionResult

Result of executing a single GOAP action.

langgoap.rehydrate_state

Return a copy of state with typed goal, plan and history.

langgoap.successful_action_names

Return names of successfully executed actions from a GOAP result.

Planning#

langgoap.PlanQualityMetric

Quality metric evaluated against a Plan's trajectory.

langgoap.MinimizeFinalStateExpression

Minimise expression evaluated on the final expected state.

langgoap.MinimizeTrajectorySum

Minimise the sum of expression over every expected state.

langgoap.MinimizeTrajectoryMax

Minimise the worst-case (maximum) value of expression.

langgoap.plan

Find an optimal action sequence from start to goal using A*.

langgoap.pipeline_plan

Two-phase planning: A* finds sequences, CSP validates/optimizes.

langgoap.Plan

A sequence of actions that achieves a goal from a given start state.

langgoap.PlanMetadata

Metadata about how a plan was generated.

langgoap.PlanningState

Immutable, hashable representation of a GOAP world state.

langgoap.infer_start_state

Build a clean-slate world state from action preconditions and effects.

Planning strategies#

langgoap.PlanningStrategy

A pluggable planning strategy.

langgoap.AStarStrategy

Pure A* construction heuristic.

langgoap.AnytimePlanningStrategy

Return the best plan found within a wall-clock time budget.

langgoap.CSPRefinementStrategy

Deprecated: call refine_with_csp() instead.

langgoap.refine_with_csp

Validate plan against goal's constraints and attach CSP scoring.

langgoap.LazyDecompositionStrategy

ADaPT-style incremental planning.

langgoap.MCTSStrategy

Monte Carlo Tree Search planning strategy.

langgoap.MCTSExploration

Search budget and exploration knobs for MCTSStrategy.

langgoap.MCTSReuseConfig

Tree-reuse and variable-depth selection config.

langgoap.MCTSTracingConfig

Observability config for MCTSStrategy.

langgoap.RepairStrategy

Plan-repair wrapper around any inner PlanningStrategy.

langgoap.RepairResult

Outcome of a plan-repair attempt.

langgoap.repair_plan

Repair a partially-executed plan by reusing its valid prefix.

langgoap.TwoPhasePipelineStrategy

A* construction + CSP refinement, composed as a single strategy.

langgoap.AgentModel

Predicts an external agent's next action given a world state.

langgoap.UniformRandomAgentModel

Baseline AgentModel that draws uniformly from a legal set.

langgoap.ScalarHeuristic

Continuous state-value function consumed by MCTS rollouts.

langgoap.RolloutPolicy

Pluggable rollout policy Protocol.

langgoap.RandomRollout

Baseline control condition — uniformly random applicable action.

langgoap.HeuristicRollout

Greedy rollout: pick the applicable action minimising h.

langgoap.StochasticRollout

Rollout policy that advances via a TransitionModel.

Utility (greedy) planner#

langgoap.NirvanaGoal

Marker goal that is never satisfied.

langgoap.UtilityStrategy

Greedy one-step utility planner.

langgoap.is_nirvana

Return True iff goal is a NirvanaGoal instance.

Constants:

  • langgoap.NIRVANA_NAME (str)

Router#

langgoap.ProblemFeatures

Cheap-to-compute routing features extracted at plan time.

langgoap.RuleBasedClassifier

Lexicographic classifier with conservative defaults.

langgoap.StrategyClassifier

Maps ProblemFeatures to a registered strategy name.

langgoap.StrategyRouter

Dispatches to a registered PlanningStrategy by name.

langgoap.extract_features

Extract routing features.

Transition models#

langgoap.DeterministicTransitionModel

Default model: expected and sample both equal the action's declared effects, regardless of RNG state.

langgoap.DivergencePolicy

Declared divergence between expected() and declared effects.

langgoap.TransitionModel

Separates action specs from world dynamics.

langgoap.assert_expected_matches_declared

Enforce the expected() / declared-effects contract.

Guards#

langgoap.ActionGuard

Synchronous action guard protocol.

langgoap.AsyncActionGuard

Asynchronous action guard protocol.

langgoap.FunctionalGuard

Wraps a callable into an ActionGuard.

langgoap.GuardResult

Immutable result returned by a guard check.

langgoap.GuardSeverity

Severity of a guard failure.

langgoap.has_blocking_failure

Return True if any result has passed=False with severity=BLOCK.

langgoap.run_guards_async

Run all guards concurrently via asyncio.gather().

langgoap.run_guards_sync

Run all synchronous guards and return all GuardResult objects.

LLM cost / token accounting#

langgoap.CostAccumulator

Accumulate LLM cost / tokens / call count into a world_state dict.

Constants:

  • langgoap.DEFAULT_COST_PER_1K_TOKENS (dict)

Action QoS / retry policy#

langgoap.ActionQos

Quality-of-service / retry policy for a single action.

Constants:

  • langgoap.DEFAULT_RETRY_POLICY (ActionQos)

  • langgoap.FIRE_ONCE (ActionQos)

Stuck-handler protocol#

langgoap.FunctionalStuckHandler

Adapter that turns a callable into a StuckHandler.

langgoap.MulticastStuckHandler

Composite handler that consults each child in order.

langgoap.StuckHandler

Recovery hook fired when the planner cannot find a plan.

langgoap.AsyncStuckHandler

Coroutine-based twin of StuckHandler (issue #53).

langgoap.StuckHandlerResult

Outcome of a stuck-handler invocation.

langgoap.StuckHandlingResultCode

Whether a handler resolved a stuck situation.

Early-termination policies#

langgoap.AllOfPolicy

Composite: terminate only when every child policy fires.

langgoap.EarlyTermination

Termination decision returned by a policy.

langgoap.FirstOfPolicy

Composite: terminate when any child policy fires.

langgoap.MaxActionsPolicy

Terminate after max_actions actions have been executed.

langgoap.MaxCostPolicy

Terminate when world_state['total_cost_usd'] exceeds usd.

langgoap.MaxLLMCallsPolicy

Terminate when world_state['llm_call_count'] exceeds max_calls.

langgoap.MaxTokensPolicy

Terminate when world_state['total_tokens'] exceeds tokens.

langgoap.MaxWallClockPolicy

Terminate after seconds of wall-clock time since the run started.

langgoap.OnStuckPolicy

Convert a no_plan status into a graceful termination.

langgoap.TerminationPolicy

Policy that decides whether the GOAP loop should terminate.

Scores#

langgoap.Score

Abstract base for all score types.

langgoap.SimpleScore

A single scalar score.

langgoap.HardSoftScore

A two-level score with hard and soft components.

langgoap.BendableScore

A variable-width score with any number of hard and soft levels.

CSP#

langgoap.CSPMetadata

Results from the CSP optimizer.

langgoap.CSPStatus

Status of a CSP solve attempt.

langgoap.ResourceUsage

Per-key resource breakdown for a plan.

langgoap.ScheduleEntry

Per-action temporal slot in a schedule.

langgoap.pareto_plans

Enumerate the Pareto-optimal subset of candidate plans.

Plan explanation#

langgoap.InfeasibilityExplanation

Explanation of why a plan is infeasible.

langgoap.NoPlanExplanation

Explanation of why A* could not find a valid plan.

langgoap.ResourceShortfall

A single resource that exceeds its constraint.

langgoap.explain_infeasibility

Analyze an INFEASIBLE plan and explain which constraints conflict.

langgoap.explain_no_plan

Explain why A* could not find a valid plan.

Types#

langgoap.CostFunction

Protocol for dynamic action cost functions.

langgoap.Maximize

Direction for numeric optimization objectives.

langgoap.Minimize

Direction for numeric optimization objectives.

langgoap.ObjectiveDirection

Direction for numeric optimization objectives.

langgoap.ReplanStrategy

When to trigger replanning during execution.

Visualization#

langgoap.render_mermaid

Render a Plan as a Mermaid flowchart TD diagram.

langgoap.render_mermaid_gantt

Render a Plan's schedule as a Mermaid gantt chart.

langgoap.render_dot

Render a Plan as a Graphviz DOT digraph.

langgoap.render_ascii

Render a Plan as a top-to-bottom ASCII tree.

langgoap.render_ascii_gantt

Render the plan's schedule as an ASCII Gantt chart.

langgoap.visualize

Render a Plan for display.

Tracing#

langgoap.SafeTracerProxy

Wrap a PlanningTracer so every hook call is exception-safe.

langgoap.PlanningTracer

Sync + async observability hooks for the GOAP planning loop.

langgoap.NullTracer

No-op tracer — the default when no tracer is configured.

langgoap.LoggingTracer

Tracer that routes every event through stdlib logging.

langgoap.MultiTracer

Fan a single event out to multiple tracers.

langgoap.LangSmithTracer

Emit GOAP planning events to LangSmith as a structured run tree.

langgoap.current_thread_id

The thread_id of the graph run this code is executing in, or None.

Execution history#

langgoap.ExecutionRecord

One planner → executor → observer loop outcome.

langgoap.StoreExecutionHistory

Execution history backed by a LangGraph BaseStore.

langgoap.compute_goal_hash

Return a stable short hash of a goal's conditions.

Sensors#

langgoap.Sensor

Reads external state into the world state before planning.

langgoap.AsyncSensor

Async variant of Sensor.

langgoap.FunctionalSensor

Convenience wrapper: construct a Sensor from a plain function.

langgoap.run_sensors_sync

Run all sensors synchronously and return (name, updates) pairs.

langgoap.run_sensors_async

Run all sensors asynchronously and return (name, updates) pairs.

Reflexion#

langgoap.Reflection

A verbal reflection on an execution failure.

langgoap.ReflexionTracer

Tracer that captures failures and generates verbal reflections.

Serde#

langgoap.LangGOAPSerializer

Deprecated no-op subclass of LangGraph's JsonPlusSerializer.

langgoap.install_langgoap_serde

Deprecated no-op: returns checkpointer unchanged.

Constants:

  • langgoap.LANGGOAP_ALLOWED_MSGPACK_TYPES (tuple)