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.
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 iteration step of the simulation.
- Raises
NotImplementedError – If not overridden in subclass.
See also
-
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 toconnections[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
toconnections
.- 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 askedartifact (object) – artifact to be evaluated
- Returns
agent’s evaluation of the artifact
- Return type
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.
-
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
-
async
random_connection
()[source]¶ Connect to random agent from current
connections
.- Returns
aiomas.Proxy
object for the connected agent.
-
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.