Implementation:666ghj BettaFish ReportAgent generate report
| Knowledge Sources | |
|---|---|
| Domains | Report_Generation, NLP, LLM_Prompting |
| Last Updated | 2026-10-08 00:00 GMT |
Overview
Concrete report orchestrator that takes three engine reports, forum logs, and a user query and produces a complete HTML report through an 8-stage pipeline: normalize, select template, slice, design layout, plan word budget, generate chapters, stitch IR, and render HTML.
Description
The ReportAgent.generate_report method is the main entry point for the ReportEngine. It orchestrates the entire report generation pipeline: 1. Normalizes three engine reports (Insight, Media, Query) into a standard dict 2. Selects a template via TemplateSelectionNode (6 available templates) 3. Slices the template into sections via parse_template_sections 4. Designs document layout (title, TOC, hero, theme) via DocumentLayoutNode 5. Plans word budget per chapter via WordBudgetNode 6. Generates chapter JSON via ChapterGenerationNode (validated by IRValidator) 7. Stitches chapters into a Document IR via DocumentComposer 8. Renders to HTML via HTMLRenderer
The method supports streaming progress via a callback and can save intermediate IR/state files.
Usage
Import this method when you need to generate a unified report from multiple agent outputs. It is called by the Flask app after all agents complete their research.
Code Reference
Source Location
- Repository: BettaFish
- File: `ReportEngine/agent.py:L405-918` (generate_report), `L919-937` (_normalize_reports)
Signature
class ReportAgent:
def generate_report(
self,
query: str,
reports: List[Any],
forum_logs: str = "",
custom_template: str = "",
save_report: bool = True,
stream_handler: Optional[Callable] = None,
) -> str:
"""
Generate a complete HTML report from 3-engine outputs.
Args:
query: Report topic / user query
reports: List of 3 engine reports (Query, Media, Insight order)
forum_logs: Forum debate log text
custom_template: Optional Markdown template override
save_report: Whether to save HTML/IR/state to disk
stream_handler: Optional SSE callback for progress streaming
Returns:
Complete HTML report string
"""
def _normalize_reports(self, reports: List[Any]) -> Dict[str, str]:
"""
Normalize 3 engine reports into a dict with keys:
query_engine, media_engine, insight_engine
"""
Import
from ReportEngine.agent import ReportAgent
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| query | str | Yes | Report topic |
| reports | List[Any] | Yes | 3 engine reports (strings or dicts) |
| forum_logs | str | No | Forum debate log |
| custom_template | str | No | Custom Markdown template override |
| stream_handler | Callable | No | SSE progress callback |
Outputs
| Name | Type | Description |
|---|---|---|
| html_report | str | Complete HTML document with CSS, Chart.js, MathJax |
| saved files | various | IR JSON, state JSON, HTML file (if save_report=True) |
Usage Examples
Generate Report
from ReportEngine.agent import ReportAgent
from ReportEngine.llms import LLMClient
from ReportEngine.utils.config import settings
llm = LLMClient(
api_key=settings.REPORT_ENGINE_API_KEY,
model_name=settings.REPORT_ENGINE_MODEL_NAME,
base_url=settings.REPORT_ENGINE_BASE_URL,
)
agent = ReportAgent(llm)
html = agent.generate_report(
query="武汉大学舆情分析",
reports=[
query_engine_report, # QueryEngine Markdown output
media_engine_report, # MediaEngine Markdown output
insight_engine_report, # InsightEngine Markdown output
],
forum_logs=forum_log_content,
save_report=True,
)
print(f"Generated {len(html)} chars of HTML")
Related Pages
Implements Principle
- Principle:666ghj_BettaFish_Template_Driven_Report_Generation
- Principle:666ghj_BettaFish_Multi_Agent_Orchestration
- Principle:666ghj_BettaFish_Agent_Completion_Synchronization