fix(langchain): preserve tool calls in generation traces - #3038
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>
|
This PR is stale because it has been open for 14 days with no activity. |
|
Rechecked this on September 23 against current The same selection on this PR's unchanged head ( Environment: Windows, CPython 3.13.14, LangChain Core 1.2.27 and LiteralAI 0.1.201. No model API calls were made; frontend/E2E and live-provider tests were not run. The patch remains limited to the converter and its two test files. Could a maintainer keep this open for review and approve the pending CI workflow? Thanks! |
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.