Skip to content

negmas-llm

LLM-based negotiators for the negmas negotiation framework

negmas-llm integrates Large Language Models with the negmas negotiation framework, enabling you to create negotiators that leverage LLMs for intelligent decision-making in automated negotiations.

Key Features

  • Multiple LLM Providers: Support for 16+ LLM providers through litellm, including OpenAI, Anthropic, Google Gemini, Cohere, Mistral, and local models via Ollama, vLLM, and more.

  • Seamless negmas Integration: LLMNegotiator extends SAONegotiator, making it fully compatible with existing negmas mechanisms and negotiation protocols.

  • Customizable Prompts: Override formatting methods to control exactly how negotiation information is presented to the LLM.

  • Rich Context: Automatically provides the LLM with outcome space, utility functions, negotiation mechanism parameters, and complete state information.

Quick Example

from negmas import SAOMechanism
from negmas.preferences import LinearAdditiveUtilityFunction
from negmas.outcomes import make_issue
from negmas_llm import OpenAINegotiator

# Define the negotiation space
issues = [
    make_issue("price", (0, 100)),
    make_issue("quantity", (1, 10)),
]

# Create negotiators with utility functions
seller = OpenAINegotiator(
    model="gpt-4o",
    name="seller",
    ufun=LinearAdditiveUtilityFunction(weights=[0.6, 0.4], issues=issues),
)
buyer = OpenAINegotiator(
    model="gpt-4o", 
    name="buyer",
    ufun=LinearAdditiveUtilityFunction(weights=[-0.6, 0.4], issues=issues),
)

# Run the negotiation
mechanism = SAOMechanism(outcome_space=issues, n_steps=20)
mechanism.add(seller)
mechanism.add(buyer)
result = mechanism.run()

print(f"Agreement: {result.agreement}")

How It Works

  1. System Prompt: At the start of negotiation, the LLM receives comprehensive context including:
  2. The outcome space (issues and their possible values)
  3. Mechanism parameters (time limits, step limits, etc.)
  4. Your utility function (what outcomes you prefer)
  5. Partner's utility function (if known)
  6. Response format instructions

  7. Per-Round Messages: Each negotiation round, the LLM receives:

  8. Complete negotiation state (step, timing, offers, acceptances)
  9. The current offer and its utilities for both parties
  10. Request for a JSON-formatted decision

  11. LLM Response: The LLM responds with a JSON object containing:

  12. response_type: "accept", "reject", or "end"
  13. outcome: Counter-offer values (if rejecting)
  14. text: Optional explanation
  15. data: Optional additional data

Installation

pip install negmas-llm

Next Steps