vllm.entrypoints.context ¶
_TOOL_NAME_TO_TYPE_MAP module-attribute ¶
_TOOL_NAME_TO_TYPE_MAP = {
"browser": "web_search_preview",
"python": "code_interpreter",
"container": "container",
}
ConversationContext ¶
Bases: ABC
Source code in vllm/entrypoints/context.py
append_output abstractmethod ¶
append_output(output: RequestOutput) -> None
append_tool_output abstractmethod ¶
cleanup_session abstractmethod async ¶
init_tool_sessions abstractmethod async ¶
init_tool_sessions(
tool_server: ToolServer | None,
exit_stack: AsyncExitStack,
request_id: str,
mcp_tools: dict[str, Mcp],
) -> None
HarmonyContext ¶
Bases: ConversationContext
Source code in vllm/entrypoints/context.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
__init__ ¶
Source code in vllm/entrypoints/context.py
_update_decode_token_usage ¶
_update_decode_token_usage(output: RequestOutput) -> int
Update token usage statistics for the decode phase of generation.
The decode phase processes the generated output tokens. This method: 1. Counts output tokens from all completion outputs 2. Updates the total output token count 3. Tracks tokens generated in the current turn
In streaming mode, this is called for each token generated. In non-streaming mode, this is called once with all output tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output | RequestOutput | The RequestOutput containing generated token information | required |
Returns:
| Name | Type | Description |
|---|---|---|
int | int | Number of output tokens processed in this call |
Source code in vllm/entrypoints/context.py
_update_num_reasoning_tokens ¶
_update_prefill_token_usage ¶
_update_prefill_token_usage(output: RequestOutput) -> None
Update token usage statistics for the prefill phase of generation.
The prefill phase processes the input prompt tokens. This method: 1. Counts the prompt tokens for this turn 2. Calculates tool output tokens for multi-turn conversations 3. Updates cached token counts 4. Tracks state for next turn calculations
Tool output tokens are calculated as: current_prompt_tokens - last_turn_prompt_tokens - last_turn_output_tokens This represents tokens added between turns (typically tool responses).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output | RequestOutput | The RequestOutput containing prompt token information | required |
Source code in vllm/entrypoints/context.py
append_output ¶
append_output(output: RequestOutput) -> None
Source code in vllm/entrypoints/context.py
call_container_tool async ¶
call_container_tool(
tool_session: Union[ClientSession, Tool],
last_msg: Message,
) -> list[Message]
Call container tool. Expect this to be run in a stateful docker with command line terminal. The official container tool would at least expect the following format: - for tool name: exec - args: { "cmd":List[str] "command to execute", "workdir":optional[str] "current working directory", "env":optional[object/dict] "environment variables", "session_name":optional[str] "session name", "timeout":optional[int] "timeout in seconds", "user":optional[str] "user name", }
Source code in vllm/entrypoints/context.py
call_python_tool async ¶
Source code in vllm/entrypoints/context.py
call_search_tool async ¶
Source code in vllm/entrypoints/context.py
call_tool async ¶
call_tool() -> list[Message]
Source code in vllm/entrypoints/context.py
cleanup_session async ¶
Can be used as coro to used in aexit
Source code in vllm/entrypoints/context.py
init_tool_sessions async ¶
init_tool_sessions(
tool_server: ToolServer | None,
exit_stack: AsyncExitStack,
request_id: str,
mcp_tools: dict[str, Mcp],
)
Source code in vllm/entrypoints/context.py
ParsableContext ¶
Bases: ConversationContext
Source code in vllm/entrypoints/context.py
parser instance-attribute ¶
parser = get_responses_parser_for_simple_context(
tokenizer=tokenizer,
reasoning_parser_cls=reasoning_parser_cls,
response_messages=response_messages,
request=request,
)
__init__ ¶
__init__(
*,
response_messages: list[ResponseInputOutputItem],
tokenizer: AnyTokenizer,
reasoning_parser_cls: Callable[
[AnyTokenizer], ReasoningParser
]
| None,
request: ResponsesRequest,
)
Source code in vllm/entrypoints/context.py
append_output ¶
append_output(output: RequestOutput) -> None
Source code in vllm/entrypoints/context.py
append_tool_output ¶
append_tool_output(
output: list[ResponseInputOutputItem],
) -> None
call_tool async ¶
call_tool() -> list[ResponseInputOutputItem]
cleanup_session async ¶
init_tool_sessions async ¶
init_tool_sessions(
tool_server: ToolServer | None,
exit_stack: AsyncExitStack,
request_id: str,
mcp_tools: dict[str, Mcp],
)
SimpleContext ¶
Bases: ConversationContext
This is a context that cannot handle MCP tool calls
Source code in vllm/entrypoints/context.py
__init__ ¶
Source code in vllm/entrypoints/context.py
append_output ¶
Source code in vllm/entrypoints/context.py
append_tool_output ¶
cleanup_session async ¶
init_tool_sessions async ¶
init_tool_sessions(
tool_server: ToolServer | None,
exit_stack: AsyncExitStack,
request_id: str,
mcp_tools: dict[str, Mcp],
) -> None
StreamingHarmonyContext ¶
Bases: HarmonyContext
Source code in vllm/entrypoints/context.py
__init__ ¶
Source code in vllm/entrypoints/context.py
append_output ¶
append_output(output: RequestOutput) -> None
Source code in vllm/entrypoints/context.py
append_tool_output ¶
append_tool_output(output: list[Message]) -> None
Source code in vllm/entrypoints/context.py
render_for_completion ¶
Source code in vllm/entrypoints/context.py
TurnMetrics ¶
Tracks token and toolcall details for a single conversation turn.
Source code in vllm/entrypoints/context.py
_create_json_parse_error_messages ¶
_create_json_parse_error_messages(
last_msg: Message, e: JSONDecodeError
) -> list[Message]
Creates an error message when json parse failed.