mlpy.agents.Agent

class mlpy.agents.Agent(mid=None, module_type=None, task=None, *args, **kwargs)[source]

Bases: mlpy.modules.Module

The agent base class.

Agents act in an environment (Environment) usually performing a task (Task). Depending on the agent module they either follow a policy (FollowPolicyModule), are user controlled via the keyboard or a PS2 controller (UserModule), or learn according to a learner (LearningModule). New agent modules can be created by inheriting from the IAgentModule class.

Parameters:

mid : str, optional

The agent’s unique identifier.

module_type : str

The agent module type, which is the name of the class.

task: Task

The task the agent must complete.

args: tuple

Positional parameters passed to the agent module.

kwargs: dict

Non-positional parameters passed to the agent module.

Examples

>>> from mlpy.agents import Agent
>>> Agent(module_type='learningmodule', learner_type='qlearner', max_steps=10)
>>> Agent(None, 'learningmodule', None, 'qlearner', max_steps=10)

This creates an agent with a LearningModule agent module that performs qlearning. The parameters are given in the order in which the objects are created. Internally the agent creates the learning agent module and the learning agent module creates the qlearner.

Alternatively, non-positional arguments can be used:

>>> Agent(module_type='learningmodule', learner_type='qlearner', max_steps=10)
>>> from mlpy.experiments.task import Task
>>> task = Task()
>>> Agent(None, 'learningmodule', task, 'qlearner', max_steps=10)

This creates an agent that performs the given task. If a task is given, the method Task.get_reward is passed as the reward callback to the learning module to retrieve the reward. By default Task.get_reward returns None.

Attributes

mid The module’s unique identifier.
module The agent module controlling the actions of the agent.
task The task the agent is to perform.

Methods

enter(t) Enter the agent and the agent module.
exit() Exit the agent and the agent module.
is_task_complete() Check if the agent’s task is completed.
load(filename) Load the state of the module from file.
reset(t, **kwargs) Reset the agent’s state.
save(filename) Save the current state of the module to file.
update(dt) Update the agent and the agent module.