# How to define an action space when an agent can take multiple sub-actions in a step?

I'm attempting to design an action space in OpenAI's gym and hitting the following roadblock. I've looked at this post which is closely related but subtly different.

The environment I'm writing needs to allow an agent to make between $$1$$ and $$n$$ sub-actions in each step. Leaving it up to the agent to decide how many sub-actions it wants to take. So, something like (sub-action-category, sub-action-id, action) where the agent can specify between $$1$$ and $$n$$ such tuples.

It doesn't seem possible to define a Box space without specifying bounds on the shape which is what I need here. I'm trying to avoid defining an action space where each sub-action is explicitly enumerated by the environment like (action) tuple with n entries for each sub-action.

Are there any other spaces I could use to dynamically scale the space?

• Is the last element of the tuple (sub-action-category, sub-action-id, action) a discrete or continuous value? What is its dimension? gym offers the class MultiDiscrete for a similar use case. You could also write your own action type if you wanted to, but imo the straightest way to deal with this is to have actions to be instances of some suitably defined Python class you can document etc. and deal with the details of the execution to the Environment subclass. Feb 19, 2020 at 9:51

## 1 Answer

One way to handle an arbitrarily large sequence is by adding a STOP signal as one possible token in the sequence, just like LSTM.

So you could divide your game in turns:

• What you now call a single action (composed by multiple sub-actions) would become a turn.
• Now, you can have as many actions you'd like inside a turn.
• Each action is simply a list accumulated inside the environment, but won't evaluate the game yet.
• When the player is satisfied with their actions, they can call the action: "End Turn".
• When turn ends, you can concatenate every sub-actions, evaluate the game and proceed as usual.