Define GBNF grammar for constrained game-command decoding #968

Closed
opened 2026-03-22 18:45:50 +00:00 by perplexity · 0 comments
Collaborator

Parent

  • #963 — [Study] Solving the Perception Bottleneck

Objective

Create a GBNF grammar file that constrains LLM output to valid Morrowind game commands, eliminating parsing failures and hallucinated actions.

Scope

  • Write morrowind_commands.gbnf grammar covering:
    • move_to <target> — navigation commands
    • interact <object/npc> — interaction
    • attack <target> — combat
    • use_item <item> — item usage
    • cast_spell <spell> [target] — magic
    • wait <duration> — idle/rest
    • dialogue_choose <option_index> — conversation choices
    • navigate_menu <action> — UI navigation
  • Integrate grammar loading: load_gbnf("morrowind_commands.gbnf")
  • Pass grammar to all LLM .generate() calls via grammar=self.command_grammar
  • Ensure compatibility with both llama.cpp and MLX backends
  • Test: verify 100% of LLM outputs parse into valid commands

Key Design Notes

  • GBNF constrains token generation at decode time — no post-processing needed
  • max_tokens=40 is sufficient for any single command
  • Grammar should be extensible as new command types are added

References

  • Paper §GBNF Grammar (pp. 8-9)
  • Paper §Heartbeat Loop Pseudocode (pp. 16-17)
## Parent - #963 — [Study] Solving the Perception Bottleneck ## Objective Create a GBNF grammar file that constrains LLM output to valid Morrowind game commands, eliminating parsing failures and hallucinated actions. ## Scope - Write `morrowind_commands.gbnf` grammar covering: - `move_to <target>` — navigation commands - `interact <object/npc>` — interaction - `attack <target>` — combat - `use_item <item>` — item usage - `cast_spell <spell> [target]` — magic - `wait <duration>` — idle/rest - `dialogue_choose <option_index>` — conversation choices - `navigate_menu <action>` — UI navigation - Integrate grammar loading: `load_gbnf("morrowind_commands.gbnf")` - Pass grammar to all LLM `.generate()` calls via `grammar=self.command_grammar` - Ensure compatibility with both llama.cpp and MLX backends - Test: verify 100% of LLM outputs parse into valid commands ## Key Design Notes - GBNF constrains token generation at decode time — no post-processing needed - `max_tokens=40` is sufficient for any single command - Grammar should be extensible as new command types are added ## References - Paper §GBNF Grammar (pp. 8-9) - Paper §Heartbeat Loop Pseudocode (pp. 16-17)
claude was assigned by Rockachopa 2026-03-22 23:30:50 +00:00
claude added the harnessmorrowindp1-important labels 2026-03-23 13:54:07 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#968