OneShotAgent

class scml.oneshot.OneShotAgent(owner=None, ufun=None, name=None)[source]

Bases: negmas.sao.controllers.SAOController, negmas.situated.situated.Entity, abc.ABC

Base class for all agents in the One-Shot game.

Parameters
  • owner – The adapter owning the agent. You do not need to directly deal with this.

  • ufun – An optional OneShotUFun to set for the agent.

  • name – Agent name.

Remarks:
  • You can access all of the negotiators associated with the agent using self.negotiators which is a dictionary mapping the negotiator_id to a tuple of two values: The SAONegotiator object and a key-value context dictionary. In 2021, the context will always be empty.

  • The negotiator_id associated with a negotiation with some partner will be the same as the agent ID of that partner. This means that all negotiators engaged with some partner over all simulation steps will have the same ID which is useful if you are keeping information about past negotiations and partner behavior.

Attributes Summary

awi

Returns a OneShotAWI object for accessing the simulation.

internal_state

Returns the internal state of the agent for debugging purposes.

running_negotiations

The negotiations currently requested by the agent.

unsigned_contracts

All contracts that are not yet signed.

Methods Summary

connect_to_2021_adapter(owner)

Connects the agent to its adapter (used internally)

connect_to_oneshot_adapter(owner)

Connects the agent to its adapter (used internally)

get_ami(partner_id)

Returns the SAOAMI (Agent Mechanism Interface) connecting the agent to the negotiation mechanism for the given partner.

get_negotiator(partner_id)

Returns the negotiator corresponding to the given partner ID.

init()

Called once after the AWI is set.

make_ufun([add_exogenous])

Creates a utility function for the agent.

on_contract_breached(contract, breaches, …)

rtype

None

on_contract_executed(contract)

rtype

None

on_negotiation_failure(partners, annotation, …)

Called whenever a negotiation ends without agreement.

on_negotiation_success(contract, mechanism)

Called whenever a negotiation ends with agreement.

propose(negotiator_id, state)

Proposes an offer to one of the partners.

respond(negotiator_id, state, offer)

Responds to an offer from one of the partners.

sign_all_contracts(contracts)

Signs all contracts (used internally)

step()

Called every step.

Attributes Documentation

awi

Returns a OneShotAWI object for accessing the simulation.

internal_state

Returns the internal state of the agent for debugging purposes.

Remarks:
  • In your agent, you can add any key-value pair to this dict and then use agent_log_* methods to log this information at any point.

Return type

Dict[str, Any]

running_negotiations

The negotiations currently requested by the agent.

Return type

List[RunningNegotiationInfo]

Returns

A list of negotiation information objects (RunningNegotiationInfo)

unsigned_contracts

All contracts that are not yet signed.

Return type

List[Contract]

Methods Documentation

connect_to_2021_adapter(owner)[source]

Connects the agent to its adapter (used internally)

connect_to_oneshot_adapter(owner)[source]

Connects the agent to its adapter (used internally)

get_ami(partner_id)[source]

Returns the SAOAMI (Agent Mechanism Interface) connecting the agent to the negotiation mechanism for the given partner.

Return type

SAOAMI

get_negotiator(partner_id)[source]

Returns the negotiator corresponding to the given partner ID.

Remarks:
  • Note that the negotiator ID and the partner ID are always the same.

Return type

SAONegotiator

init()[source]

Called once after the AWI is set.

Remarks:
  • Use this for any proactive initialization code.

make_ufun(add_exogenous=False)[source]

Creates a utility function for the agent.

Parameters

add_exogenous – If True then the exogenous contracts of the agent will be automatically added whenever the ufun is evaluated for any set of contracts, offers or otherwise.

Remarks:
  • You can always as assume that self.ufun returns the ufun for your. You will not need to directly use this method in most cases.

on_contract_breached(contract, breaches, resolution)[source]
Return type

None

on_contract_executed(contract)[source]
Return type

None

on_negotiation_failure(partners, annotation, mechanism, state)[source]

Called whenever a negotiation ends without agreement.

Parameters
  • partners (List[str]) – List of the partner IDs consisting from self and the opponent.

  • annotation (Dict[str, Any]) – The annotation of the negotiation including the seller ID, buyer ID, and the product.

  • mechanism (AgentMechanismInterface) – The AgentMechanismInterface instance containing all information about the negotiation.

  • state (MechanismState) – The final state of the negotiation of the type SAOState including the agreement if any.

Return type

None

on_negotiation_success(contract, mechanism)[source]

Called whenever a negotiation ends with agreement.

Parameters
  • contract (Contract) – The Contract agreed upon.

  • mechanism (AgentMechanismInterface) – The AgentMechanismInterface instance containing all information about the negotiation that led to the Contract if any.

Return type

None

abstract propose(negotiator_id, state)[source]

Proposes an offer to one of the partners.

Parameters
  • negotiator_id (str) – ID of the negotiator (and partner)

  • state (MechanismState) – Mechanism state including current step

Return type

Union[OutcomeType, Tuple[Union[int, float, str, list]], Dict[Union[int, str], Union[int, float, str, list]]]

Returns

an outcome to offer.

respond(negotiator_id, state, offer)[source]

Responds to an offer from one of the partners.

Parameters
Return type

ResponseType

Returns

A response type which can either be reject, accept, or end negotiation.

Remarks:

default behavior is to accept only if the current offer is the same or has a higher utility compared with what the agent would have proposed in the given state and reject otherwise

sign_all_contracts(contracts)[source]

Signs all contracts (used internally)

Return type

List[Optional[str]]

step()[source]

Called every step.

Remarks:
  • Use this for any proactive code that needs to be done every simulation step.