# OnPolicyBatchReplay

## **OnPolicyBatchReplay**

Code: [slm\_lab/agent/memory/onpolicy.py](https://github.com/kengz/SLM-Lab/blob/master/slm_lab/agent/memory/onpolicy.py)

Sometimes for on-policy training, an agent trains at a fixed frequency, e.g. every 200 steps, instead of at the end of an episode. The signal for training also comes from the memory class in `memory.to_train`. For batched training schedule, OnPolicyBatchReplay extends OnPolicyReplay to set `self.to_train = true`  based on agent's training frequency and the number of experiences collected.

Suitable for on-policy algorithms.

### Source Documentation

Refer to the class documentation and example memory spec from the source: [slm\_lab/agent/memory/onpolicy.py#L100-L110](https://github.com/kengz/SLM-Lab/blob/master/slm_lab/agent/memory/onpolicy.py#L100-L110)

### **Example Memory Spec**

The spec for this memory has no parameters, since it automatically flushes at the end of a batch after training. The `batch_size` is the `training_frequency` provided by algorithm\_spec.

```javascript
{
    ...
    "agent": [{
      "memory": {
        "name": "OnPolicyBatchReplay"
      }
    }],
    ...
}
```

For more concrete examples of memory spec specific to algorithms, refer to the existing [spec files](https://github.com/kengz/SLM-Lab/tree/master/slm_lab/spec).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://slm-lab.gitbook.io/slm-lab/master/development/memory/episodic.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
