Story Agents¶
The versifai.story_agents package provides agents for transforming research into narrative reports.
StoryTellerAgent¶
StoryTellerAgent
¶
StoryTellerAgent(cfg: StorytellerConfig | None = None, dbutils=None, resume: bool = False)
Bases: BaseAgent
Autonomous narrative report writer powered by Claude.
Reads DataScientist outputs and produces a compelling, evidence-grounded Markdown document organized into configured narrative sections.
Supports smart resume: if interrupted, re-launching picks up from the last completed section. Previously written sections are loaded from disk and skipped.
Workflow
- Inventory — scan research outputs, map coverage per section
- Evidence Evaluation — score finding strength, build bill of materials
- Section Writing — write each section using curated evidence
- Coherence Pass — fix transitions, consistency, completeness
- Finalization — assemble document, add TOC, bibliography
Usage in a Databricks notebook::
from versifai.story_agents.storyteller.agent import StoryTellerAgent
from versifai.story_agents.storyteller.config import StorytellerConfig
cfg = StorytellerConfig()
agent = StoryTellerAgent(cfg=cfg, dbutils=dbutils)
agent.run()
Source code in src/versifai/story_agents/storyteller/agent.py
89 90 91 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 | |
run
¶
Run the full storytelling pipeline.
By default, scans for previously written sections and skips them
(smart resume). Set rerun=True to force a fresh start.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instructions
|
str
|
Optional high-level guidance prepended to every phase prompt (e.g., "Focus on the bullwhip effect"). |
''
|
rerun
|
bool
|
If True, ignore existing sections and rewrite everything. |
False
|
focus_visuals
|
list[str] | None
|
Optional shortlist of chart/table filenames the
agent should prioritize when selecting visuals for sections.
e.g., |
None
|
Returns a summary dict with sections written, word counts, etc.
Source code in src/versifai/story_agents/storyteller/agent.py
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 594 595 596 597 598 599 600 | |
run_sections
¶
run_sections(sections: list[int] | None = None, coherence: bool = True, instructions: str = '') -> dict
Re-run specific sections only (like DataScientist.run_themes).
Always rewrites the specified sections (no smart resume). Loads existing sections from disk so coherence pass and assembly have the full document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sections
|
list[int] | None
|
Section sequence numbers to run.
e.g., |
None
|
coherence
|
bool
|
Whether to run coherence pass after sections. |
True
|
instructions
|
str
|
High-level guidance for the agent. |
''
|
Usage::
agent = StoryTellerAgent(cfg=cfg, dbutils=dbutils)
agent.run_sections(sections=[0, 1]) # rewrite first two sections
agent.run_sections(coherence=False) # all sections, skip coherence
Source code in src/versifai/story_agents/storyteller/agent.py
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 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 735 736 737 738 739 740 741 742 743 | |
run_editor
¶
Run an editorial review pass on the completed narrative.
Reads all existing sections, then works with the human operator
to diagnose issues and apply targeted revisions. Uses ask_human
proactively at defined checkpoints — this is a HITL workflow by
design.
This is the validation step for the storyteller, analogous to
DataScientistAgent.run_validation().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instructions
|
str
|
Editorial guidance for the review. e.g.,
|
''
|
Usage::
agent = StoryTellerAgent(cfg=cfg, dbutils=dbutils)
# Guided review
agent.run_editor(
instructions="The bullwhip section is too technical. "
"Simplify for a policymaker audience."
)
# Open-ended review
agent.run_editor()
Source code in src/versifai/story_agents/storyteller/agent.py
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 | |
Configuration¶
StorytellerConfig
dataclass
¶
StorytellerConfig(name: str = '', thesis: str = '', llm: LLMConfig = LLMConfig(), research_results_path: str = '', narrative_output_path: str = '', project: ProjectConfig = (lambda: _default_project())(), narrative_sections: list[NarrativeSection] = list(), evidence_threshold: EvidenceThreshold = EvidenceThreshold(), style_guide: StyleGuide = StyleGuide(), output_format: OutputFormat = OutputFormat(), citation_urls: list[str] = list(), domain_writing_rules: str = '', citation_source_guidance: str = '', max_turns_per_section: int = 60, max_turns_per_phase: int = 80, coherence_pass_max_turns: int = 40, editor_max_turns_per_section: int = 40, editor_max_turns_overview: int = 30, chart_style: str = 'seaborn-v0_8-whitegrid', chart_dpi: int = 150, color_palette: str = 'viridis', run_id: str = '', dependencies: list[AgentDependency] = list())
Configuration for a narrative report project.
The StoryTellerAgent uses this to drive its writing workflow. Assemble one from building blocks (sections, style guide, evidence rules) and pass it to the agent. The agent code is generic — all domain knowledge lives in the config instance.
results_volume_path
property
¶
Alias for CreateVisualizationTool compatibility.
CreateVisualizationTool reads cfg.results_volume_path to determine where to write charts/ and tables/. For the storyteller, new charts and tables are co-located with the DataScientist's outputs.
evidence_prompt_text
property
¶
Evidence rules formatted for prompt injection.
NarrativeSection
dataclass
¶
NarrativeSection(id: str, title: str, purpose: str, source_theme_ids: list[str], tone: str = 'analytical', max_words: int = 1500, key_evidence: str = '', charts_to_include: list[str] = list(), charts_to_reconfigure: list[str] = list(), narrative_guidance: str = '', transition_from: str = '', transition_to: str = '', sequence: int = 0)
One section of the narrative report.
EvidenceThreshold
dataclass
¶
EvidenceThreshold(min_significance_for_lead: str = 'high', min_significance_for_support: str = 'medium', require_effect_size: bool = True, max_unsupported_claims: int = 0)
Rules for when evidence is strong enough to cite.
StyleGuide
dataclass
¶
StyleGuide(voice: str = 'third-person analytical', audience: str = '', reading_level: str = 'professional', citation_style: str = 'inline', document_type: str = '', purpose: str = '', tone_guidance: str = '', anti_patterns: str = '')
Voice, audience, and writing rules for the narrative.
OutputFormat
dataclass
¶
OutputFormat(format: str = 'markdown', filename: str = 'narrative_report.md', include_toc: bool = True, include_methodology_appendix: bool = True, include_data_sources_appendix: bool = True, chart_reference_style: str = 'relative_path')
How the final document is assembled and exported.