# `vllm_mlx.tool_parsers.hermes_tool_parser`

Hermes/Nous tool call parser for vllm-mlx.

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

## 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.tool_parsers.hermes_tool_parser
    options:
      members:
        - generate_tool_id
        - _parse_param_value
        - HermesToolParser
      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.tool_parsers.hermes_tool_parser.generate_tool_id" markdown="1">
<summary><code>vllm_mlx.tool_parsers.hermes_tool_parser.generate_tool_id</code> · function</summary>

```python
vllm_mlx.tool_parsers.hermes_tool_parser.generate_tool_id() -> str
```

Generate a unique tool call ID.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `str`
- Direct return expressions: `f'call_{uuid.uuid4().hex[:8]}'`

**Exceptions and behavior**

Function `generate_tool_id` calls `uuid.uuid4`; returns `f'call_{uuid.uuid4().hex[:8]}'`.
No direct `raise` statement appears in this definition.

[View source #L22-L24](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/hermes_tool_parser.py#L22-L24).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.hermes_tool_parser._parse_param_value" markdown="1">
<summary><code>vllm_mlx.tool_parsers.hermes_tool_parser._parse_param_value</code> · function</summary>

```python
vllm_mlx.tool_parsers.hermes_tool_parser._parse_param_value(val: str) -> Any
```

Parse a tool call parameter value, handling both JSON and Python literals.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `val` | `str` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `Any`
- Direct return expressions: `json.loads(val)`; `val`; `python_val`

**Exceptions and behavior**

Function `_parse_param_value` calls `json.loads`, `ast.literal_eval`, `isinstance`, `sorted`; has 3 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L27-L49](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/hermes_tool_parser.py#L27-L49).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser" markdown="1">
<summary><code>vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser</code> · class</summary>

```python
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser()
```

Tool call parser for Hermes/Nous models.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Constructs: `vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser`

**Exceptions and behavior**

Class `HermesToolParser` derives from `ToolParser` and declares 3 direct member(s).
No direct `raise` statement appears in this definition.

[View source #L53-L336](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/hermes_tool_parser.py#L53-L336).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.extract_tool_calls" markdown="1">
<summary><code>vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.extract_tool_calls</code> · method</summary>

```python
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.extract_tool_calls(model_output: str, request: dict[str, Any] | None = None) -> ExtractedToolCallInformation
```

Extract tool calls from a complete Hermes model response.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `model_output` | `str` | `yes` | `none` | Required positional or keyword input. |
| `request` | `dict[str, Any] \| None` | `no` | `None` | Optional positional or keyword input; defaults to `None`. |

**Returns**

- Type: `ExtractedToolCallInformation`
- Direct return expressions: `ExtractedToolCallInformation(tools_called=True, tool_calls=tool_calls, content=cleaned_text if cleaned_text else None)`; `ExtractedToolCallInformation(tools_called=False, tool_calls=[], content=cleaned_text)`

**Exceptions and behavior**

Method `HermesToolParser.extract_tool_calls` calls `self.strip_think_tags`, `self.REASONING_PATTERN.findall`, `self.REASONING_PATTERN.sub`, `self.TOOL_CALL_PATTERN.findall`; has 2 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L92-L245](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/hermes_tool_parser.py#L92-L245).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser._format_streaming_tool_calls" markdown="1">
<summary><code>vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser._format_streaming_tool_calls</code> · method</summary>

```python
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser._format_streaming_tool_calls(tool_calls: list[dict], start_index: int = 0) -> dict[str, Any]
```

Format tool calls for streaming response.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `tool_calls` | `list[dict]` | `yes` | `none` | Required positional or keyword input. |
| `start_index` | `int` | `no` | `0` | Optional positional or keyword input; defaults to `0`. |

**Returns**

- Type: `dict[str, Any]`
- Direct return expressions: `{'tool_calls': [{'index': start_index + i, 'id': tc['id'], 'type': 'function', 'function': {'name': tc['name'], 'argume…`

**Exceptions and behavior**

Method `HermesToolParser._format_streaming_tool_calls` calls `enumerate`; returns `{'tool_calls': [{'index': start_index + i, 'id': tc['id'], 'type': 'function', 'function': {'name': tc['name'], 'argume…`.
No direct `raise` statement appears in this definition.

[View source #L248-L265](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/hermes_tool_parser.py#L248-L265).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.extract_tool_calls_streaming" markdown="1">
<summary><code>vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.extract_tool_calls_streaming</code> · method</summary>

```python
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.extract_tool_calls_streaming(previous_text: str, current_text: str, delta_text: str, previous_token_ids: Sequence[int] | None = None, current_token_ids: Sequence[int] | None = None, delta_token_ids: Sequence[int] | None = None, request: dict[str, Any] | None = None) -> dict[str, Any] | None
```

Extract tool calls from streaming Hermes model output.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `previous_text` | `str` | `yes` | `none` | Required positional or keyword input. |
| `current_text` | `str` | `yes` | `none` | Required positional or keyword input. |
| `delta_text` | `str` | `yes` | `none` | Required positional or keyword input. |
| `previous_token_ids` | `Sequence[int] \| None` | `no` | `None` | Optional positional or keyword input; defaults to `None`. |
| `current_token_ids` | `Sequence[int] \| None` | `no` | `None` | Optional positional or keyword input; defaults to `None`. |
| `delta_token_ids` | `Sequence[int] \| None` | `no` | `None` | Optional positional or keyword input; defaults to `None`. |
| `request` | `dict[str, Any] \| None` | `no` | `None` | Optional positional or keyword input; defaults to `None`. |

**Returns**

- Type: `dict[str, Any] | None`
- Direct return expressions: `None`; `self._format_streaming_tool_calls(new_calls, start_index=prev_close_count)`; `{'content': delta_text}`; `self._format_streaming_tool_calls(new_calls, start_index=prev_func_close)`; `self._format_streaming_tool_calls(result.tool_calls)`

**Exceptions and behavior**

Method `HermesToolParser.extract_tool_calls_streaming` calls `current_text.count`, `previous_text.count`, `self.extract_tool_calls`, `self._format_streaming_tool_calls`; has 5 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L267-L336](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/hermes_tool_parser.py#L267-L336).

</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 |
| --- | --- | --- | --- | --- |
| [`generate_tool_id`](#contract-vllm_mlx.tool_parsers.hermes_tool_parser.generate_tool_id) | function | `generate_tool_id() -> str` | Generate a unique tool call ID. | [#L22-L24](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/hermes_tool_parser.py#L22-L24) |
| [`_parse_param_value`](#contract-vllm_mlx.tool_parsers.hermes_tool_parser._parse_param_value) | function | `_parse_param_value(val: str) -> Any` | Parse a tool call parameter value, handling both JSON and Python literals. | [#L27-L49](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/hermes_tool_parser.py#L27-L49) |
| [`HermesToolParser`](#contract-vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser) | class | `HermesToolParser()` | Tool call parser for Hermes/Nous models. | [#L53-L336](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/hermes_tool_parser.py#L53-L336) |
| [`HermesToolParser.extract_tool_calls`](#contract-vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.extract_tool_calls) | method | `HermesToolParser.extract_tool_calls(model_output: str, request: dict[str, Any] \| None = None) -> ExtractedToolCallInformation` | Extract tool calls from a complete Hermes model response. | [#L92-L245](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/hermes_tool_parser.py#L92-L245) |
| [`HermesToolParser._format_streaming_tool_calls`](#contract-vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser._format_streaming_tool_calls) | method | `HermesToolParser._format_streaming_tool_calls(tool_calls: list[dict], start_index: int = 0) -> dict[str, Any]` | Format tool calls for streaming response. | [#L248-L265](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/hermes_tool_parser.py#L248-L265) |
| [`HermesToolParser.extract_tool_calls_streaming`](#contract-vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.extract_tool_calls_streaming) | method | `HermesToolParser.extract_tool_calls_streaming(previous_text: str, current_text: str, delta_text: str, previous_token_ids: Sequence[int] \| None = None, current_token_ids: Sequence[int] \| None = None, delta_token_ids: Sequence[int] \| None = None, request: dict[str, Any] \| None = None) -> dict[str, Any] \| None` | Extract tool calls from streaming Hermes model output. | [#L267-L336](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/hermes_tool_parser.py#L267-L336) |
