"""GraphContext -- typed wrapper around the compiled graph and its dependencies.""" from __future__ import annotations from dataclasses import dataclass from typing import TYPE_CHECKING if TYPE_CHECKING: from langgraph.graph.state import CompiledStateGraph from app.intent import ClassificationResult, IntentClassifier from app.registry import AgentRegistry @dataclass(frozen=True) class GraphContext: """Bundles the compiled LangGraph graph with its associated services. Replaces the previous pattern of monkey-patching attributes onto the third-party CompiledStateGraph instance. """ graph: CompiledStateGraph registry: AgentRegistry intent_classifier: IntentClassifier | None = None async def classify_intent(self, message: str) -> ClassificationResult | None: """Classify user intent using the attached classifier. Returns None if no classifier is configured. """ if self.intent_classifier is None: return None agents = self.registry.list_agents() return await self.intent_classifier.classify(message, agents)