Implementation:666ghj BettaFish FileCountBaseline initialize
| Knowledge Sources | |
|---|---|
| Domains | Multi_Agent_Systems, Process_Coordination |
| Last Updated | 2026-10-08 00:00 GMT |
Overview
Concrete utility class that tracks file counts across three engine output directories to determine when all agents have produced new reports, signaling readiness for report generation.
Description
The FileCountBaseline class solves the synchronization problem: how does the system know when all three research agents have completed their work? It maintains a baseline count of `.md` files in each engine's output directory (`insight_engine_streamlit_reports`, `media_engine_streamlit_reports`, `query_engine_streamlit_reports`). After agents start, it polls the directories and compares current counts against the baseline. When all three directories have new files, it signals readiness for the ReportEngine to begin.
Usage
Import this class when you need to synchronize report generation with agent completion. It is used by `ReportAgent` in the Full Public Opinion Analysis workflow.
Code Reference
Source Location
- Repository: BettaFish
- File: `ReportEngine/agent.py:L47-171`
Signature
class FileCountBaseline:
def __init__(self):
"""Initialize and load baseline from logs/report_baseline.json."""
def initialize_baseline(self, directories: Dict[str, str]) -> Dict[str, int]:
"""
Record current .md file counts as baseline.
Args:
directories: Maps engine names to report directories
Returns:
Dict of engine -> file count at baseline
"""
def check_new_files(self, directories: Dict[str, str]) -> Dict[str, Any]:
"""
Check if all engines have new .md files since baseline.
Returns:
Dict with:
- current_counts: Dict[str, int]
- new_files_found: Dict[str, int]
- all_ready: bool (True if all engines have new files)
- missing_engines: List[str]
"""
Import
from ReportEngine.agent import FileCountBaseline
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| directories | Dict[str, str] | Yes | Maps engine names to output directories |
Outputs
| Name | Type | Description |
|---|---|---|
| baseline_data | Dict[str, int] | Persisted to logs/report_baseline.json |
| all_ready | bool | Whether all engines have new reports |
Usage Examples
Check Agent Readiness
from ReportEngine.agent import FileCountBaseline
baseline = FileCountBaseline()
directories = {
"insight_engine": "insight_engine_streamlit_reports",
"media_engine": "media_engine_streamlit_reports",
"query_engine": "query_engine_streamlit_reports",
}
# Set baseline before agents start
baseline.initialize_baseline(directories)
# After agents start, poll for new files
import time
while True:
status = baseline.check_new_files(directories)
if status["all_ready"]:
print("All engines ready! Starting report generation.")
break
print(f"Waiting... Missing: {status['missing_engines']}")
time.sleep(10)