vllm_mlx.tool_parsers.hermes_tool_parser¶
Hermes/Nous tool call parser for vllm-mlx.
View the complete module source at #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
¶
Hermes/Nous tool call parser for vllm-mlx.
Handles Hermes-style tool calling format used by NousResearch models.
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser
¶
Bases: ToolParser
Tool call parser for Hermes/Nous models.
Supports Hermes tool call format:
-
Used when --enable-auto-tool-choice --tool-call-parser hermes are set.
Source code in vllm_mlx/tool_parsers/abstract_tool_parser.py
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.SUPPORTS_NATIVE_TOOL_FORMAT
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.TOOL_CALL_PATTERN
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.TOOL_CALL_LENIENT_PATTERN
class-attribute
instance-attribute
¶
TOOL_CALL_LENIENT_PATTERN = re.compile('<tool_call[^{]*(\\{"name":\\s*"[^"]+",\\s*"arguments":\\s*\\{[^}]*\\}\\})', re.DOTALL)
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.NEMOTRON_PATTERN
class-attribute
instance-attribute
¶
NEMOTRON_PATTERN = re.compile('<tool_call>\\s*<function=([^>]+)>(.*?)</function>\\s*</tool_call>', re.DOTALL)
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.PARAM_PATTERN
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.REASONING_PATTERN
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.RAW_JSON_TOOL_PATTERN
class-attribute
instance-attribute
¶
RAW_JSON_TOOL_PATTERN = re.compile('\\{"name":\\s*"([^"]+)",\\s*"arguments":\\s*(\\{[^}]*\\})\\}', re.DOTALL)
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.BARE_FUNCTION_PATTERN
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.extract_tool_calls
¶
extract_tool_calls(model_output: str, request: dict[str, Any] | None = None) -> ExtractedToolCallInformation
Extract tool calls from a complete Hermes model response.
Source code in vllm_mlx/tool_parsers/hermes_tool_parser.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser._format_streaming_tool_calls
staticmethod
¶
Format tool calls for streaming response.
Source code in vllm_mlx/tool_parsers/hermes_tool_parser.py
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.extract_tool_calls_streaming
¶
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.
Uses tag counting to correctly handle multiple sequential tool calls.
Source code in vllm_mlx/tool_parsers/hermes_tool_parser.py
vllm_mlx.tool_parsers.hermes_tool_parser.generate_tool_id
¶
vllm_mlx.tool_parsers.hermes_tool_parser._parse_param_value
¶
Parse a tool call parameter value, handling both JSON and Python literals.
Tries json.loads first. If that fails, falls back to ast.literal_eval for Python literal syntax (single quotes, True/False, None). Converts sets to lists and rejects types that are not JSON-serializable (complex, bytes) to avoid crashes during json.dumps later.
Source code in vllm_mlx/tool_parsers/hermes_tool_parser.py
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.
vllm_mlx.tool_parsers.hermes_tool_parser.generate_tool_id · function
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.
vllm_mlx.tool_parsers.hermes_tool_parser._parse_param_value · function
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.
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser · class
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.
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.extract_tool_calls · method
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.
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser._format_streaming_tool_calls · method
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.
vllm_mlx.tool_parsers.hermes_tool_parser.HermesToolParser.extract_tool_calls_streaming · method
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.
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 |
function | generate_tool_id() -> str |
Generate a unique tool call ID. | #L22-L24 |
_parse_param_value |
function | _parse_param_value(val: str) -> Any |
Parse a tool call parameter value, handling both JSON and Python literals. | #L27-L49 |
HermesToolParser |
class | HermesToolParser() |
Tool call parser for Hermes/Nous models. | #L53-L336 |
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 |
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 |
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 |