> This page is for version 0.4.0.
> For other versions, use one of these documentation indexes:
> - Main (default): https://docs.nvidia.com/nemo/gym/main/llms.txt
> - 0.7.0: https://docs.nvidia.com/nemo/gym/v0.7.0/llms.txt
> - 0.6.0: https://docs.nvidia.com/nemo/gym/v0.6.0/llms.txt
> - 0.5.1: https://docs.nvidia.com/nemo/gym/v0.5.1/llms.txt
> - 0.5.0: https://docs.nvidia.com/nemo/gym/v0.5.0/llms.txt
> - 0.4.0: https://docs.nvidia.com/nemo/gym/v0.4.0/llms.txt
> - 0.3.0: https://docs.nvidia.com/nemo/gym/v0.3.0/llms.txt
> - 0.2.1: https://docs.nvidia.com/nemo/gym/v0.2.1/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/gym/llms.txt.

# nemo_gym.agents.context_management.policies

Context-history policy protocols, registry, and built-in policies.

## Module Contents

### Classes

| Name                                                                                          | Description |
| --------------------------------------------------------------------------------------------- | ----------- |
| [`HistoryPolicy`](#nemo_gym-agents-context_management-policies-HistoryPolicy)                 | -           |
| [`IdentityHistoryPolicy`](#nemo_gym-agents-context_management-policies-IdentityHistoryPolicy) | -           |
| [`RecencyHistoryPolicy`](#nemo_gym-agents-context_management-policies-RecencyHistoryPolicy)   | -           |

### Functions

| Name                                                                                                  | Description                                                        |
| ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| [`build_history_policy`](#nemo_gym-agents-context_management-policies-build_history_policy)           | -                                                                  |
| [`register_history_policy`](#nemo_gym-agents-context_management-policies-register_history_policy)     | Register an agent-owned compaction policy factory.                 |
| [`unregister_history_policy`](#nemo_gym-agents-context_management-policies-unregister_history_policy) | Remove a custom policy registration, primarily for isolated tests. |

### Data

[`HistoryPolicyFactory`](#nemo_gym-agents-context_management-policies-HistoryPolicyFactory)

[`_CUSTOM_HISTORY_POLICY_FACTORIES`](#nemo_gym-agents-context_management-policies-_CUSTOM_HISTORY_POLICY_FACTORIES)

### API

```python
class nemo_gym.agents.context_management.policies.HistoryPolicy()
```

Protocol

**`name`** `str`

---

**`version`** `str`

---

```python
nemo_gym.agents.context_management.policies.HistoryPolicy.plan(
    history: 'SemanticHistory',
    decision_turn: int
) -> nemo_gym.agents.context_management.history.HistoryViewPlan
```

```python
class nemo_gym.agents.context_management.policies.IdentityHistoryPolicy()
```

**`name`** `= 'identity'`

---

**`version`** `= '1'`

---

```python
nemo_gym.agents.context_management.policies.IdentityHistoryPolicy.plan(
    history: nemo_gym.agents.context_management.history.SemanticHistory,
    decision_turn: int
) -> nemo_gym.agents.context_management.history.HistoryViewPlan
```

```python
class nemo_gym.agents.context_management.policies.RecencyHistoryPolicy(
    config: nemo_gym.agents.context_management.config.RecencyHistoryPolicyConfig
)
```

**`_config_dict`** `= config.model_dump(mode='json')`

---

**`_digest`**

---

**`name`** `= 'recency'`

---

**`version`** `= '3'`

---

```python
nemo_gym.agents.context_management.policies.RecencyHistoryPolicy.plan(
    history: nemo_gym.agents.context_management.history.SemanticHistory,
    decision_turn: int
) -> nemo_gym.agents.context_management.history.HistoryViewPlan
```

```python
nemo_gym.agents.context_management.policies.build_history_policy(
    config: nemo_gym.agents.context_management.config.HistoryPolicyConfig
) -> nemo_gym.agents.context_management.policies.HistoryPolicy
```

```python
nemo_gym.agents.context_management.policies.register_history_policy(
    name: str,
    factory: nemo_gym.agents.context_management.policies.HistoryPolicyFactory,
    replace_existing: bool = False
) -> None
```

Register an agent-owned compaction policy factory.

Custom policies receive their JSON-compatible configuration and return an
object implementing `HistoryPolicy`. Registration is process-local,
so an agent package can register its protocol during import without making
NeMo-Gym depend on that package.

```python
nemo_gym.agents.context_management.policies.unregister_history_policy(
    name: str
) -> None
```

Remove a custom policy registration, primarily for isolated tests.

```python
nemo_gym.agents.context_management.policies.HistoryPolicyFactory = Callable[[Mapping[str, Any]], HistoryPolicy]
```

```python
nemo_gym.agents.context_management.policies._CUSTOM_HISTORY_POLICY_FACTORIES: dict[str, HistoryPolicyFactory] = {}
```