Agent

Agent module holds CreativeAgent implementation, a subclass of aiomas.Agent, which holds basic functionality thought to be shared by creative agents.

class creamas.core.agent.CreativeAgent(environment, resources=0, name=None, log_folder=None, log_level=10)[source]

Base class for all creative agents.

All agents share certain common attributes:

Variables
  • env – The environment where the agent lives.

  • max_res (int) – Agent’s resources per step, 0 if agent has unlimited resources.

  • cur_res (int) – Agent’s current resources.

  • A (list) – Artifacts the agent has created so far

  • D (dict) – Domain knowledge, other agents’ artifacts seen by this agent

  • connections (list) – Dictionary of other agents this agent knows

  • name (str) – Name of the agent. Defaults to the address of the agent.

async act(*args, **kwargs)[source]

Trigger agent to act.

This is a dummy method which should be overridden in a subclass.

This function serves as the main function for the simulations, and is called for each agent on each step of the simulation.

See also

trigger_all()

add_artifact(artifact)[source]

Add artifact to A.

Raises

TypeError – If the artifact is not derived from Artifact.

add_connection(addr, **kwargs)[source]

Add an agent with given address to current connections with given information.

Does nothing if address is already in connections. Given **kwargs are stored as key-value pairs to connections[addr] dictionary.

Parameters

addr (str) – Address of the agent to be added

Returns

True if the agent was successfully added, False otherwise.

add_connections(conns)[source]

Add agents from conns to connections.

Parameters

conns (list) – A list of (addr, kwargs)-tuples

Returns

A boolean list, as returned by add_connections().

async ask_opinion(addr, artifact)[source]

Ask an agent’s opinion about an artifact.

Parameters
  • addr (CreativeAgent) – Address of the agent which opinion is asked

  • artifact (object) – artifact to be evaluated

Returns

agent’s evaluation of the artifact

Return type

float

This is a shortcut to:

remote_agent = await self.env.connect(addr)
opinion = await remote_agent.evaluate(artifact)

Note

The artifact object should be serializable by the environment.

clear_connections()[source]

Clear all connections from the agent.

close(folder=None)[source]

Perform any bookkeeping needed before closing the agent.

This is a dummy method which should be overridden in a subclass.

Parameters

folder (str) – Folder where the agent should save its data.

async connect(addr)[source]

Connect to agent in given address using the agent’s environment.

This is a shortcut to connect().

Returns

aiomas.Proxy object for the connected agent.

evaluate(artifact)[source]

Evaluate an artifact.

This is a dummy method which should be overridden in a subclass.

get_connections(data=False)[source]

Get agent’s current connections.

Parameters

data (bool) – Also return the data dictionary for each connection.

Returns

A list of agent addresses or a dictionary

publish(artifact)[source]

Publish artifact to agent’s environment.

Parameters

artifact (Artifact) – artifact to be published

qualname()[source]

Get qualified name of this class.

async random_connection()[source]

Connect to random agent from current connections.

Returns

aiomas.Proxy object for the connected agent.

refill()[source]

Refill agent’s resources to maximum.

remove_connection(addr)[source]

Remove agent with given address from current connections.

sanitized_name()[source]

Sanitized name of the agent, used for file and directory creation.

property A

Artifacts created so far by the agent.

property D

Domain knowledge accumulated by this agent.

Dictionary of agents and their artifacts.

property connections

Known other agents

The connections has a dict-in-a-dict data type able to hold arbitrary information about known other agents. The keys in the dictionary are agent addresses and values are dictionaries holding information relating to the key-agent.

property cur_res

Agent’s current resources. Capped to maximum resources.

property env

The environment where the agent lives. Must be a subclass of Environment.

property logger

A logger for the agent.

The logger should be derived from ObjectLogger.

property max_res

Maximum resources for the agent per simulation iteration act.

If max_res == 0, agent has unlimited resources. If maximum resources are set below current resources, current resources are capped to new maximum resources.

property name

The name of the agent.

The agent should not change its name during its lifetime.