fix(langchain): preserve tool calls in generation traces - #3038
Open
Kuang-xianxin wants to merge 1 commit into
Open
Kuang-xianxin wants to merge 1 commit into
Kuang-xianxin wants to merge 1 commit into
Conversation
Keep normalized tool calls and tool-result IDs in both message conversion paths. Cover real async callback events and legacy provider message formats. Co-Authored-By: Codex <noreply@openai.com>
Kuang-xianxin
requested review from
asvishnyakov,
hayescode and
sandangel
as code owners
September 5, 2026 12:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem and change
LangChain exposes provider-independent tool calls in
AIMessage.tool_callsand correlates results throughToolMessage.tool_call_id. Chainlit's generation converter drops both: a message such asAIMessage(content="", tool_calls=[{"name": "weather", "args": {"city": "Paris"}, "id": "call_1"}])is recorded as an empty assistant message, and its tool result losescall_1.Preserve normalized call IDs, names and arguments, and the tool-result ID, for both live messages and LangChain's serialized constructor dictionaries. Prefer normalized calls when a provider also puts the same calls in content blocks, so Anthropic calls are not duplicated. Existing text content, legacy
function_call, and content-only Anthropictool_usehandling are retained. This repairs generation tracing; it does not change agent tool execution.Validation
PYTHONPATH=backend uv run --no-sync pytest backend/tests/langchain backend/tests/test_step.py -q(Python 3.13.14, LangChain Core 1.2.27, LiteralAI 0.1.201).AsyncCallbackManagerthrough start/end events and inspects the resulting generation payload, without a model API request.Found through source inspection; searches for LangChain/tool-call PRs did not identify an overlapping open fix. No existing issue is claimed as resolved.
No manual browser verification was performed.
Summary by cubic
Fixes LangChain generation tracing so tool calls and tool-result IDs are preserved in the persisted step.
name,args,id) fromAIMessage.tool_callsin both live and serialized message conversion.tool_call_idon tool result messages so calls and results stay correlated.tool_useentries.function_call, and content-only Anthropic handling.Written for commit 45bae9d. Summary will update on new commits.