# `vllm_mlx.tool_parsers.xlam_tool_parser`

xLAM tool call parser for vllm-mlx.

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

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

```python
vllm_mlx.tool_parsers.xlam_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 #L24-L26](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/xlam_tool_parser.py#L24-L26).

</details>

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

```python
vllm_mlx.tool_parsers.xlam_tool_parser.xLAMToolParser()
```

Tool call parser for Salesforce xLAM models.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Constructs: `vllm_mlx.tool_parsers.xlam_tool_parser.xLAMToolParser`

**Exceptions and behavior**

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

[View source #L30-L177](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/xlam_tool_parser.py#L30-L177).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.xlam_tool_parser.xLAMToolParser._try_extract_json" markdown="1">
<summary><code>vllm_mlx.tool_parsers.xlam_tool_parser.xLAMToolParser._try_extract_json</code> · method</summary>

```python
vllm_mlx.tool_parsers.xlam_tool_parser.xLAMToolParser._try_extract_json(text: str) -> tuple[str | None, list | None]
```

Try to extract JSON tool calls from text.

**Parameters**

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

**Returns**

- Type: `tuple[str | None, list | None]`
- Direct return expressions: `(content if content else None, parsed)`; `(None, parsed)`; `(text, None)`

**Exceptions and behavior**

Method `xLAMToolParser._try_extract_json` calls `pattern.findall`, `json.loads`, `match.strip`, `isinstance`; has 3 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L47-L91](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/xlam_tool_parser.py#L47-L91).

</details>

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

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

Extract tool calls from xLAM model output.

**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=False, tool_calls=[], content=content or model_output)`; `ExtractedToolCallInformation(tools_called=True, tool_calls=tool_calls, content=content)`; `ExtractedToolCallInformation(tools_called=False, tool_calls=[], content=model_output)`

**Exceptions and behavior**

Method `xLAMToolParser.extract_tool_calls` calls `self._try_extract_json`, `ExtractedToolCallInformation`, `isinstance`, `call.get`; has 3 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L93-L131](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/xlam_tool_parser.py#L93-L131).

</details>

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

```python
vllm_mlx.tool_parsers.xlam_tool_parser.xLAMToolParser.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 xLAM 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: `{'content': delta_text}`; `{'tool_calls': [{'index': i, 'id': tc['id'], 'type': 'function', 'function': {'name': tc['name'], 'arguments': tc['argu…`; `None`

**Exceptions and behavior**

Method `xLAMToolParser.extract_tool_calls_streaming` calls `any`, `current_text.strip`, `stripped.startswith`, `self.extract_tool_calls`; has 3 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L133-L177](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/xlam_tool_parser.py#L133-L177).

</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.xlam_tool_parser.generate_tool_id) | function | `generate_tool_id() -> str` | Generate a unique tool call ID. | [#L24-L26](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/xlam_tool_parser.py#L24-L26) |
| [`xLAMToolParser`](#contract-vllm_mlx.tool_parsers.xlam_tool_parser.xLAMToolParser) | class | `xLAMToolParser()` | Tool call parser for Salesforce xLAM models. | [#L30-L177](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/xlam_tool_parser.py#L30-L177) |
| [`xLAMToolParser._try_extract_json`](#contract-vllm_mlx.tool_parsers.xlam_tool_parser.xLAMToolParser._try_extract_json) | method | `xLAMToolParser._try_extract_json(text: str) -> tuple[str \| None, list \| None]` | Try to extract JSON tool calls from text. | [#L47-L91](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/xlam_tool_parser.py#L47-L91) |
| [`xLAMToolParser.extract_tool_calls`](#contract-vllm_mlx.tool_parsers.xlam_tool_parser.xLAMToolParser.extract_tool_calls) | method | `xLAMToolParser.extract_tool_calls(model_output: str, request: dict[str, Any] \| None = None) -> ExtractedToolCallInformation` | Extract tool calls from xLAM model output. | [#L93-L131](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/xlam_tool_parser.py#L93-L131) |
| [`xLAMToolParser.extract_tool_calls_streaming`](#contract-vllm_mlx.tool_parsers.xlam_tool_parser.xLAMToolParser.extract_tool_calls_streaming) | method | `xLAMToolParser.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 xLAM model output. | [#L133-L177](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/xlam_tool_parser.py#L133-L177) |
