# tinker_cookbook.rl.EnvFromMessageEnv

## _class_ [**tinker_cookbook.rl.EnvFromMessageEnv**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L84)( _types. [Env](https://tinker-docs.thinking-machines-ai/cookbook/api-reference/rl/env/)_)

Adapter that wraps a MessageEnv to implement the token-level Env interface.

This bridges the message-level abstraction to the token-level interface expected by the RL training loop.

### [**step**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L172)( _action_, _extra_)

Parse tokens to a message, delegate to MessageEnv, and render response.

**Parameters:**

- [**action**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L173) ( _types.Action_)
- [**extra**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L173) ( _types. [ActionExtra](https://tinker-docs.thinking-machines-ai/cookbook/api-reference/rl/actionextra/) \| None_)

**Returns:** _types. [StepResult](https://tinker-docs.thinking-machines-ai/cookbook/api-reference/rl/stepresult/)_

### [**set_parse_error_policy**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L284)( _policy_)

Apply a rollout-level parse-error policy (seam used by the rollout runner: the narrow method interface through which it pushes configuration into the env).

Configures this adapter's structural-failure handling and forwards the policy to the inner [`MessageEnv`](https://tinker-docs.thinking-machines-ai/cookbook/api-reference/rl/messageenv/) when it supports one (content failures — unparsable tool calls — are handled there).

**Parameters:**

- [**policy**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L284) ( _ParseErrorPolicy_)

**Returns:** _None_

### [**inject_messages**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L343)( _messages_)

Inject externally supplied messages before the next sampling call.

Seam used by rollout hooks (`on_turn_begin`). Forwards to the inner `MessageEnv.add_messages` and re-renders the conversation, so injected tokens count toward any trajectory budget.

**Parameters:**

- [**messages**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L344) ( _list\[ [Message](https://tinker-docs.thinking-machines-ai/cookbook/api-reference/renderers/message/)\] _)

**Returns:** _tuple\[tinker. [ModelInput](https://tinker-docs.thinking-machines-ai/tinker/api-reference/types/modelinput/), StopCondition\]_

**Raises:**

- TypeError: If the inner :class:`MessageEnv` does not support message injection.

### [**set_max_tool_calls**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L365)( _max_tool_calls_)

Forward a rollout-level tool-call limit to the inner MessageEnv.

Seam used by the rollout runner for `RolloutLimits.max_tool_calls` (tool dispatch happens inside the message env, so the runner cannot enforce it directly). Logs a warning when the inner env does not support a tool-call limit, in which case the limit is not enforced.

**Parameters:**

- [**max_tool_calls**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L365) ( _int_)

**Returns:** _None_

## Referenced by

- [tinker_cookbook.rl.MessageEnv.observe_truncated_response](https://tinker-docs.thinking-machines-ai/cookbook/api-reference/rl/messageenv/#messageenv-observe_truncated_response)
