Getting "object has no attribute 'unwrapped'" when creating a custom multi agent environment

I am trying to create a custom multi agent environment, but get the following error:

Traceback (most recent call last):
  File "server.py", line 134, in <module>
    env = gym.make("rl_agent-v0")
  File "/home/aviskarkc10/.local/lib/python3.8/site-packages/gym/envs/registration.py", line 145, in make
    return registry.make(id, **kwargs)
  File "/home/aviskarkc10/.local/lib/python3.8/site-packages/gym/envs/registration.py", line 90, in make
    env = spec.make(**kwargs)
  File "/home/aviskarkc10/.local/lib/python3.8/site-packages/gym/envs/registration.py", line 65, in make
    env.unwrapped.spec = spec
AttributeError: 'RLAgent_v0' object has no attribute 'unwrapped'

This is more of an OpenAI gym internal error than an RLlib issue. Recommend posting a Git Issue on Issues · openai/gym · GitHub.

The agent works fine if I use the gym.Env subclass but it doesn’t when I use MultiAgentEnv subclass from rllib. So I was hoping I’d get some information here.

I have opened an issue in openai/gym GitHub repo as well. Thanks.

Hi @aviskarkc10,

Can you post an example script with what you are trying to do?

I followed this blog to create a custom environment:

I have defined my environment as follows:

from ray.rllib.env import MultiAgentEnv

class RLAgent_v0(MultiAgentEnv):

I register my environment as mentioned in the blog.

Then I try to create an instance of my environment using:

env = gym.make("rl_agent-v0")

This is where the error happens.

It works perfectly fine if I use the gym.Env subclass instead of MultiAgentEnv

The rllib defined environment classes (MultiagentEnv, RemoteEnv, VectorEnv) do not use the gym make interface. You just construct it manually. Something like:

env = RLAgent_v0(env_config)

Didn’t realize that. Thanks a lot.