""" modules/langgraph_adapter.py Minimal LangGraph orchestration hook for IntelliForm Enterprise. """ from __future__ import annotations from dataclasses import asdict, dataclass from typing import Dict, List, TypedDict try: from langgraph.graph import END, START, StateGraph LANGGRAPH_OK = True except ImportError: END = START = StateGraph = None LANGGRAPH_OK = False class IntegrationState(TypedDict): platform: str usable_smiles_count: int route: str steps: List[str] @dataclass class LangGraphSummary: active: bool route: str steps: List[str] notes: List[str] def to_dict(self) -> dict: return asdict(self) def orchestrate_public_stack(platform: str, usable_smiles_count: int) -> LangGraphSummary: if not LANGGRAPH_OK: return LangGraphSummary( active=False, route="", steps=[], notes=["LangGraph is not installed in the current runtime."], ) def initialize(state: IntegrationState) -> IntegrationState: state["steps"] = ["normalize"] return state def choose_route(state: IntegrationState) -> IntegrationState: if state["platform"] == "orbitchem": state["route"] = "materials-escalation" elif state["platform"] == "printchem": state["route"] = "polymer-escalation" elif state["usable_smiles_count"] > 0: state["route"] = "molecular-escalation" else: state["route"] = "availability-only" state["steps"].append(state["route"]) return state graph = StateGraph(IntegrationState) graph.add_node("initialize", initialize) graph.add_node("choose_route", choose_route) graph.add_edge(START, "initialize") graph.add_edge("initialize", "choose_route") graph.add_edge("choose_route", END) compiled = graph.compile() final_state = compiled.invoke( {"platform": platform, "usable_smiles_count": usable_smiles_count, "route": "", "steps": []} ) return LangGraphSummary( active=True, route=final_state["route"], steps=final_state["steps"], notes=[ "LangGraph orchestration is active for stateful routing across the public integration stack.", ], )