feat(langchain): add v1 support #680
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Important
Update Langchain to v1, refactor
CallbackHandlerfor new message types, and adjust tests accordingly.@langchain/coreto^1.0.1,@langchain/langgraphto^1.0.1, and@langchain/openaito^1.0.0inpackage.json.instanceofchecks withgetType()for message type inCallbackHandler.extractChatMessageContent()to handle new message types.langchain.e3e.test.tsto reflect changes in message handling and tool call structure.langchain.e3e.test.ts.This description was created by
for 5c0925c. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Overview
Updated On: 2025-10-25 17:45:16 UTC
Greptile Summary
This PR upgrades LangChain dependencies from v0.x to v1.x (
@langchain/core,@langchain/langgraph, and@langchain/openai).Key changes:
instanceofchecks with.getType()method calls for message type detection (e.g.,message instanceof HumanMessage→message.getType() === "human")ChatMessage,FunctionMessage,HumanMessage,SystemMessage,ToolMessage)tool_callsfrommessage.additional_kwargsfunctionpropertyinstanceof BaseMessagecheck before type casting inhandleLLMEndIssues found:
extractChatMessageContent(lines 870-876)console.logleft in test fileConfidence Score: 3/5
additional_kwargs.tool_callsunconditionally overwritesmessage.tool_callsif both exist. The removedinstanceof BaseMessagecheck could also cause type safety issues. The debug console.log is a minor style issue.packages/langchain/src/CallbackHandler.tslines 870-876 where tool_calls handling may overwrite valid dataImportant Files Changed
File Analysis
instanceofchecks with.getType()calls for v1 compatibility; adds tool_calls handling from additional_kwargs but has potential overwrite issue on line 870-876functionproperty); includes debug console.log that should be removedSequence Diagram
sequenceDiagram participant LC as LangChain v1 participant CB as CallbackHandler participant LF as Langfuse LC->>CB: handleChatModelStart(messages) CB->>CB: extractChatMessageContent(message) Note over CB: Uses message.getType() instead of instanceof CB->>CB: Check message type (human/ai/system/tool/function) alt AI Message with tool_calls CB->>CB: Check message.tool_calls exists CB->>CB: Set response.tool_calls from message.tool_calls CB->>CB: Check additional_kwargs.tool_calls Note over CB: ⚠️ May overwrite existing tool_calls CB->>CB: Set response.tool_calls from additional_kwargs end CB->>LF: startObservation(extracted messages) LC->>CB: handleLLMEnd(output) CB->>CB: Extract lastResponse.message Note over CB: Cast to BaseMessage without instanceof check CB->>CB: extractChatMessageContent(message) CB->>LF: Update observation with output Note over LC,LF: Tool calls structure changed: <br/>v0.x: tool_calls[0].name<br/>v1.x: tool_calls[0].function.name