Heuristic:666ghj BettaFish Parallel Agent Isolation
| Knowledge Sources | |
|---|---|
| Domains | Multi_Agent, Optimization, Architecture |
| Last Updated | 2026-10-08 21:30 GMT |
Overview
Run independent search agents (Insight, Media, Query) as isolated subprocesses with separate LLM configurations, preventing cascading failures and enabling parallel execution.
Description
BettaFish's three search engines (InsightEngine, MediaEngine, QueryEngine) are designed as independent agents, each with their own LLM client, API key, base URL, and model configuration. In the full public opinion analysis pipeline, they run in parallel via subprocess execution (Streamlit apps launched as separate processes). This isolation ensures that a failure in one engine (e.g., API rate limit on DeepSeek) does not affect the others (e.g., Moonshot/Kimi continues working). Each engine writes results to its own output directory, and the ReportEngine collects and synthesizes them.
Usage
Use this heuristic when orchestrating multiple independent agents with different external dependencies. Apply when agents should fail independently and run concurrently.
The Insight (Rule of Thumb)
- Action: Give each agent its own LLM config (API key, base URL, model), run as separate processes, and collect results via filesystem.
- Value: Each engine has `{ENGINE}_API_KEY`, `{ENGINE}_BASE_URL`, `{ENGINE}_MODEL_NAME` env vars.
- Trade-off: Process isolation adds startup overhead and complexity but provides fault isolation and parallelism.
- Compatibility: Works with any multi-agent architecture. Requires filesystem-based result collection.
Reasoning
If all agents shared a single LLM API key and ran in the same process, a rate limit or API outage would halt the entire pipeline. By isolating each agent with its own API provider and running as separate processes: (1) failures are contained, (2) agents run truly in parallel, (3) different LLM providers can be used per task (Kimi for DB mining, Gemini for multimodal, DeepSeek for news), (4) resource usage is distributed. The ReportEngine uses file count polling to detect when all agents have completed.
Code Evidence
Separate LLM configuration per engine from `config.py:45-62`:
# Insight Agent (Kimi)
INSIGHT_ENGINE_API_KEY: Optional[str] = Field(None)
INSIGHT_ENGINE_BASE_URL: Optional[str] = Field("https://api.moonshot.cn/v1")
INSIGHT_ENGINE_MODEL_NAME: str = Field("kimi-k2-0711-preview")
# Media Agent (Gemini)
MEDIA_ENGINE_API_KEY: Optional[str] = Field(None)
MEDIA_ENGINE_BASE_URL: Optional[str] = Field("https://inferera.com/v1")
MEDIA_ENGINE_MODEL_NAME: str = Field("gemini-2.5-pro")
# Query Agent (DeepSeek)
QUERY_ENGINE_API_KEY: Optional[str] = Field(None)
QUERY_ENGINE_BASE_URL: Optional[str] = Field("https://api.deepseek.com")
QUERY_ENGINE_MODEL_NAME: str = Field("deepseek-chat")
Parallel Streamlit app execution from `app.py:13`:
import subprocess
# Each engine runs as a separate Streamlit app (subprocess)
# Ports: 8501 (Insight), 8502 (Media), 8503 (Query)
Docker port mapping from `docker-compose.yml:13-17`:
ports:
- "5000:5000"
- "8501:8501"
- "8502:8502"
- "8503:8503"