AI Barter in a Two-Good Economy Part I
An Open Source AI Simulation Showing How Free Market Exchange Makes Us Better Off
Market economics makes life better for everyone by allowing everyone to make life better for themselves. The power of the free market is so pervasive that it's apparent even in the absence of currency. This shouldn't be too shocking, because barter is so natural that it predates written history. A caveman may have had all the pure water he could drink from a subterranean stream in his cave, yet have often hungered for the elusive but sweet taste of meat. Conversely, a hunter may have no shortage of game animals to eat but may find clean water more scarce.
It probably didn't take too many generations to learn that trying to overpower or kill one another for a desired resource is a bit short-sighted. Even if you manage to get what you want, fighting it out takes time and probably leads to injury when it doesn't kill you. Not only that, but after you've eliminated the competition you now have two tasks instead of just one—you have to gather the water and hunt for dinner. Those early economic actors who learned to trade gained the luxury of having to look over their shoulders less often, taking advantage of specialization, and potentially enjoying a market with many buyers and sellers of resources they'd never be able to accumulate on their own. It may all sound simple and obvious – and it is – but by studying the welfare-enhancing effects of such simple exchange economies, economists have been able to gain key insights into economic theory.
In this first post in a mini-series on this topic, we'll visualize how it works using artificial intelligence rather than cavemen. The use of AI adds some interesting angles because it sheds light not only on economic theory but on AI itself – answering questions like "Is this something AI can do yet?" and "Is this something AI can do for me better than I can?". The code behind this article is open source on the Poso Press GitHub, so feel free to copy, run it, change it, and follow along.
Utility and a Couple of Nerds Named Cobb and Douglas
The goal is to determine if the AIs are able to make themselves better off—which, again, is called increasing or maximizing their "utility". Utility is one of the flexible, situationally defined concepts in economics. In this and most cases, it is simply a variable that represents the benefit or satisfaction derived from having goods, which might be hard to describe or measure if we didn't have a concept like utility to cover it.
Since we need to be able to describe how much utility a person (or AI) gets from an arbitrary bundle of goods, we need to write functions to define it. Such functions are broadly called "utility functions" and, if we're talking about utility as pleasure or satisfaction derived from consuming the goods, then we might call that a "hedonic" utility function. There's no reason to believe that everyone's utility function will be the same. Your remote boss from Baltimore may love to have tickets to an Orioles baseball game, but would be mostly indifferent about seats at a Seattle Mariners game. If you're from Seattle, then your preferences for those tickets may be far different from your boss’ and you'd have to have different utility functions to represent your preferences accurately.
For this simulation—which it's called because we're simulating a tiny economy with just two people and two goods, for simplicity—we could make up any utility functions we like. It's useful to make some basic, realistic assumptions like having more of the goods is always preferable to having fewer (called "non-satiability" or “strict monotonicity”). When we start to have a whole lot of one of the two goods and very little of the other, the chances go up that we'd be willing to trade off more of our plentiful good to get some of the other. This assumption is called a diminishing marginal rate of substitutability or, if you're really into math plots, "convexity" (the latter term will be more clear in the next post on this topic when we talk about indifference curves and contract curves).
These and a few other basic assumptions for utility and production functions necessitate an appropriate functional form. The mathematician and economist Charles Cobb from Amherst University and his Quaker buddy Paul Douglas came up with just such a functional form, and it was all the roar of the late 1920s. Today we call it Cobb-Douglas and it's ubiquitous, as it gives us the above assumptions and a few other useful ones, represented as basic math. A Cobb-Douglas utility function looks something like this:
where U represents utility (measured in "utils"), x and y are quantities of our two goods, like Orioles and Mariners game tickets. α and β are variables whose values depend on how much you like each of those teams.
How the AI-based Simulation Works
Our simulation begins by defining a function that generates random Cobb-Douglas utility functions, which are then assigned to AI agents. Another function generates a random quantity of goods as the initial endowment for each agent, which they may use to trade with each other, in hopes of selfishly raising their utility. We generate multiple independent API connections to OpenAI, each representing a unique individual, then give them their epic system messages (a custom system message prompt, with dynamic content describing their utility functions) which lets them know that they're allowed to negotiate trades.
Instead of chatting with the AIs, our program manages the connections such that they speak to each other while we sit back and watch. They can stop voluntarily if they've determined that no other possible combination of goods they can get through negotiation will make them better off or, much more likely, when they've reached whatever maximum number of conversation turns we've set as the limit.
What We Learned
All that's left to do at this point is to look at our logs and see how things went. If the natural efficiency of a free market holds up, then both AI will have as much or more utility at the end of the experiment as they did at the beginning. It's a stellar outcome if you think about it. Greedy, self-interested exchanges improve everyone's quality of life. Nowhere to be seen is the heavy hand of government nor the harsh whip of socialism. Only the invisible hand of Capitalism.
Getting back to the questions we asked about AI, our experiment showed us that:
1. Yes, this is something that AI can already do—but just barely.
Plain conversation models, namely ChatGPT 4o and 4o-mini, didn't fare so well, although copious amounts of prompt engineering got them pretty close. Chain-of-thought models, in this case o3-mini and o4-mini, did much better. In many ways, finding this frontier of AI capability is the point. In an experiment like this, as opposed to the real-world, we have a known utility function. We could’ve written a much simpler program without the AI agents that makes trades based on precise utility calculations, but it would’ve been much less useful. The limited math and memory capabilities of the conversation models are AI equivalents of our own bounded rationality, making the experiment far richer. The initial failures of non-reasoning models like ChatGPT 4o show that all out breakdown of rationality can prevent improvements to economic efficiency from trade. On the other hand, imperfect rationality did not prevent the reasoning models from successful negotiations.
2. At this moment in history, a gold-standard reasoning model combined with carefully developed prompts is, at best, on par with what you could do for yourself.
Of course, it's also within a highly synthetic environment, with only two goods to consider, and wherein each consumer's utility can be perfectly described in an equation. For something more complicated and subjective, like trading baseball players themselves between teams, a human being might still outperform an AI, and certainly, the combination of human and AI judgment would likely outperform either in isolation.
3. Like humans, there are bounds to AI's rationality.
While its limitations are computational and statistical rather than psychological, the parallels make them relatable and should be a reminder to avoid over-reliance on agents as your perfect stand-in, especially when dealing with plain out-of-the-box models performing tasks for which they haven't been validated.
If you're new to this sort of thing, you may be surprised to know that the AI's main limitation was mathematics rather than the dialoguing or the art of the deal. Despite being the product of advanced math itself, LLMs are like English majors who gave so much of their attention to developing a broad understanding of vast amounts of material that they never became well-practiced at calculating figures or keeping track of data.
Of course, agentic systems can overcome that limitation by embedding the conversational AI inside environments with tools they can use, like programming sandboxes where they can write and run their scripts, or helper routines provided via software libraries like LangChain. Undoubtedly, over time your AI agent will become your best friend when trading baseball cards online or deciding which of your old junk to sell on eBay. Best of all, you'll know that when it's out pursuing your best interests, it's making the world a better place for everyone else too, as you can see in the plot below.
Check out the full code on GitHub: https://github.com/posocap/ai_barter_experiment