Hierarchical, Symbolic, Language, and Multi-Agent Planning › Worked example: language-conditioned goals

Michael BrenndoerferJuly 12, 20264 min read
World Models HandbookAll chapters
Part 7 of 12Planning and Agency
Chapter 42Hierarchical, Symbolic, Language, and Multi-Agent Planning › Worked example: language-conditioned goals
Reading section 8 of 13 · Worked example: language-conditioned goals · 4 minSection 8 of 13 · 4 min

Book contents

Section 8 of 13 · 4 min read

Hierarchical, Symbolic, Language, and Multi-Agent Planning › Worked example: language-conditioned goalsOne section · Sections in this chapter8 / 13 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

The final layer maps a small set of instructions to goal predicates. This hand-written grounder accepts a state argument for the interface but does not use it to choose a goal; its accepted mappings are context-insensitive. It requires the relevant object token and rejects negation rather than silently reversing its meaning.

In[16]:
Code
def ground_instruction(text, state):
    """Map fixed token patterns to goals; state appears only in error text."""
    punctuation = str.maketrans("", "", ".,!?;:")
    tokens = set(text.lower().translate(punctuation).split())
    if tokens & {"not", "never", "don't", "dont"}:
        raise ValueError("Negated instructions are outside this toy grammar.")
    if {"key", "goal"}.issubset(tokens) and tokens & {"get", "reach"}:
        return frozenset({"has_key", "at_goal"})
    if "key" in tokens and tokens & {"get", "take"}:
        return frozenset({"has_key"})
    if "door" in tokens and tokens & {"unlock", "open"}:
        return frozenset({"door_open"})
    if "goal" in tokens and tokens & {"reach", "go"}:
        return frozenset({"at_goal"})
    raise ValueError(f"Could not ground instruction in state {state}: {text!r}")


INSTRUCTIONS = [
    "Get the key.",
    "Unlock the door.",
    "Reach the goal.",
    "Get the key, then reach the goal.",
]
grounded_goals = {
    text: ground_instruction(text, INITIAL_ENV) for text in INSTRUCTIONS
}

rejected = []
for text in ["Open the window.", "Unlock the phone.", "Do not open the door."]:
    try:
        ground_instruction(text, INITIAL_ENV)
    except ValueError:
        rejected.append(text)
assert len(rejected) == 3
assert ground_instruction("Get the key.", INITIAL_ENV) == ground_instruction(
    "Get the key.", manual_final
)
Out[17]:
Console
'Get the key.' -> ['has_key']
'Unlock the door.' -> ['door_open']
'Reach the goal.' -> ['at_goal']
'Get the key, then reach the goal.' -> ['at_goal', 'has_key']
Rejected off-target or negated instructions: 3
Grounded symbolic plan: ['navigate_to_key', 'navigate_to_door', 'unlock_door', 'navigate_to_goal']
Executed option calls: ['go_to_key', 'go_to_door', 'unlock_door', 'go_to_goal']
Instruction satisfied in environment: True

The word “then” is not represented by the unordered goal set. In this domain, operator preconditions independently force key acquisition before the goal can be reached. A general procedure grounder would need to emit explicit ordering constraints, while a context-sensitive goal grounder would need to use the supplied state. The example therefore demonstrates a fixed-vocabulary goal interface, not unrestricted language understanding.

Out[18]:
Visualization
Four rounded boxes show the actual instruction, grounded predicates, symbolic operator plan, and successful option execution, connected by arrows.
Computed instruction-to-action chain for the toy task. A context-insensitive token grounder maps the instruction to goal predicates, symbolic BFS selects four operators, the binding dispatches four options, and execution reaches a state satisfying the goal. Each displayed value comes from the preceding code.

Every link remains a potential failure point: grounding can select the wrong goal, symbolic effects can be inaccurate, and an option can fail despite valid preconditions. The end-to-end assertion proves only this deterministic toy instance; it does not turn any learned component into a verifier.