# tinker_cookbook.rl.MessageEnv ## *class* [**tinker_cookbook.rl.MessageEnv**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L39)(*ABC*) Abstract base class for message-level environments. ### [**initial_observation**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L43)() Return the initial conversation history as renderer messages. **Returns:** *list\[[Message](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/renderers/message/index.md)\]* *Abstract method.* ### [**step**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L48)(*message*) Process an assistant message and return reward/next state. **Parameters:** - [**message**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L48) (*[Message](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/renderers/message/index.md)*) **Returns:** *[MessageStepResult](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/rl/messagestepresult/index.md)* *Abstract method.* ### [**observe_truncated_response**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L52)(*message*) Record a truncated assistant response without running a full step. Used by the continue-past-truncation path (the sampler hit the per-turn `max_tokens` cap, `stop_reason == "length"`, and [`EnvFromMessageEnv`](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/rl/envfrommessageenv/index.md) has `terminate_on_length=False`): the truncated message is appended to the conversation as-is (no tool execution, no completion check) so the rollout can continue on the next turn. **Parameters:** - [**message**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L52) (*[Message](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/renderers/message/index.md)*) **Returns:** list[Message] | None: The updated message history, or `None` if this environment does not support recording truncated responses (the default), in which case the caller falls back to the default terminate-on-length behavior. ### [**add_messages**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L70)(*messages*) Append externally injected messages to the conversation. Used by rollout hooks (`on_turn_begin`) to inject messages before a sampling call. **Parameters:** - [**messages**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/message_env.py#L70) (*list\[[Message](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/renderers/message/index.md)\]*) **Returns:** list[Message] | None: The updated message history, or `None` if this environment does not support message injection (the default). ## Referenced by - [tinker_cookbook.rl.EnvFromMessageEnv.set_parse_error_policy](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/rl/envfrommessageenv/#envfrommessageenv-set_parse_error_policy) - [tinker_cookbook.tool_use.AgentToolMessageEnv](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/tool_use/agenttoolmessageenv/index.md)