666ghj/MiroFish · error · ValueError

ZEP_API_KEY未配置

Error message

ZEP_API_KEY未配置

What it means

ZepGraphMemoryUpdater.__init__ mirrors the reader's key check: graph_id plus optional api_key, falling back to Config.ZEP_API_KEY; when empty it raises ValueError('ZEP_API_KEY未配置') (note: no space, unlike the reader's message) before building the Zep client and its activity queue. Any simulation started with graph memory enabled will fail at updater construction without the key.

Source

Thrown at backend/app/services/zep_graph_memory_updater.py:261

    def __init__(
        self,
        graph_id: str,
        api_key: Optional[str] = None,
        simulation_id: Optional[str] = None,
    ):
        """
        初始化更新器
        
        Args:
            graph_id: Zep图谱ID
            api_key: Zep API Key(可选,默认从配置读取)
        """
        self.graph_id = graph_id
        self.simulation_id = simulation_id or "unknown"
        self.api_key = api_key or Config.ZEP_API_KEY
        
        if not self.api_key:
            raise ValueError("ZEP_API_KEY未配置")
        
        self.client = get_zep_client(self.api_key)
        
        # 活动队列
        self._activity_queue: Queue = Queue()
        
        # 按平台分组的活动缓冲区(每个平台各自累积到BATCH_SIZE后批量发送)
        self._platform_buffers: Dict[str, List[AgentActivity]] = {
            'twitter': [],
            'reddit': [],
        }
        self._buffer_lock = threading.Lock()
        self._acceptance_lock = threading.Lock()
        
        # 控制标志
        self._running = False
        self._worker_thread: Optional[threading.Thread] = None
        

View on GitHub (pinned to b5b53acc57)

Solutions

  1. Provision ZEP_API_KEY (Zep Cloud project key) in the backend's environment and restart.
  2. If you did not intend to use graph memory, disable the Zep/graph-memory option in the simulation config so the updater is never constructed.
  3. Check for whitespace/quotes around the value in .env — it must be a non-empty string.

Example fix

# before
updater = ZepGraphMemoryUpdater(graph_id="sim_42", simulation_id="sim_42")  # ValueError

# after
# export ZEP_API_KEY=zep_live_xxx  (or set in .env)
updater = ZepGraphMemoryUpdater(graph_id="sim_42", simulation_id="sim_42")
# or explicitly:
updater = ZepGraphMemoryUpdater(graph_id="sim_42", simulation_id="sim_42", api_key=os.environ["ZEP_API_KEY"])
Defensive patterns

Strategy: validation

Validate before calling

def can_enable_graph_memory() -> bool:
    return bool(Config.ZEP_API_KEY)

Try / catch

try:
    ZepGraphMemoryManager.start_updater(sim_id, graph_id)
except ValueError as e:
    if "ZEP_API_KEY" in str(e):
        disable_graph_memory(sim_id)  # degrade gracefully or fail the start request
        raise HTTPException(400, detail="ZEP_API_KEY required for graph memory")
    raise

Prevention

When it happens

Trigger: Starting a simulation with graph memory (Zep) enabled while ZEP_API_KEY is unset in the backend process; constructing the updater programmatically without api_key; deploying with a different env file than the one containing the key.

Common situations: Graph-memory feature toggled on before credentials were provisioned; secrets not mounted in container deployments; local dev .env not loaded.

Related errors


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