666ghj/MiroFish · error · ValueError

模拟配置中没有Agent: {simulation_id}

Error message

模拟配置中没有Agent: {simulation_id}

What it means

interview_all_agents loads simulation_config.json and reads agent_configs; if the key is absent or the list is empty, there is nothing to interview and it raises ValueError('模拟配置中没有Agent'). Only agents with a non-null agent_id are included, so a config whose agents all lack agent_id also produces an empty list downstream of this check failing first.

Source

Thrown at backend/app/services/simulation_runner.py:1855

        Returns:
            全局采访结果字典
        """
        sim_dir = os.path.join(cls.RUN_STATE_DIR, simulation_id)
        if not os.path.exists(sim_dir):
            raise ValueError(f"模拟不存在: {simulation_id}")

        # 从配置文件获取所有Agent信息
        config_path = os.path.join(sim_dir, "simulation_config.json")
        if not os.path.exists(config_path):
            raise ValueError(f"模拟配置不存在: {simulation_id}")

        with open(config_path, 'r', encoding='utf-8') as f:
            config = json.load(f)

        agent_configs = config.get("agent_configs", [])
        if not agent_configs:
            raise ValueError(f"模拟配置中没有Agent: {simulation_id}")

        # 构建批量采访列表
        interviews = []
        for agent_config in agent_configs:
            agent_id = agent_config.get("agent_id")
            if agent_id is not None:
                interviews.append({
                    "agent_id": agent_id,
                    "prompt": prompt
                })

        logger.info(f"发送全局Interview命令: simulation_id={simulation_id}, agent_count={len(interviews)}, platform={platform}")

        return cls.interview_agents_batch(
            simulation_id=simulation_id,
            interviews=interviews,
            platform=platform,
            timeout=timeout

View on GitHub (pinned to b5b53acc57)

Solutions

  1. Inspect simulation_config.json in the run directory: confirm agent_configs is a non-empty array of objects each carrying agent_id.
  2. Regenerate the simulation config from valid agent profiles and restart the simulation.
  3. If you meant to interview specific agents, use interview_agent/batch_interview with explicit ids instead of the global path.

Example fix

// before
{ "simulation_name": "demo", "agent_configs": [] }  // 模拟配置中没有Agent

// after
{ "simulation_name": "demo", "agent_configs": [ { "agent_id": "agent_001", "platform": "twitter" }, { "agent_id": "agent_002", "platform": "reddit" } ] }
Defensive patterns

Strategy: validation

Validate before calling

def config_has_agents(sim_id: str) -> bool:
    cfg_path = Path(SimulationRunner.RUN_STATE_DIR) / sim_id / "simulation_config.json"
    if not cfg_path.is_file():
        return False
    agents = json.loads(cfg_path.read_text(encoding="utf-8")).get("agent_configs", [])
    return any(a.get("agent_id") is not None for a in agents)

Type guard

def is_valid_agent_config(cfg: dict) -> bool:
    return isinstance(cfg.get("agent_configs"), list) and len(cfg["agent_configs"]) > 0 and all(
        isinstance(a, dict) and a.get("agent_id") for a in cfg["agent_configs"]
    )

Try / catch

try:
    SimulationRunner.interview_all_agents(sim_id, prompt)
except ValueError as e:
    if "没有Agent" in str(e):
        return {"success": False, "error": "empty_agent_config"}
    raise

Prevention

When it happens

Trigger: Config JSON has "agent_configs": [] or omits the key entirely; mis-generated config from the simulation generator; schema drift where the field was renamed.

Common situations: Config generator produced an empty agent set (bad profile input); hand-edited configs; older configs written before the agent_configs schema was introduced.

Related errors


AI-assisted analysis of 666ghj/MiroFish@b5b53acc57 (2026-08-14). Data as JSON: /api/errors/8b776d05326d32cc. Report an issue: GitHub.