File size: 837 Bytes
4156529 9f1c9d5 4156529 9f1c9d5 4156529 9f1c9d5 4156529 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | """Process-wide shared state.
This module holds the cached agent instances in a single, neutral location.
Both the FastAPI auth app and the LangGraph graph import this module the same
way (``utils.shared_state``), guaranteeing there is only ONE copy of the state
in the running process.
Do NOT store this state in ``web/login.py`` — the LangGraph server imports
that file under multiple module names, which would create duplicate module
objects each with their own independent state.
"""
from __future__ import annotations
import asyncio
from typing import Any
# Cached agent instances keyed by agent name. All agents are shared singletons
# built with the server-wide HF_TOKEN environment variable.
agents: dict[str, Any] = {}
# Guards concurrent first-time initialization of the same agent.
locks: dict[str, asyncio.Lock] = {}
|