Heuristic:666ghj BettaFish Polling Interval Tuning
| Knowledge Sources | |
|---|---|
| Domains | Optimization, Multi_Agent |
| Last Updated | 2026-10-08 21:30 GMT |
Overview
Poll file counts at a tuned interval to detect agent completion without overwhelming the filesystem, using a file count baseline comparison strategy.
Description
The ReportEngine uses a `FileCountBaseline` mechanism to detect when all sub-agents have completed their work. It establishes a baseline file count at initialization, then periodically polls the output directory. When the file count stops increasing for a sustained period (indicating all agents have finished writing), the report generation pipeline proceeds. The polling interval is tuned to balance responsiveness (detecting completion quickly) against filesystem overhead (too-frequent polling wastes I/O).
Usage
Use this heuristic when synchronizing multi-agent completion via filesystem signals. Apply when agents write output files and the orchestrator needs to know when all are done.
The Insight (Rule of Thumb)
- Action: Initialize `FileCountBaseline` at pipeline start, then poll output directory at a fixed interval until file count stabilizes.
- Value: Polling interval should be 2-5 seconds for most workloads. Completion is detected when file count matches expected count or stabilizes.
- Trade-off: Shorter interval = faster detection but more I/O. Longer interval = less I/O but slower detection.
- Compatibility: Works with any file-based multi-agent system. Requires agents to write output files.
Reasoning
In the BettaFish architecture, multiple agents (Insight, Media, Query) run in parallel and write reports to disk. The ReportEngine must wait for all to finish before composing the final document. Polling file counts is a simple, robust synchronization mechanism that doesn't require inter-process communication. The baseline comparison ensures that pre-existing files don't cause false completion signals.
Code Evidence
FileCountBaseline initialization from `ReportEngine/agent.py:204,222-224`:
self.file_baseline = FileCountBaseline()
# ...
self._initialize_file_baseline()
# Ensures output directories exist
os.makedirs(self.config.OUTPUT_DIR, exist_ok=True)
SocketIO-based real-time updates from `app.py:37`:
socketio = SocketIO(app, cors_allowed_origins="*")
Completion status tracking from `ReportEngine/agent.py:742`:
completion_status['warningMessage'] = self._CONTENT_SPARSE_WARNING_TEXT