Plan: LangChain + LangGraph as the Framework-Wide Engine¶
- Spec: spec.md (027-langchain-langgraph-default)
- Approach: one shared transport module first, then route existing agents
through it, then flip defaults last (so every default-path consumer already sits on the resilient transport when the flip lands). All changes additive; the
use_langgraph=falseescape hatch preserves prior behavior.
Steps¶
- Shared transport — new
backend/law_ai/agents_runtime/llm.py:build_chat_ollama()(ChatOllama +with_retry: 3 attempts, exponential jitter, transient-error allowlist incl.ollama.ResponseError),generate_text_sync(),coerce_text(), TTL-cachedollama_available()+ollama_available_async()(shared cache, 1 s probe, 15 s TTL),LLMUnavailableErrorfor bare installs,reset_probe_cache()test helper. - LegalWorkflow —
_default_llm_factorydelegates tobuild_chat_ollama()(drops its private ChatOllama construction). - LegalAnalyst —
_run_via_langgraphgains the resilience boundary: async availability probe → degraded[ENGINE UNAVAILABLE]refusal (loggedfallback/offline), try/except around the workflow for ImportError/transport errors → same degraded contract. New module-level_langgraph_fallback_irac(). - Default flip —
AnalysisRequest.use_langgraphdefaulttrue; frontend toggles (AnalysisStudio,AgentDashboard) default on, withAnalysisStudiosending the explicit boolean (omission would re-enable the engine server-side after user opt-out). - TestSynthesizer —
_call_ollamainternals swap togenerate_text_sync; name/signature/RuntimeError contract preserved (tests patch that seam). - TopicFrontier —
_build_graph()compiles the realStateGraph(TopicFrontierState)with async closures binding the DI collaborators;run()prefersgraph.ainvoke,_run_sequential()fallback on ImportError;_call_ollama→ shared transport; prioritize node logs its LLM call viaprovenance.log_agent_call(model, latency, prompt id/version). - Review-driven fixes (from the spec-026 adversarial review, applied in
this cycle since they touch the same files): phoenix healthcheck exec-form (distroless image has no
/bin/sh), backend debug-override command folding (continuation indentation brokesh -cinto two commands), de-vacuumed HITL threshold test, zero-citations conclusion branch.
Test strategy¶
- New
tests/agents/test_llm_runtime.py: retry wrapper shape, bare-model escape, JSON mode, probe caching (sync + async shared cache). - New
TestLangGraphDefaultEngineintests/agents/test_legal_analyst.py: probe-fail degrade, workflow-crash degrade, request-default assertion. tests/agents/graphs/test_topic_frontier.py: transport-error contract via the LangChain seam; StateGraph compilation + run-through-graph tests.- Existing suites must stay green unmodified except where they encoded the old defaults/transports.
Rollback¶
Git revert; no migrations. Flipping use_langgraph default back restores the old routing without touching the transport layer.