Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:666ghj BettaFish FileCountBaseline initialize

From Leeroopedia
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)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment