-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent.py
66 lines (54 loc) · 1.95 KB
/
agent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
#!/usr/bin/env python
"""An abstract class that specifies the Agent API for RL-Glue-py.
"""
from __future__ import print_function
from abc import ABCMeta, abstractmethod
class BaseAgent:
"""Implements the agent for an RL-Glue environment.
Note:
agent_init, agent_start, agent_step, agent_end, agent_cleanup, and
agent_message are required methods.
"""
__metaclass__ = ABCMeta
def __init__(self):
pass
@abstractmethod
def agent_init(self, agent_info= {}):
"""Setup for the agent called when the experiment first starts."""
@abstractmethod
def agent_start(self, observation):
"""The first method called when the experiment starts, called after
the environment starts.
Args:
observation (Numpy array): the state observation from the environment's env_start function.
Returns:
The first action the agent takes.
"""
@abstractmethod
def agent_step(self, reward, observation):
"""A step taken by the agent.
Args:
reward (float): the reward received for taking the last action taken
observation (Numpy array): the state observation from the
environment's step based, where the agent ended up after the
last step
Returns:
The action the agent is taking.
"""
@abstractmethod
def agent_end(self, reward):
"""Run when the agent terminates.
Args:
reward (float): the reward the agent received for entering the terminal state.
"""
@abstractmethod
def agent_cleanup(self):
"""Cleanup done after the agent ends."""
@abstractmethod
def agent_message(self, message):
"""A function used to pass information from the agent to the experiment.
Args:
message: The message passed to the agent.
Returns:
The response (or answer) to the message.
"""