TLDR: State-Inference-Based Prompting (SIBP) is a new methodology that enables Large Language Models (LLMs) to handle rule-governed trading interactions in games reliably. It achieves this by allowing LLMs to autonomously infer dialogue states and adhere to context-specific rules, preventing common issues like item hallucinations and calculation errors. SIBP decomposes trading into six states, uses dynamic item referencing, and employs placeholder-based price calculations, demonstrating high compliance, accuracy, and precision in evaluations, making LLM-driven NPCs practical for commercial games.
Large Language Models (LLMs) are transforming how non-player characters (NPCs) interact with players in video games, moving beyond rigid scripts to offer more natural and dynamic conversations. However, these advanced AI models often struggle with rule-governed systems, especially in complex scenarios like in-game trading. Common issues include NPCs ‘hallucinating’ items that don’t exist, mismanaging inventory, and making calculation errors, which can quickly erode a player’s trust and break immersion.
To address these challenges, researchers have introduced a new approach called State-Inference-Based Prompting (SIBP). This method allows LLMs to reliably handle trading interactions by autonomously inferring the current state of a dialogue and adhering to specific rules based on that context. SIBP breaks down the trading process into six distinct states within a unified prompting framework, ensuring that NPCs respond appropriately at each stage of a transaction.
How SIBP Works
The core idea behind SIBP is to enable LLMs to understand “what situation is happening right now?” solely from the ongoing dialogue. The system defines three main situational contexts:
- NONE (general conversation): For casual chats, like discussing weather or monsters.
- TRADE (trading conversation): For commercial interactions, such as buying or selling items.
- END_CONVERSATION (conversation ending): For phrases that signal the end of a chat, like “Goodbye.”
Within the TRADE context, SIBP further refines the interaction into five sub-states to manage the complexities of buying and selling:
- SHOW_INVENTORY: The NPC displays items available for sale.
- OFFER_SELL: The NPC proposes selling specific items and states their price.
- NEGOTIATE_PRICE: The player attempts to haggle, and the NPC responds based on their personality.
- CHECK_CONFIRMATION: The NPC seeks final confirmation before completing a purchase, preventing accidental transactions.
- CONFIRM_SELL: The player confirms the purchase, leading to the final update of game data.
These states are not strictly linear; players can dynamically switch contexts, and the LLM is designed to infer these changes and adapt its responses accordingly. For instance, a player might ask for a price, then try to negotiate, or even switch to a casual conversation mid-trade.
Key Prompt Design Elements
SIBP employs four crucial elements in its prompt design to guide the LLM:
- Basic State Definitions: Clearly outlines what each trading state represents and the appropriate actions within it.
- State Transition Conditions with Previous Context: Defines the prerequisites for entering each state, emphasizing how the previous state influences the current one. This helps prevent confusion and ensures necessary steps, like confirmation, are not skipped.
- Directive to Identify Previous State: Instructs the LLM to explicitly recognize the last trading state from the dialogue history before formulating a response.
- Directive to Respond including Previous State: Requires the LLM to document its identified previous state in its output, making the AI’s reasoning transparent and aiding in debugging.
Enhanced Functionalities
SIBP also incorporates state-specific rules for better game integration:
- State-specific Data Referencing: NPCs reference different datasets based on the conversation context. In general conversation (NONE state), they can discuss all game items. However, during trading (TRADE state), they only reference items actually in their inventory. This prevents item hallucinations and ensures accurate transactions.
- State-specific Post-processing: To overcome LLMs’ occasional struggles with precise arithmetic, SIBP uses a clever trick. In the OFFER_SELL state, the LLM is instructed to use a placeholder like “__PRICE__” for the total amount. The system then accurately calculates the price based on the item details provided by the LLM and replaces the placeholder with the correct number. This ensures 99.7% calculation precision without adding computational overhead.
Also Read:
- Bridging the Social Gap: How New AI Models Learn Human-Like Interaction
- Exploring the New Frontier of Generative Recommendations with Large Language Models
Empirical Validation
Evaluations across 100 trading dialogues demonstrated SIBP’s effectiveness. The system achieved over 97% state compliance, meaning NPCs correctly followed the defined dialogue flow, including the crucial confirmation step before finalizing purchases. Item referencing accuracy was over 95%, ensuring NPCs only discussed and offered items they actually possessed. The placeholder-based post-processing resulted in 99.7% calculation precision, a significant improvement over basic LLM calculations.
These results highlight SIBP’s ability to create practical and trustworthy NPC interactions in commercial games, bridging the gap between the flexibility of natural language and the strict requirements of game systems. The methodology maintains computational efficiency and even allows smaller LLMs to achieve accuracy comparable to larger, more resource-intensive models when combined with post-processing.
For more technical details, you can refer to the full research paper: State-Inference-Based Prompting for Natural Language Trading with Game NPCs.


