# `vllm_mlx.reasoning.base`

Base classes for reasoning content extraction.

[View the complete module source at #L1-L126](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/base.py#L1-L126).

## API details

Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.

::: vllm_mlx.reasoning.base
    options:
      members:
        - DeltaMessage
        - ReasoningParser
      filters: []
      show_if_no_docstring: true

## Complete contract reference

Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.

<details class="api-contract" id="contract-vllm_mlx.reasoning.base.DeltaMessage" markdown="1">
<summary><code>vllm_mlx.reasoning.base.DeltaMessage</code> · class</summary>

```python
vllm_mlx.reasoning.base.DeltaMessage(role: str | None = None, content: str | None = None, reasoning: str | None = None)
```

Delta message for streaming reasoning output.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `role` | `str \| None` | `no` | `None` | Optional constructor field; defaults to `None`. |
| `content` | `str \| None` | `no` | `None` | Optional constructor field; defaults to `None`. |
| `reasoning` | `str \| None` | `no` | `None` | Optional constructor field; defaults to `None`. |

**Returns**

- Constructs: `vllm_mlx.reasoning.base.DeltaMessage`

**Exceptions and behavior**

Class `DeltaMessage` declares 1 direct member(s).
No direct `raise` statement appears in this definition.

[View source #L15-L33](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/base.py#L15-L33).

</details>

<details class="api-contract" id="contract-vllm_mlx.reasoning.base.DeltaMessage.reasoning_content" markdown="1">
<summary><code>vllm_mlx.reasoning.base.DeltaMessage.reasoning_content</code> · method</summary>

```python
vllm_mlx.reasoning.base.DeltaMessage.reasoning_content() -> str | None
```

Deprecated: use reasoning instead.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `str | None`
- Direct return expressions: `self.reasoning`

**Exceptions and behavior**

Method `DeltaMessage.reasoning_content` returns `self.reasoning`.
No direct `raise` statement appears in this definition.

[View source #L31-L33](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/base.py#L31-L33).

</details>

<details class="api-contract" id="contract-vllm_mlx.reasoning.base.ReasoningParser" markdown="1">
<summary><code>vllm_mlx.reasoning.base.ReasoningParser</code> · class</summary>

```python
vllm_mlx.reasoning.base.ReasoningParser(tokenizer: Any | None = None)
```

Abstract base class for reasoning content extraction.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `tokenizer` | `Any \| None` | `no` | `None` | Optional tokenizer for token-based parsing. For vllm-mlx, text-based parsing is sufficient, so this is optional. |

**Returns**

- Constructs: `vllm_mlx.reasoning.base.ReasoningParser`

**Exceptions and behavior**

Class `ReasoningParser` derives from `ABC` and declares 5 direct member(s).
No direct `raise` statement appears in this definition.

[View source #L36-L126](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/base.py#L36-L126).

</details>

<details class="api-contract" id="contract-vllm_mlx.reasoning.base.ReasoningParser.__init__" markdown="1">
<summary><code>vllm_mlx.reasoning.base.ReasoningParser.__init__</code> · method</summary>

```python
vllm_mlx.reasoning.base.ReasoningParser.__init__(tokenizer: Any | None = None) -> not annotated
```

Initialize parser with optional tokenizer.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `tokenizer` | `Any \| None` | `no` | `None` | Optional tokenizer for token-based parsing. For vllm-mlx, text-based parsing is sufficient, so this is optional. |

**Returns**

- Type: `not annotated`

**Exceptions and behavior**

Method `ReasoningParser.__init__` updates `self.tokenizer`.
No direct `raise` statement appears in this definition.

[View source #L49-L57](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/base.py#L49-L57).

</details>

<details class="api-contract" id="contract-vllm_mlx.reasoning.base.ReasoningParser.extract_reasoning" markdown="1">
<summary><code>vllm_mlx.reasoning.base.ReasoningParser.extract_reasoning</code> · method</summary>

```python
vllm_mlx.reasoning.base.ReasoningParser.extract_reasoning(model_output: str) -> tuple[str | None, str | None]
```

Extract reasoning content from complete model output.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `model_output` | `str` | `yes` | `none` | Complete text output from the model. |

**Returns**

- Type: `tuple[str | None, str | None]`

**Exceptions and behavior**

Method `ReasoningParser.extract_reasoning` contains no state mutation, call, raise, return, await, or yield.
No direct `raise` statement appears in this definition.

[View source #L60-L74](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/base.py#L60-L74).

</details>

<details class="api-contract" id="contract-vllm_mlx.reasoning.base.ReasoningParser.extract_reasoning_streaming" markdown="1">
<summary><code>vllm_mlx.reasoning.base.ReasoningParser.extract_reasoning_streaming</code> · method</summary>

```python
vllm_mlx.reasoning.base.ReasoningParser.extract_reasoning_streaming(previous_text: str, current_text: str, delta_text: str) -> DeltaMessage | None
```

Extract reasoning from streaming delta.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `previous_text` | `str` | `yes` | `none` | Accumulated text before this delta. |
| `current_text` | `str` | `yes` | `none` | Accumulated text including this delta. |
| `delta_text` | `str` | `yes` | `none` | The new text in this streaming chunk. |

**Returns**

- Type: `DeltaMessage | None`

**Exceptions and behavior**

Method `ReasoningParser.extract_reasoning_streaming` contains no state mutation, call, raise, return, await, or yield.
No direct `raise` statement appears in this definition.

[View source #L77-L100](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/base.py#L77-L100).

</details>

<details class="api-contract" id="contract-vllm_mlx.reasoning.base.ReasoningParser.reset_state" markdown="1">
<summary><code>vllm_mlx.reasoning.base.ReasoningParser.reset_state</code> · method</summary>

```python
vllm_mlx.reasoning.base.ReasoningParser.reset_state() -> not annotated
```

Reset any internal state for a new request.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `not annotated`

**Exceptions and behavior**

Method `ReasoningParser.reset_state` contains no state mutation, call, raise, return, await, or yield.
No direct `raise` statement appears in this definition.

[View source #L102-L110](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/base.py#L102-L110).

</details>

<details class="api-contract" id="contract-vllm_mlx.reasoning.base.ReasoningParser.finalize_stream" markdown="1">
<summary><code>vllm_mlx.reasoning.base.ReasoningParser.finalize_stream</code> · method</summary>

```python
vllm_mlx.reasoning.base.ReasoningParser.finalize_stream() -> DeltaMessage | None
```

Finalize streaming state at end of stream.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `DeltaMessage | None`
- Direct return expressions: `None`

**Exceptions and behavior**

Method `ReasoningParser.finalize_stream` returns `None`.
No direct `raise` statement appears in this definition.

[View source #L112-L126](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/base.py#L112-L126).

</details>

## Complete symbol map

This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.

| Symbol | Kind | Signature and inputs | What it does | Source |
| --- | --- | --- | --- | --- |
| [`DeltaMessage`](#contract-vllm_mlx.reasoning.base.DeltaMessage) | class | `DeltaMessage(role: str \| None = None, content: str \| None = None, reasoning: str \| None = None)` | Delta message for streaming reasoning output. | [#L15-L33](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/base.py#L15-L33) |
| [`DeltaMessage.reasoning_content`](#contract-vllm_mlx.reasoning.base.DeltaMessage.reasoning_content) | method | `DeltaMessage.reasoning_content() -> str \| None` | Deprecated: use reasoning instead. | [#L31-L33](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/base.py#L31-L33) |
| [`ReasoningParser`](#contract-vllm_mlx.reasoning.base.ReasoningParser) | class | `ReasoningParser(tokenizer: Any \| None = None)` | Abstract base class for reasoning content extraction. | [#L36-L126](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/base.py#L36-L126) |
| [`ReasoningParser.__init__`](#contract-vllm_mlx.reasoning.base.ReasoningParser.__init__) | method | `ReasoningParser.__init__(tokenizer: Any \| None = None) -> not annotated` | Initialize parser with optional tokenizer. | [#L49-L57](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/base.py#L49-L57) |
| [`ReasoningParser.extract_reasoning`](#contract-vllm_mlx.reasoning.base.ReasoningParser.extract_reasoning) | method | `ReasoningParser.extract_reasoning(model_output: str) -> tuple[str \| None, str \| None]` | Extract reasoning content from complete model output. | [#L60-L74](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/base.py#L60-L74) |
| [`ReasoningParser.extract_reasoning_streaming`](#contract-vllm_mlx.reasoning.base.ReasoningParser.extract_reasoning_streaming) | method | `ReasoningParser.extract_reasoning_streaming(previous_text: str, current_text: str, delta_text: str) -> DeltaMessage \| None` | Extract reasoning from streaming delta. | [#L77-L100](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/base.py#L77-L100) |
| [`ReasoningParser.reset_state`](#contract-vllm_mlx.reasoning.base.ReasoningParser.reset_state) | method | `ReasoningParser.reset_state() -> not annotated` | Reset any internal state for a new request. | [#L102-L110](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/base.py#L102-L110) |
| [`ReasoningParser.finalize_stream`](#contract-vllm_mlx.reasoning.base.ReasoningParser.finalize_stream) | method | `ReasoningParser.finalize_stream() -> DeltaMessage \| None` | Finalize streaming state at end of stream. | [#L112-L126](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/base.py#L112-L126) |
