Streaming ExecutorΒΆ
DSPy streaming execution with Rich display and WebSocket support.
Phase 6: Extracted from dspy_engine.py to reduce file size and improve modularity.
This module handles all streaming-related logic for DSPy program execution, including two modes: - CLI mode: Rich Live display with terminal formatting (agents.run()) - Dashboard mode: WebSocket-only streaming for parallel execution (no Rich overhead)
ClassesΒΆ
DSPyStreamingExecutor ΒΆ
DSPyStreamingExecutor(*, status_output_field: str, stream_vertical_overflow: str, theme: str, no_output: bool)
Executes DSPy programs in streaming mode with Rich or WebSocket output.
Responsibilities: - Standard (non-streaming) execution - WebSocket-only streaming (dashboard mode, no Rich overhead) - Rich CLI streaming with formatted tables - Stream formatter setup (themes, styles) - Final display rendering with artifact metadata
Initialize streaming executor with configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
status_output_field | str | Field name for status output | required |
stream_vertical_overflow | str | Rich Live vertical overflow strategy | required |
theme | str | Theme name for Rich output formatting | required |
no_output | bool | Whether to disable output | required |
Source code in src/flock/engines/dspy/streaming_executor.py
FunctionsΒΆ
execute_standard async
ΒΆ
Execute DSPy program in standard mode (no streaming).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dspy_mod | DSPy module | required | |
program | DSPy program (Predict or ReAct) | required | |
description | str | System description | required |
payload | dict[str, Any] | Execution payload with semantic field names | required |
Returns:
Type | Description |
---|---|
Any | DSPy Prediction result |
Source code in src/flock/engines/dspy/streaming_executor.py
execute_streaming_websocket_only async
ΒΆ
execute_streaming_websocket_only(dspy_mod, program, signature, *, description: str, payload: dict[str, Any], agent: Any, ctx: Any = None, pre_generated_artifact_id: Any = None, output_group=None) -> tuple[Any, None]
Execute streaming for WebSocket only (no Rich display).
Optimized path for dashboard mode that skips all Rich formatting overhead. Used when multiple agents stream in parallel to avoid terminal conflicts and deadlocks with MCP tools.
This method eliminates the Rich Live context that can cause deadlocks when combined with MCP tool execution and parallel agent streaming.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dspy_mod | DSPy module | required | |
program | DSPy program (Predict or ReAct) | required | |
signature | DSPy Signature | required | |
description | str | System description | required |
payload | dict[str, Any] | Execution payload with semantic field names | required |
agent | Any | Agent instance | required |
ctx | Any | Execution context | None |
pre_generated_artifact_id | Any | Pre-generated artifact ID for streaming | None |
output_group | OutputGroup defining expected outputs | None |
Returns:
Type | Description |
---|---|
tuple[Any, None] | Tuple of (DSPy Prediction result, None) |
Source code in src/flock/engines/dspy/streaming_executor.py
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 |
|
execute_streaming async
ΒΆ
execute_streaming(dspy_mod, program, signature, *, description: str, payload: dict[str, Any], agent: Any, ctx: Any = None, pre_generated_artifact_id: Any = None, output_group=None) -> Any
Execute DSPy program in streaming mode with Rich table updates.
Source code in src/flock/engines/dspy/streaming_executor.py
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 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 |
|
prepare_stream_formatter ΒΆ
Build formatter + theme metadata for streaming tables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent | Any | Agent instance | required |
Returns:
Type | Description |
---|---|
tuple[Any, dict[str, Any], dict[str, Any], str] | Tuple of (formatter, theme_dict, styles, agent_label) |
Source code in src/flock/engines/dspy/streaming_executor.py
print_final_stream_display ΒΆ
print_final_stream_display(stream_display_data: tuple[Any, OrderedDict, dict, dict, str], artifact_id: str, artifact) -> None
Print the final streaming display with the real artifact ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream_display_data | tuple[Any, OrderedDict, dict, dict, str] | Tuple of (formatter, display_data, theme_dict, styles, agent_label) | required |
artifact_id | str | Final artifact ID | required |
artifact | Artifact instance with metadata | required |