Agent

class textworld.gym.core.Agent[source]

Bases: object

Interface for any agent playing TextWorld games.

act(obs, score, done, infos)[source]

Acts upon the current list of observations.

One text command must be returned for each observation.

Parameters:
  • obs (str) – Previous command’s feedback (game’s narrative).
  • score (int) – The score obtained so far.
  • done (bool) – Whether the game is finished.
  • infos (Mapping[str, Any]) – Additional information requested.
Return type:

str

Returns:

Text command to be performed. If episode has ended (i.e. done is True), the returned value is expected to be ignored.

infos_to_request

Returns what additional information should be made available at each game step.

Requested information will be included within the infos dictionary passed to Agent.act(). To request specific information, create a textworld.EnvInfos and set its attributes to True accordingly.

In addition to the standard information, certain games may have specific information that can be requested via the extras attribute. Refer to the documentation specific to the game to know more (see textworld.challenges).

Example

Here is an example of how to request information and retrieve it.

>>> from textworld import EnvInfos
>>> request_infos = EnvInfos(description=True, inventory=True)
...
>>> env = gym.make(env_id)
>>> ob, infos = env.reset()
>>> print(infos["description"])
>>> print(infos["inventory"])
Return type:EnvInfos