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 LogMonitor start monitoring

From Leeroopedia
Knowledge Sources
Domains Multi_Agent_Systems, File_Monitoring, Inter_Agent_Communication
Last Updated 2026-10-08 00:00 GMT

Overview

Concrete file-based log monitor that tails three agent log files in real-time, detects SummaryNode outputs, buffers agent speeches, and triggers the LLM forum host when a speech threshold is reached.

Description

The LogMonitor class implements file-based inter-agent communication for the ForumEngine. It runs in a background thread, polling `insight.log`, `media.log`, and `query.log` for new lines. When it detects SummaryNode output patterns (FirstSummaryNode, ReflectionSummaryNode), it captures the JSON content, buffers the agent speech, and when the buffer reaches the threshold (5 speeches), it triggers the ForumHost to generate moderator guidance. The host speech is written to `forum.log`, which agents read via `forum_reader.get_latest_host_speech()`.

Usage

Import this class when you need to coordinate multi-agent debate through file-based log monitoring. It is started by the Flask app's `initialize_system_components()` function.

Code Reference

Source Location

  • Repository: BettaFish
  • File: `ForumEngine/monitor.py:L24-859`

Signature

class LogMonitor:
    def __init__(self, log_dir: str = "logs"):
        """
        Args:
            log_dir: Directory containing agent log files.
                     Monitors insight.log, media.log, query.log.
        """

    def start_monitoring(self) -> bool:
        """Start background monitoring thread. Returns success bool."""

    def stop_monitoring(self) -> None:
        """Stop the monitoring thread."""

    def clear_forum_log(self) -> None:
        """Clear forum.log and reset all state."""

    def write_to_forum_log(self, content: str, source: str = None) -> None:
        """Write a line to forum.log with timestamp and source tag."""

    def is_target_log_line(self, line: str) -> bool:
        """Check if a log line matches SummaryNode output patterns."""

    def process_lines_for_json(self, new_lines: List[str], app_name: str) -> List[str]:
        """Extract JSON content blocks from multi-line log entries."""

Import

from ForumEngine.monitor import LogMonitor

I/O Contract

Inputs

Name Type Required Description
log_dir str No Directory with agent logs (default: "logs")
host_speech_threshold int No Speeches before host triggers (default: 5)

Outputs

Name Type Description
forum.log file HOST moderator speeches appended for agents to read
is_monitoring bool Whether monitoring thread is active

Usage Examples

Start Forum Monitoring

from ForumEngine.monitor import LogMonitor

monitor = LogMonitor(log_dir="logs")
monitor.clear_forum_log()  # Reset for new session

# Start background monitoring
monitor.start_monitoring()

# Monitor will:
# 1. Tail insight.log, media.log, query.log
# 2. Detect SummaryNode outputs
# 3. Buffer agent speeches
# 4. Every 5 speeches: call ForumHost.generate_host_speech
# 5. Write host speech to forum.log
# 6. Agents read via forum_reader.get_latest_host_speech()

# Stop when done
monitor.stop_monitoring()

Related Pages

Implements Principle

Requires Environment

Page Connections

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