
AI Shopkeeper NPCs: Merchants Who Haggle Back
Most game shops are a menu with a face on it: same prices, same greeting, whether the player saved the district or robbed the stall next door. With Neocortex, an AI shopkeeper NPC haggles in its own voice, notices what the player is carrying and how the last visit went, and returns actions your game runs, like a discount, a refusal or a look at the good stock.
What it looks like
Brassmoor is a canal city in an original gaslamp fantasy game, all fog, barges and pawn tickets. Ysolde Varn runs the Lamplighter's Exchange, a pawnshop wedged under a bridge. She is sharp, patient and impossible to rush, and she has a soft spot for anyone who can make her laugh.
The player walks in carrying a silver compass they lifted from the harbourmaster's office an hour ago. The game sends the player's inventory as metadata, and the compass carries a property that marks it as stolen. It also resumes the player's session with Ysolde, which still holds their last visit, when they tried to sell her a brass ring painted gold.
Player: I'll give you forty for the storm lantern. Ysolde: Forty, from the one who sold me painted brass. Sixty, and you show me what's in your coat. Player: It's just a compass. Ysolde: It's the harbourmaster's compass. I'll take it for twenty and forget I ever saw it.
While she talks, the reply carries a SHOW_WARES action pointed at the lantern shelf, so the game swings the camera to her best stock. When the player makes her laugh with a terrible excuse, the next reply comes back with OFFER_DISCOUNT on the lantern. If the player threatens her instead, she answers coldly, returns REFUSE_SALE, and the shop window closes.
Nobody scripted that haggle line by line. The writer gave Ysolde a personality, a price list, a strong dislike of liars and three actions, and the player's own behaviour did the rest.
How Neocortex makes it work
- Visual character design. Ysolde's personality, backstory, haggling style and voice live in the Neocortex visual node editor, and you can argue prices with her in the browser dashboard before you write any game code.
- Actions. You author
SHOW_WARES,OFFER_DISCOUNTandREFUSE_SALEas Action nodes on the character. Each reply lists which ones to run and on which target, such as the lantern's item ID, and your shop code runs them. - Metadata. The player's inventory goes in as entities with an ID, a name, a position and properties like value, condition or stolen, so she can name the compass and decide what it is worth to her.
- Session memory. Keep the returned
sessionIdfor each player and send it on their next visit. Resume the player's session and Ysolde picks up the thread, painted ring and all. - Events. Tell her what just happened in your world: "the player was caught stealing on Fen Street", "the city watch doubled its patrols". Her tone and her offers follow.
- Knowledge base. Upload her price list and item lore as a PDF or TXT document (1 upload on Free, 5 on Starter, 20 on Pro, 100 on Team), so her starting prices come from your economy rather than thin air.
- Emotions and voice. Every line arrives with an emotion tag your animation system can use, and streamed speech in her voice. Custom voices, cloned from a short sample or designed from a text description, are on Pro (5) and Team (20).
Ideas to build
The black-market fence. In a heist game, the fence only buys what is hot. Mark stolen goods in metadata and send the city's heat level as events. During a lockdown she pays half and wants the player gone fast, and a known informant gets REFUSE_SALE before he reaches the counter.
Rival merchants across the street. Two stallholders share one group chat (Pro and Team plans) and undercut each other out loud. Ask one for a price and the other shouts a lower one from across the lane. Buy from the rival, and the next exchange is all about that betrayal.
A survival trader who prices by scarcity. At the gate of a bunker in a post-collapse survival game, the trader reads the news before she reads the player. Send events like "the water purifier broke" or "a supply drop landed in the east", and her offers on filters and fuel shift with them, while your economy code keeps the final numbers in range.
A travelling merchant with opinions. His cart turns up in a different town each week. He refuses to deal with anyone wearing the colours of the guild that robbed him, which he spots in the player's equipped items, unless the player can talk him round.
Building it
AI shopkeepers work with the Unity SDK, the Unreal Engine plugin, the Godot addon (beta) and any engine or web game that can call the Web API. The loop is the same everywhere: send the player's line with their inventory and recent events, then run the actions that come back.
- Design the merchant in the visual editor: personality, how they haggle, what they can't stand, a voice and the actions they may return.
- Upload the price list to their knowledge base so they know what things are worth in your economy.
- Haggle in the dashboard until the character feels right, before touching game code.
- Send the player's inventory as metadata and recent world changes as events with each message.
- Store the
sessionIdfor each player and merchant pair, and send it on the next visit to resume the player's session. - Map each action to your shop: open the wares, apply a discount, close the window.
A haggling turn from any engine:
const res = await fetch("https://api.neocortex.link/v3/chat", {
method: "POST",
headers: {
"x-api-key": apiKey, // load from your own config, never hard-code it
"Content-Type": "application/json",
},
body: JSON.stringify({
characterIds: [ysolde],
message: playerLine,
sessionId: savedSessionId, // resume this player's session with her
playerId,
metadata: inventoryAsEntities(player), // your helper: id, name, position, properties
events: [{ priority: 1, content: "Lamp oil is scarce after the refinery fire" }],
}),
});
const { sessionId, messages } = await res.json();
for (const action of messages[0].actions) runShopAction(action); // your helperKeep the money in your code. Let the character decide that a discount is deserved, and let your economy decide how big it is, with a floor so a smooth talker can't walk out with the whole shop for a copper.
Shopkeepers are one of our AI NPC, ambient AI and voice command use cases. Pair them with AI quest giver NPCs for a town that trades and talks, or with NPCs that react to world events so prices follow the story. The smart NPCs page, the action system and the interactables docs cover the details. Start with one merchant and one item worth arguing over.
Checked October 2026.
Frequently Asked Questions
Can an AI shopkeeper NPC haggle with the player?
Yes. A Neocortex character answers the player's offers in its own words and personality, and each reply can return actions such as OFFER_DISCOUNT or REFUSE_SALE that your shop code runs, while your economy keeps control of the final price.
How does an AI merchant know what the player is carrying?
Your game sends the player's items as metadata with each message: an ID, a name, a position and properties like value or stolen. The Neocortex character can then name an item, price it and act on it.
Can an AI shopkeeper remember the player's last visit?
Within a session, yes. Neocortex returns a sessionId with every reply. Store it per player and send it on their next visit to resume the player's session, so the merchant picks up where the last conversation ended.
Do AI shopkeeper NPCs work in Unity and Unreal?
Yes. Neocortex has a Unity SDK, an Unreal Engine plugin with Blueprints and a Godot addon in beta, and any engine or web game can call the Neocortex Web API directly.
Written by
Neocortex
Date
Oct 24, 2026
Updated
Oct 24, 2026
Read time
6 min






