Cheat sheets

Negotiation, Simulation and Agent Economies

Contract Net, OG-Narrator bargaining, Smallville memory, Theory of Mind tests, Shapley credit and second-price auctions.

  • Concepts and terms
  • Tasks and commands
  • Annotated code
  • Diagrams
  • Defaults and numbers
  • Troubleshooting
  • Questions and tips

Source

Contract Net task market#

1Managerdecomposes the task into units.2Managerbroadcasts cfp with the task description toworkers.3Bidderreturns a propose with (price, eta, confidence),or a refuse.4Managerkeeps bids with price within budget and etawithin the deadline.5Managerpicks the max of conf/price and sendsaccept-proposal.6Managersends reject-proposal to the losers. They bid onother tasks.

Negotiation mechanisms#

OG-Narrator
a deterministic offer generator computes the price. The LLM only narrates.
Offer generator
Rubinstein bargaining, Zeuthen strategy or tit-for-tat over price.
Rule
let the LLM narrate. Do not let the LLM compute the offer.
Structured proposal
the LLM drafts it. Validate it against a schema before you send.
CoT concealment
winners compute strategy privately. The public channel shows the offer only.
Persona manipulation
a desperation persona gives about 20% more payoff.

Bargaining in code#

state = BargainState(buyer_max=buyer_max, seller_min=seller_min)
og_narrator_bargain(state, rng, concession=0.35)buyer offer
seller_response(state, rng, concession=0.3)seller counter
move = max(1, int(concession * (state.seller_offer - prior)))
candidate = min(candidate, state.buyer_max)never past own max
naive_llm_bargain(state, rng)high variance, often outside ZOPA
bench_deal_rate(buyer_fn, label, trials=1000)deal rate in percent
winner = max(feasible, key=lambda b: b.confidence / max(b.price, 1))

Generative agent loop#

observescoreimportant memoriesreflection entrytop-ktickclientObservationinvitation from aneighborstoreMemory streamappend-only logprocessRetrievaltop-k by combinedscoremodelReflectionnew belief backinto the streammodelPlanday, hour, actionprocessActmove to HobbsCafeobservescoreimportant memoriesreflection entrytop-ktickclientObservationinvitation froma neighborstoreMemory streamappend-only logprocessRetrievaltop-k bycombined scoremodelReflectionnew belief backinto the streammodelPlanday, hour,actionprocessActmove toHobbsCafe

Memory retrieval#

top = retrieve_top_k(stream, query="party cafe", tick=4, k=3)
recency = math.exp(-0.3 * (tick - m.ts))exponential decay by age
importance = m.importance / 10.0self-rated 1 to 10
relevance = 0.6 if any(w in m.content.lower() for w in query.lower().split()) else 0.1
score = recency + importance + relevancesorted, keep [:k]
a.reflect(tick)importance >= 6 in the last 5 ticks
a.update_plan(tick)belief adds Plan(tick=5, where="HobbsCafe")
action = a.act(tick)move when the plan tick arrives

Theory of Mind and coordination#

Zeroth-order
no model of others. The agent acts on its own observations only.
First-order
a model of each other agent's beliefs. "Alice believes X."
Second-order
recursive beliefs. "Alice believes that Bob believes X."
ToM state
the other_models attribute. Keep it as {agent_id: belief_list}.
Riedl metrics
identity-linked differentiation, goal-directed complementarity, higher-order synergy.
Real signals
complementarity over time, anticipation and correction by turn T+2.
Demo
run_trial(n_agents, n_boxes, tom, seed, max_turns=10) counts duplications.

Economy mechanisms in code#

TaskCode
Exact Shapley, small Nshapley_exact(value_fn, agents)
Sampled Shapleyshapley_sampled(value_fn, agents, samples, rng)
Truthful auctionsecond_price(bids)
Winner payspayment = sorted_bids[1].value
Reputation storeReputation(alpha=0.95, floor=0.1)
Update after a taskrep.update(agent, quality)
Route by reputationweighted_choice(agents, rep.weights(agents), rng)

Run the demos#

CommandWhat it does
python3 code/main.py in 16-16Naive LLM ~65-75% deals, OG-Narrator ~85-95%
python3 code/main.py in 16-173 of 5 agents converge at the party
python3 code/main.py in 16-18ToM duplicates ~5%, zeroth-order ~35%
python3 code/main.py in 16-21Rep routing gives 10-20% quality gain

Defaults in the lesson code#

SettingDefaultNote
max_rounds5Bargaining rounds per trial
Buyer concession0.35Seller uses 0.3
Bargain trials1000ToM bench uses 200
Retrieval k3Top-k memories in the prompt
Reflection trigger150Sum of importance of unprocessed memories
max_turns10ToM token-collection budget
alpha0.95Reputation decay
floor0.1Lowest reputation score

Numbers to remember#

OG-Narrator
deal rate from 26.67% to 88.88%.
Competition
~180k negotiations. Concealing agents won.
Symmetric pairs
inequitable outcomes on about 40% of scenarios.
Smallville
25 agents. 24 had no knowledge of the party.
Shapley cost
N=3 has 6 permutations. N=10 has 3.6M.
Shapley sampling
100-1000 orderings.

Failure modes#

SymptomCauseFix
Offers outside the ZOPALLM computes the priceDeterministic offer generator
Counterpart knows your limitReservation price in a visible traceSeparate private scratchpad
Agents enter closed storesSpatial norm errorsDetect norm violations explicitly
Retrieval cost growsMemory overflowSummarize-and-prune, decay low importance
Invented relationshipsReflection hallucinationPut source memory ids in the prompt
Coordination only in demosPrompt dressing, no controlControl condition and p < 0.05
Belief bound to wrong agentLong horizon, context limitsExplicit or external ToM store
One operator inflates creditSybil attackDIDs and reputation cost-to-forge

Questions#

Does a larger model bargain better?
No. It writes better language with similar strategic error.
Why does Contract Net scale past 100 workers?
It is broadcast-and-respond, not synchronous chat.
Which Smallville part can you drop?
None. Each ablation hurts believability.
Why second-price?
Under monotone aggregation, agents bid their true value.
When do agent economies make sense?
Open networks, verifiable outputs, long-horizon work.

Ship checklist#

  • Bound bargaining to 3-5 rounds. Escalate to a mediator on deadlock.
  • Reject out-of-ZOPA offers at the protocol boundary.
  • Memory is append-only. Corrections are new entries.
  • Log the top-k memories that drove each action.
  • Start with reputation, not tokens.
  • Verify before you reward.