# tf_agents.policies.py_tf_eager_policy.PyTFEagerPolicyBase

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/policies/py_tf_eager_policy.py#L38-L121) |

Base class for py_policy instances of TF policies in Eager mode.

Inherits From: [`PyPolicy`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/policies/py_policy/PyPolicy)

    tf_agents.policies.py_tf_eager_policy.PyTFEagerPolicyBase(
        policy: https://www.tensorflow.org/agents/api_docs/python/tf_agents/policies/TFPolicy,
        time_step_spec: https://www.tensorflow.org/agents/api_docs/python/tf_agents/trajectories/TimeStep,
        action_spec: https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types/NestedArraySpec,
        policy_state_spec: https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types/NestedArraySpec,
        info_spec: https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types/NestedArraySpec,
        use_tf_function: bool = False,
        batch_time_steps=True
    )

Handles adding and removing batch dimensions from the actions and time_steps.
Note if you have a tf_policy you should directly use the PyTFEagerPolicy class
instead of this Base.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `policy` | [`tf_policy.TFPolicy`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/policies/TFPolicy) instance to wrap and expose as a py_policy. |
| `time_step_spec` | A `TimeStep` ArraySpec of the expected time_steps. Usually provided by the user to the subclass. |
| `action_spec` | A nest of BoundedArraySpec representing the actions. Usually provided by the user to the subclass. |
| `policy_state_spec` | A nest of ArraySpec representing the policy state. Provided by the subclass, not directly by the user. |
| `info_spec` | A nest of ArraySpec representing the policy info. Provided by the subclass, not directly by the user. |
| `use_tf_function` | Wraps the use of `policy.action` in a tf.function call which can help speed up execution. |
| `batch_time_steps` | Wether time_steps should be batched before being passed to the wrapped policy. Leave as True unless you are dealing with a batched environment, in which case you want to skip the batching as that dim will already be present. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `action_spec` | Describes the ArraySpecs of the np.Array returned by `action()`. <br /> `action` can be a single np.Array, or a nested dict, list or tuple of np.Array. |
| `collect_data_spec` | Describes the data collected when using this policy with an environment. |
| `info_spec` | Describes the Arrays emitted as info by `action()`. |
| `observation_and_action_constraint_splitter` | <br /> <br /> |
| `policy_state_spec` | Describes the arrays expected by functions with `policy_state` as input. |
| `policy_step_spec` | Describes the output of `action()`. |
| `time_step_spec` | Describes the `TimeStep` np.Arrays expected by `action(time_step)`. |
| `trajectory_spec` | Describes the data collected when using this policy with an environment. |

<br />

## Methods

### `action`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/policies/py_policy.py#L147-L169)

    action(
        time_step: https://www.tensorflow.org/agents/api_docs/python/tf_agents/trajectories/TimeStep,
        policy_state: https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types/NestedArray = (),
        seed: Optional[types.Seed] = None
    ) -> https://www.tensorflow.org/agents/api_docs/python/tf_agents/trajectories/PolicyStep

Generates next action given the time_step and policy_state.

<br />

<br />

<br />

| Args ||
|---|---|
| `time_step` | A `TimeStep` tuple corresponding to `time_step_spec()`. |
| `policy_state` | An optional previous policy_state. |
| `seed` | Seed to use if action uses sampling (optional). |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A PolicyStep named tuple containing: `action`: A nest of action Arrays matching the `action_spec()`. `state`: A nest of policy states to be fed into the next call to action. `info`: Optional side information such as action log probabilities. ||

<br />

### `get_initial_state`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/policies/py_policy.py#L134-L145)

    get_initial_state(
        batch_size: Optional[int] = None
    ) -> https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types/NestedArray

Returns an initial state usable by the policy.

<br />

<br />

<br />

| Args ||
|---|---|
| `batch_size` | An optional batch size. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| An initial policy state. ||

<br />

### `variables`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/policies/py_tf_eager_policy.py#L87-L88)

    variables()