-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Feature: Implement a Generalized Exchange and Negotiation System
Labels: feature, epic, research, social-science, economics, agent-engine
Opened: 2025-07-14
1. Overview & Motivation
To elevate ARLA into a truly generalizable platform for computational social science, we need to implement a foundational primitive for all forms of social and economic interaction: exchange. This moves beyond single-purpose systems (like a hardcoded "trade" or "barter" system) to a powerful, abstract ExchangeSystem that can model a vast range of phenomena, from simple resource trades to complex, multi-step negotiations and even the exchange of intangible social goods.
This system will be the bedrock for future research into:
- Economics: Barter, fixed-price markets, and auctions.
- Game Theory: The ultimatum game, prisoner's dilemma, and recursive negotiations.
- Social Psychology: The dynamics of reciprocity, trust, and social capital.
2. Detailed Architectural Plan
This new system will be implemented within the agent-engine to be reusable across all simulations.
New Core Component (agent-core/components.py)
-
NegotiationComponent(Component): Attached to agents to track the state of their ongoing exchanges.active_negotiations: Dict[str, Negotiation](A dictionary mapping a uniquenegotiation_idto a state object).
-
Negotiation(dataclass): A simple data structure to hold the state of a single negotiation.negotiation_id: strinitiator_id: strreceiver_id: stroffer: Dict[str, Any](What the initiator is giving up, e.g.,{"resource.wood": 10}). The key should be a string that can be resolved to a specific component and attribute.ask: Dict[str, Any](What the initiator wants in return, e.g.,{"resource.stone": 5}).status: str(An enum:PENDING,COUNTERED,ACCEPTED,REJECTED,COMPLETED,FAILED,TIMED_OUT).history: List[Tuple[str, Dict]](A log of offers and counter-offers).last_update_tick: int(To track for timeouts).
New Core Actions (agent-core/actions/)
ProposeExchangeAction(ActionInterface): The primary action to start any transaction.- Params:
{"target_agent_id": str, "offer": Dict, "ask": Dict}.
- Params:
RespondToOfferAction(ActionInterface): Used to continue a negotiation.- Params:
{"negotiation_id": str, "response": str, "counter_offer": Optional[Dict], "counter_ask": Optional[Dict]}. Theresponsecan beaccept,reject, orcounter.
- Params:
New Core System (agent-engine/systems/)
ExchangeSystem(System): The engine that orchestrates all negotiations and transactions.- Listens for
ProposeExchangeActionandRespondToOfferActionevents. - Initiates: When an agent proposes an exchange, the system creates a
Negotiationobject, validates that the initiator actually possesses the offered goods, and adds theNegotiationto theNegotiationComponentof both participating agents. It then notifies the receiving agent. - Mediates: It processes responses. If an offer is
countered, it validates the counter-offer and updates theNegotiationstate, notifying the original initiator. - Executes: If an offer is
accepted, theExchangeSystemperforms the actual transfer. This is the critical part: it will modify the components of both agents (e.g., deduct from one agent'sInventoryComponentand add to the other's). For abstract goods, it might modify aRelationalSchemain theSocialMemoryComponent. - Terminates: It cleans up the
Negotiationobject from the components once the exchange iscompleted,rejected,failed, ortimed_out.
- Listens for
3. Edge Cases and Considerations
A robust ExchangeSystem must handle numerous edge cases:
- Transaction Atomicity: What if Agent A agrees to give wood for stone from Agent B, but by the time the deal is executed, Agent B has spent their stone? The system must perform a final validation check immediately before the transfer. If either party cannot fulfill their side, the
Negotiationstatus must be set toFAILED, and both parties should be notified. No partial transfers should occur. - Asynchronous Responses & Timeouts: Agents may not respond immediately. The
ExchangeSystem'supdatemethod should periodically scan all active negotiations. Ifcurrent_tick - last_update_tickexceeds a configurable threshold (e.g.,negotiation_timeout_ticks), the negotiation's status should be set toTIMED_OUTand terminated. - Resource/State Validation: The system must have a robust way to parse the
offerandaskdictionaries (e.g.,"resource.wood") and map them to the correct component (InventoryComponent) and attribute (wood) on the agent entity. It must check for both existence and sufficient quantity before initiating or executing a trade. - Intangible Goods: For exchanges involving abstract concepts (e.g., offer: "information", ask: "increase_trust"), the
ExchangeSystemwill need a way to apply these effects. This could be done by publishing a genericapply_social_effectevent that other systems (like theIdentitySystemorSocialMemorySystem) can listen for. The event payload would include the target agent and the effect to be applied (e.g.,{"effect": "increase_trust", "value": 0.5}). - Concurrent Offers: What happens if Agent A makes an offer to Agent B, and while B is deciding, Agent C makes a better offer? The current design handles this naturally. Agent B will have two separate
Negotiationobjects in itsNegotiationComponent. Its decision-making logic will have to choose whichRespondToOfferActionto execute. It can accept one and reject (or ignore) the other.
4. Phased Implementation Plan
-
Phase 1: Core Data Structures & Actions
- Implement
NegotiationComponentand theNegotiationdataclass inagent-core. - Implement
ProposeExchangeActionandRespondToOfferActioninagent-core.
- Implement
-
Phase 2: "Happy Path" System Logic
- Implement the
ExchangeSysteminagent-engine. - Implement the logic to handle
ProposeExchangeAction: create theNegotiationobject and notify the receiver. - Implement the logic to handle an
acceptresponse fromRespondToOfferAction, including the final validation and execution of the transfer for simple numerical resources.
- Implement the
-
Phase 3: Edge Case and Negotiation Logic
- Add logic to handle
rejectandcounterresponses. - Implement the timeout mechanism in the
ExchangeSystem'supdatemethod. - Implement the atomic transaction logic to prevent partial trades.
- Add logic to handle
-
Phase 4: Integration and Testing
- Integrate the new components and actions into the
soul-simScenarioLoaderfor a subset of agents. - Write unit tests for the
ExchangeSystemcovering all edge cases. - Run a test simulation in
soul-simwhere agents can successfully barter for different types of resources.
- Integrate the new components and actions into the
5. Updated Definition of Done
- All new components and actions are defined and implemented in
agent-core. - The
ExchangeSystemis implemented inagent-engineand handles the full lifecycle of a negotiation (propose, accept, reject, counter, timeout, fail, complete). - The system can successfully mediate a simple resource-for-resource trade between two agents in the
soul-simenvironment. - Unit tests for the
ExchangeSystemexist and provide high coverage, including for all identified edge cases. - The system is designed with a clear path to supporting abstract/social exchanges.