# 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.thinking-machines-ai/cookbook/api-reference/renderers/message/)]_

_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.thinking-machines-ai/cookbook/api-reference/renderers/message/)_)

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

_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.thinking-machines-ai/cookbook/api-reference/rl/envfrommessageenv/) 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.thinking-machines-ai/cookbook/api-reference/renderers/message/)_)

**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.thinking-machines-ai/cookbook/api-reference/renderers/message/)]_)

**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.thinking-machines-ai/cookbook/api-reference/rl/envfrommessageenv/#envfrommessageenv-set_parse_error_policy)
- [tinker_cookbook.tool_use.AgentToolMessageEnv](https://tinker-docs.thinking-machines-ai/cookbook/api-reference/tool_use/agenttoolmessageenv/)

Back to top
