Skip to content

Commit 26458d4

Browse files
feat(closes OPEN-11315): modernize the LangChain/LangGraph callback handler for v1
Modernizes the sync + async Openlayer LangChain/LangGraph callback handler for LangChain v1 (OPEN-11315). The callbacks API stayed backwards-compatible across v1, so these are gap-fills and modernizations rather than a migration. High-priority fixes: - Wire on_retriever_start/end/error into the sync handler (previously only the async handler had them) so synchronous RAG pipelines produce a RETRIEVER step and populate the context column; fall back to the handler-owned trace when a root-level retriever has no external trace context. - Fall back to serializing AIMessage.tool_calls in _extract_output when the generation text is empty, and preserve tool_calls in _message_to_dict, so tool-only agent turns no longer record empty output. Modernization: - Tokens: read AIMessage.usage_metadata first, then llm_output / generation_info; capture input/output token details (cache_read, cache_creation, reasoning) under step metadata. - Provider: use metadata["ls_provider"] as the primary source (mapped to Openlayer provider names), with the _type map and LiteLLM prefixes as fallbacks. - LangGraph metadata: chain steps prefer the runnable's own name, falling back to langgraph_node, then the serialized id (matching the TS handler) so node internals keep their real names; metadata["thread_id"] auto-maps to session_id unless an explicit session is set (opt-out via map_thread_id_to_session). - v1 content blocks: normalize list / content-block message content (text joined into content, non-text blocks preserved under content_blocks). - Drop the removed langchain.schema / langchain.callbacks.base import fallback; import from langchain_core only. Tests: - Add an offline test suite for the handler (real langchain_core objects, publishing disabled). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 88891a0 commit 26458d4

4 files changed

Lines changed: 889 additions & 157 deletions

File tree

0 commit comments

Comments
 (0)