API Reference¶
Base Class¶
negmas_llm.LLMNegotiator
¶
Bases: SAONegotiator, ABC
A negotiator that uses an LLM for decision-making.
This negotiator delegates the negotiation strategy to a Large Language Model. It converts negotiation state to text, sends it to the LLM, and parses the response into negotiation actions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
str
|
The LLM provider (e.g., "openai", "anthropic", "ollama"). |
required |
model
|
str
|
The model name (e.g., "gpt-4", "claude-3-opus"). |
required |
api_key
|
str | None
|
API key for the provider (if required). |
None
|
api_base
|
str | None
|
Base URL for the API (useful for local deployments). |
None
|
temperature
|
float
|
Sampling temperature for the LLM. |
0.7
|
max_tokens
|
int
|
Maximum tokens in the LLM response. |
1024
|
system_prompt
|
str | None
|
Custom system prompt (overrides build_system_prompt). |
None
|
llm_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to litellm.completion. |
None
|
preferences
|
Preferences | None
|
The preferences of the negotiator. |
None
|
ufun
|
BaseUtilityFunction | None
|
The utility function (overrides preferences if given). |
None
|
name
|
str | None
|
Negotiator name. |
None
|
parent
|
Controller | None
|
Parent Controller if any. |
None
|
owner
|
Agent | None
|
The Agent that owns the negotiator. |
None
|
id
|
str | None
|
Unique ID for the negotiator. |
None
|
type_name
|
str | None
|
Type name string. |
None
|
can_propose
|
bool
|
Whether the negotiator can propose offers. |
True
|
**kwargs
|
Any
|
Additional arguments passed to SAONegotiator. |
{}
|
Source code in src/negmas_llm/negotiator.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 | |
Functions¶
__init__(provider, model, *, api_key=None, api_base=None, temperature=0.7, max_tokens=1024, system_prompt=None, llm_kwargs=None, preferences=None, ufun=None, name=None, parent=None, owner=None, id=None, type_name=None, can_propose=True, **kwargs)
¶
Source code in src/negmas_llm/negotiator.py
get_model_string()
¶
Get the model string for litellm.
Returns:
| Type | Description |
|---|---|
str
|
The full model string in litellm format (provider/model). |
format_outcome_space(state)
¶
Format the outcome space for the LLM.
Override this method to customize how the outcome space (negotiation issues and their possible values) is presented to the LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
SAOState
|
The current negotiation state. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string describing the outcome space, or empty string if unavailable. |
Source code in src/negmas_llm/negotiator.py
format_own_ufun(state)
¶
Format your own utility function for the LLM.
Override this method to customize how your utility function is presented to the LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
SAOState
|
The current negotiation state. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string describing your utility function, or a note if unavailable. |
Source code in src/negmas_llm/negotiator.py
format_partner_ufun(state)
¶
Format the partner's utility function for the LLM.
Override this method to customize how the partner's utility function (if known) is presented to the LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
SAOState
|
The current negotiation state. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string describing partner's utility function, or empty if unknown. |
Source code in src/negmas_llm/negotiator.py
format_nmi_info()
¶
Format the Negotiator Mechanism Interface (NMI) information.
The NMI contains metadata about the negotiation mechanism including time limits, step limits, number of possible outcomes, etc.
Override this method to customize how NMI info is presented to the LLM.
Returns:
| Type | Description |
|---|---|
str
|
A string describing the negotiation mechanism parameters. |
Source code in src/negmas_llm/negotiator.py
format_state(state, offer=None)
¶
Format the complete SAOState for the LLM.
This provides a comprehensive view of the current negotiation state including all relevant fields.
Override this method to customize how state is presented to the LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
SAOState
|
The current negotiation state. |
required |
offer
|
Outcome | None
|
The specific offer being responded to (may differ from current_offer). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A string describing the complete state. |
Source code in src/negmas_llm/negotiator.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
format_response_instructions()
¶
Format the response format instructions for the LLM.
Override this method to customize the expected response format.
Returns:
| Type | Description |
|---|---|
str
|
A string describing the expected JSON response format. |
Source code in src/negmas_llm/negotiator.py
build_system_prompt(state)
¶
Build the system prompt for the LLM.
This method combines the output of format_outcome_space(), format_nmi_info(), format_own_ufun(), format_partner_ufun(), and format_response_instructions() to create the full system prompt.
Override this method for complete control, or override the individual format_* methods to customize specific sections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
SAOState
|
The current negotiation state. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The system prompt string. |
Source code in src/negmas_llm/negotiator.py
build_user_message(state, offer, source)
¶
Build the user message describing the current negotiation state.
This method uses format_state() to provide comprehensive state information to the LLM for each round.
Override this method to customize how negotiation state is presented to the LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
SAOState
|
The current negotiation state. |
required |
offer
|
Outcome | None
|
The received offer (if any). |
required |
source
|
str | None
|
The ID of the negotiator who made the offer. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The user message string. |
Source code in src/negmas_llm/negotiator.py
counter(state, offer, source=None, dest=None)
¶
Generate a counter-offer using the LLM.
This method is called by the negotiation mechanism when this negotiator needs to respond to an offer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
SAOState
|
The current negotiation state. |
required |
offer
|
Outcome | None
|
The received offer (or None if this is the first proposal). |
required |
source
|
str | None
|
The ID of the negotiator who made the offer. |
None
|
dest
|
str | None
|
The ID of the destination negotiator. |
None
|
Returns:
| Type | Description |
|---|---|
SAOResponse
|
An SAOResponse containing the response type and optional counter-offer. |
Source code in src/negmas_llm/negotiator.py
propose(state, dest=None)
¶
Propose an offer using the LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
SAOState
|
The current negotiation state. |
required |
dest
|
str | None
|
The ID of the destination negotiator. |
None
|
Returns:
| Type | Description |
|---|---|
Outcome | ExtendedOutcome | None
|
The proposed outcome or None. |
Source code in src/negmas_llm/negotiator.py
respond(state, source=None)
¶
Respond to an offer using the LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
SAOState
|
The current negotiation state. |
required |
source
|
str | None
|
The ID of the negotiator who made the offer. |
None
|
Returns:
| Type | Description |
|---|---|
ResponseType
|
The response type. |
Source code in src/negmas_llm/negotiator.py
on_negotiation_start(state)
¶
Cloud Providers¶
OpenAI¶
negmas_llm.OpenAINegotiator
¶
Bases: LLMNegotiator
LLM Negotiator using OpenAI models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
OpenAI model name (default: "gpt-4o"). |
'gpt-4o'
|
api_key
|
str | None
|
OpenAI API key (uses OPENAI_API_KEY env var if not provided). |
None
|
**kwargs
|
Any
|
Additional arguments passed to LLMNegotiator. |
{}
|
Source code in src/negmas_llm/negotiator.py
Anthropic¶
negmas_llm.AnthropicNegotiator
¶
Bases: LLMNegotiator
LLM Negotiator using Anthropic Claude models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Anthropic model name (default: "claude-sonnet-4-20250514"). |
'claude-sonnet-4-20250514'
|
api_key
|
str | None
|
Anthropic API key (uses ANTHROPIC_API_KEY env var if not provided). |
None
|
**kwargs
|
Any
|
Additional arguments passed to LLMNegotiator. |
{}
|
Source code in src/negmas_llm/negotiator.py
Google Gemini¶
negmas_llm.GeminiNegotiator
¶
Bases: LLMNegotiator
LLM Negotiator using Google Gemini models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Gemini model name (default: "gemini-2.0-flash"). |
'gemini-2.0-flash'
|
api_key
|
str | None
|
Google API key (uses GOOGLE_API_KEY env var if not provided). |
None
|
**kwargs
|
Any
|
Additional arguments passed to LLMNegotiator. |
{}
|
Source code in src/negmas_llm/negotiator.py
Cohere¶
negmas_llm.CohereNegotiator
¶
Bases: LLMNegotiator
LLM Negotiator using Cohere models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Cohere model name (default: "command-r-plus"). |
'command-r-plus'
|
api_key
|
str | None
|
Cohere API key (uses COHERE_API_KEY env var if not provided). |
None
|
**kwargs
|
Any
|
Additional arguments passed to LLMNegotiator. |
{}
|
Source code in src/negmas_llm/negotiator.py
Mistral¶
negmas_llm.MistralNegotiator
¶
Bases: LLMNegotiator
LLM Negotiator using Mistral AI models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Mistral model name (default: "mistral-large-latest"). |
'mistral-large-latest'
|
api_key
|
str | None
|
Mistral API key (uses MISTRAL_API_KEY env var if not provided). |
None
|
**kwargs
|
Any
|
Additional arguments passed to LLMNegotiator. |
{}
|
Source code in src/negmas_llm/negotiator.py
Groq¶
negmas_llm.GroqNegotiator
¶
Bases: LLMNegotiator
LLM Negotiator using Groq-hosted models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Groq model name (default: "llama-3.3-70b-versatile"). |
'llama-3.3-70b-versatile'
|
api_key
|
str | None
|
Groq API key (uses GROQ_API_KEY env var if not provided). |
None
|
**kwargs
|
Any
|
Additional arguments passed to LLMNegotiator. |
{}
|
Source code in src/negmas_llm/negotiator.py
Together AI¶
negmas_llm.TogetherAINegotiator
¶
Bases: LLMNegotiator
LLM Negotiator using Together AI hosted models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Together AI model name (default: "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo"). |
'meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo'
|
api_key
|
str | None
|
Together AI API key (uses TOGETHER_API_KEY env var if not provided). |
None
|
**kwargs
|
Any
|
Additional arguments passed to LLMNegotiator. |
{}
|
Source code in src/negmas_llm/negotiator.py
Azure OpenAI¶
negmas_llm.AzureOpenAINegotiator
¶
Bases: LLMNegotiator
LLM Negotiator using Azure OpenAI Service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Azure deployment name. |
required |
api_key
|
str | None
|
Azure OpenAI API key. |
None
|
api_base
|
str | None
|
Azure OpenAI endpoint URL. |
None
|
api_version
|
str
|
Azure OpenAI API version (default: "2024-02-15-preview"). |
'2024-02-15-preview'
|
**kwargs
|
Any
|
Additional arguments passed to LLMNegotiator. |
{}
|
Source code in src/negmas_llm/negotiator.py
Functions¶
__init__(model, *, api_key=None, api_base=None, api_version='2024-02-15-preview', **kwargs)
¶
Source code in src/negmas_llm/negotiator.py
AWS Bedrock¶
negmas_llm.AWSBedrockNegotiator
¶
Bases: LLMNegotiator
LLM Negotiator using AWS Bedrock.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Bedrock model ID (default: "anthropic.claude-3-sonnet-20240229-v1:0"). |
'anthropic.claude-3-sonnet-20240229-v1:0'
|
aws_region
|
str
|
AWS region (default: "us-east-1"). |
'us-east-1'
|
**kwargs
|
Any
|
Additional arguments passed to LLMNegotiator. |
{}
|
Source code in src/negmas_llm/negotiator.py
Functions¶
__init__(model='anthropic.claude-3-sonnet-20240229-v1:0', *, aws_region='us-east-1', **kwargs)
¶
Source code in src/negmas_llm/negotiator.py
OpenRouter¶
negmas_llm.OpenRouterNegotiator
¶
Bases: LLMNegotiator
LLM Negotiator using OpenRouter API.
OpenRouter provides access to many models through a unified API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
OpenRouter model name (default: "openai/gpt-4o"). |
'openai/gpt-4o'
|
api_key
|
str | None
|
OpenRouter API key (uses OPENROUTER_API_KEY env var if not provided). |
None
|
**kwargs
|
Any
|
Additional arguments passed to LLMNegotiator. |
{}
|
Source code in src/negmas_llm/negotiator.py
DeepSeek¶
negmas_llm.DeepSeekNegotiator
¶
Bases: LLMNegotiator
LLM Negotiator using DeepSeek models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
DeepSeek model name (default: "deepseek-chat"). |
'deepseek-chat'
|
api_key
|
str | None
|
DeepSeek API key (uses DEEPSEEK_API_KEY env var if not provided). |
None
|
**kwargs
|
Any
|
Additional arguments passed to LLMNegotiator. |
{}
|
Source code in src/negmas_llm/negotiator.py
Hugging Face¶
negmas_llm.HuggingFaceNegotiator
¶
Bases: LLMNegotiator
LLM Negotiator using Hugging Face Inference API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Hugging Face model ID (default: "meta-llama/Llama-3.2-3B-Instruct"). |
'meta-llama/Llama-3.2-3B-Instruct'
|
api_key
|
str | None
|
Hugging Face API token (uses HF_TOKEN env var if not provided). |
None
|
**kwargs
|
Any
|
Additional arguments passed to LLMNegotiator. |
{}
|
Source code in src/negmas_llm/negotiator.py
Local Providers¶
Ollama¶
negmas_llm.OllamaNegotiator
¶
Bases: LLMNegotiator
LLM Negotiator using Ollama for local model inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Ollama model name (default: "llama3.2"). |
'llama3.2'
|
api_base
|
str
|
Ollama server URL (default: "http://localhost:11434"). |
'http://localhost:11434'
|
**kwargs
|
Any
|
Additional arguments passed to LLMNegotiator. |
{}
|
Source code in src/negmas_llm/negotiator.py
vLLM¶
negmas_llm.VLLMNegotiator
¶
Bases: LLMNegotiator
LLM Negotiator using vLLM server for local model inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model name as configured in vLLM. |
required |
api_base
|
str
|
vLLM server URL (default: "http://localhost:8000/v1"). |
'http://localhost:8000/v1'
|
**kwargs
|
Any
|
Additional arguments passed to LLMNegotiator. |
{}
|
Source code in src/negmas_llm/negotiator.py
LM Studio¶
negmas_llm.LMStudioNegotiator
¶
Bases: LLMNegotiator
LLM Negotiator using LM Studio for local model inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model name (default: "local-model"). |
'local-model'
|
api_base
|
str
|
LM Studio server URL (default: "http://localhost:1234/v1"). |
'http://localhost:1234/v1'
|
**kwargs
|
Any
|
Additional arguments passed to LLMNegotiator. |
{}
|
Source code in src/negmas_llm/negotiator.py
Text Generation WebUI¶
negmas_llm.TextGenWebUINegotiator
¶
Bases: LLMNegotiator
LLM Negotiator using text-generation-webui (oobabooga) server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model name. |
'local-model'
|
api_base
|
str
|
Server URL (default: "http://localhost:5000/v1"). |
'http://localhost:5000/v1'
|
**kwargs
|
Any
|
Additional arguments passed to LLMNegotiator. |
{}
|