Implementation:666ghj BettaFish WordBudgetNode run
| Knowledge Sources | |
|---|---|
| Domains | Report_Generation, LLM_Prompting |
| Last Updated | 2026-10-08 00:00 GMT |
Overview
Concrete node that uses an LLM to plan the word count budget for each chapter in the report, producing target/min/max word constraints and global writing guidelines.
Description
The WordBudgetNode takes template sections, the layout design, normalized reports, and the query, then calls an LLM to produce a word budget plan. The plan includes a total word count, global writing guidelines, and per-chapter constraints (target, min, max words). This ensures the final report has balanced chapter lengths and stays within reasonable length limits.
Usage
Import this node when you need to plan word budgets for report chapters. It runs after DocumentLayoutNode in the ReportEngine pipeline.
Code Reference
Source Location
- Repository: BettaFish
- File: `ReportEngine/nodes/word_budget_node.py:L21-126`
Signature
class WordBudgetNode(BaseNode):
def __init__(self, llm_client):
"""Args: llm_client - LLMClient"""
def run(
self,
sections: List[TemplateSection],
design: Dict[str, Any],
reports: Dict[str, str],
forum_logs: str,
query: str,
template_overview: Dict[str, Any] | None = None,
) -> Dict[str, Any]:
"""
Plan word budget for each chapter.
Returns:
Dict with totalWords (int), globalGuidelines (List),
chapters (List[Dict] with chapterId, target, min, max words)
"""
Import
from ReportEngine.nodes import WordBudgetNode
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| sections | List[TemplateSection] | Yes | Parsed template sections |
| design | Dict | Yes | Layout design from DocumentLayoutNode |
| reports | Dict[str, str] | Yes | Normalized engine reports |
| query | str | Yes | User query |
Outputs
| Name | Type | Description |
|---|---|---|
| totalWords | int | Total target word count |
| globalGuidelines | List | Global writing guidelines |
| chapters | List[Dict] | Per-chapter word constraints |
Usage Examples
Plan Word Budget
from ReportEngine.nodes import WordBudgetNode
from ReportEngine.llms import LLMClient
llm = LLMClient(api_key="sk-...", model_name="deepseek-chat", base_url="...")
node = WordBudgetNode(llm)
plan = node.run(
sections=template_sections,
design=layout_design,
reports=normalized_reports,
forum_logs="",
query="武汉大学舆情分析"
)
print(f"Total words: {plan['totalWords']}")
for ch in plan['chapters']:
print(f" {ch['chapterId']}: {ch['target']} words (min {ch['min']}, max {ch['max']})")