vllm.entrypoints.openai.responses.streaming_events
¶
Streaming SSE event builders for the Responses API.
Pure functions that translate streaming state + delta data into OpenAI Response API SSE events. Used by the streaming event processors in serving.py.
The file is organized as
- StreamingState dataclass + utility helpers
- Shared leaf helpers — delta events (take plain strings, no context)
- Shared leaf helpers — done events (take plain strings, no context)
- Harmony-specific dispatchers (route ctx/previous_item → leaf helpers)
- Harmony-specific tool lifecycle helpers
Classes:
-
SimpleStreamingEventProcessor–State-machine processor for the simple (non-Harmony) streaming path.
-
StreamingState–Mutable state for streaming event processing.
Functions:
-
emit_browser_tool_events–Emit events for browser tool calls (web search).
-
emit_code_interpreter_completion_events–Emit events when code interpreter completes.
-
emit_code_interpreter_delta_events–Emit events for code interpreter delta streaming.
-
emit_content_delta_events–Emit events for content delta streaming based on channel type.
-
emit_function_call_delta_events–Emit events for function call argument deltas.
-
emit_function_call_done_events–Emit events when a function call completes.
-
emit_mcp_completion_events–Emit events when an MCP tool call completes.
-
emit_mcp_delta_events–Emit events for MCP tool delta streaming.
-
emit_previous_item_done_events–Emit done events for the previous item when expecting a new start.
-
emit_reasoning_delta_events–Emit events for reasoning text delta streaming.
-
emit_reasoning_done_events–Emit events when a reasoning (analysis) item completes.
-
emit_text_delta_events–Emit events for text content delta streaming.
-
emit_text_output_done_events–Emit events when a final text output item completes.
-
emit_tool_action_events–Emit events for a completed assistant action turn.
-
is_mcp_tool_by_namespace–Determine if a tool call is an MCP tool based on recipient prefix.
-
split_delta–Decompose a DeltaMessage with multiple fields into atomic deltas.
SimpleStreamingEventProcessor
¶
State-machine processor for the simple (non-Harmony) streaming path.
Core flow
- Resolve the target state from the delta_message (CONTENT / REASONING / TOOL_CALL).
- If the target state differs from the current one, close_current() then open() the new state.
- emit_delta() produces the incremental events for the state.
State lifecycle
open() -> repeated emit_delta() -> close_current()
Methods:
-
close_current–Close the current state and emit its 'done' event sequence.
-
emit_delta–Emit incremental events for the current state from the delta.
-
needs_transition–Return True when we must close the current state and open a new one.
-
open–Open a new state and emit its 'added' / 'open' event sequence.
-
resolve_target_state–Decide which state the next delta belongs to.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 | |
close_current()
¶
Close the current state and emit its 'done' event sequence.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
emit_delta(delta_message, output, get_logprobs=None)
¶
Emit incremental events for the current state from the delta.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
needs_transition(target_state, tool_call)
¶
Return True when we must close the current state and open a new one.
Two cases trigger a transition
- The target state differs from the current state (e.g. CONTENT -> TOOL_CALL).
- We are already in TOOL_CALL but the next tool_call has a different index (multiple consecutive tool calls).
Source code in vllm/entrypoints/openai/responses/streaming_events.py
open(target_state, tool_call=None)
¶
Open a new state and emit its 'added' / 'open' event sequence.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
resolve_target_state(delta_message)
¶
Decide which state the next delta belongs to.
Priority: TOOL_CALL > REASONING > CONTENT, fallback to NONE. For TOOL_CALL the first tool_call object is also returned so callers can detect a switch between consecutive tools.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
StreamingState
dataclass
¶
Mutable state for streaming event processing.
Methods:
-
reset_for_new_item–Reset state when expecting a new output item.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
reset_for_new_item()
¶
Reset state when expecting a new output item.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
_StateHandlers
¶
Bases: NamedTuple
Tuple for each state: open(start), delta(chunk), done(finish).
Source code in vllm/entrypoints/openai/responses/streaming_events.py
_resolve_mcp_name_label(recipient)
¶
Resolve MCP tool name and server label from a recipient string.
mcp.*recipients: strip prefix, use the bare name as both name and server_label.- Everything else: use the recipient as the name and look up the server_label in TOOL_NAME_TO_MCP_SERVER_LABEL.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
emit_browser_tool_events(previous_item, state)
¶
Emit events for browser tool calls (web search).
Source code in vllm/entrypoints/openai/responses/streaming_events.py
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 | |
emit_code_interpreter_completion_events(previous_item, state)
¶
Emit events when code interpreter completes.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
emit_code_interpreter_delta_events(delta, state)
¶
Emit events for code interpreter delta streaming.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
emit_content_delta_events(segment, state, function_tool_names=None)
¶
Emit events for content delta streaming based on channel type.
This is a Harmony-specific dispatcher that extracts values from the latest append segment and delegates to shared leaf helpers.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
emit_function_call_delta_events(delta, function_name, state)
¶
Emit events for function call argument deltas.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
emit_function_call_done_events(function_name, arguments, state)
¶
Emit events when a function call completes.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
emit_mcp_completion_events(recipient, arguments, state)
¶
Emit events when an MCP tool call completes.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
emit_mcp_delta_events(delta, state, recipient)
¶
Emit events for MCP tool delta streaming.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
emit_previous_item_done_events(previous_item, state, function_tool_names=None)
¶
Emit done events for the previous item when expecting a new start.
This is a Harmony-specific dispatcher that extracts values from the Harmony parser's message object and delegates to shared leaf helpers.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
emit_reasoning_delta_events(delta, state)
¶
Emit events for reasoning text delta streaming.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
emit_reasoning_done_events(text, state)
¶
Emit events when a reasoning (analysis) item completes.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
emit_text_delta_events(delta, state)
¶
Emit events for text content delta streaming.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
emit_text_output_done_events(text, state)
¶
Emit events when a final text output item completes.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
emit_tool_action_events(previous_item, state, tool_server)
¶
Emit events for a completed assistant action turn.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
is_mcp_tool_by_namespace(recipient, allowed_function_tool_names=None)
¶
Determine if a tool call is an MCP tool based on recipient prefix.
Inverse of :func:is_function_recipient — everything that is not
a function call is an MCP tool.
Source code in vllm/entrypoints/openai/responses/streaming_events.py
split_delta(delta)
¶
Decompose a DeltaMessage with multiple fields into atomic deltas.
The Responses API emits typed SSE events (one type per event), so a compound DeltaMessage must be split before entering the state machine. Order: reasoning -> content -> tool_calls (grouped by index).