Repository navigation
fix(langsmith): record reasoning tokens as completion_reasoning_tokens - #2844
Open
BASIL K AJI (basil-k-aji-dev) wants to merge 1 commit into
Open
BASIL K AJI (basil-k-aji-dev) wants to merge 1 commit into
BASIL K AJI (basil-k-aji-dev) wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Summary
The LangSmith instrumentation extracted
prompt_cached_tokensandprompt_cache_creation_tokensfromusage_metadata.input_token_detailsbut never readoutput_token_details, so reasoning tokens were missing from LangSmith-routed traces. The LangChain handler already reads the same shape and emitscompletion_reasoning_tokens.extractMetricsnow recordscompletion_reasoning_tokensfromusage_metadata.output_token_details.reasoning, using the file's existingassignFirstMetrichelper (a finite number >= 0 is recorded, so0is kept; strings and absent values are skipped).Tests
langsmith-instrumentation.test.ts: the lifecycle test now carriesoutput_token_details: { reasoning: 7 }and expectscompletion_reasoning_tokens: 7, and a new test covers0, nooutput_token_details, a string, andreasoningonly underinput_token_details.check:typings,lint, the formatting check andvalidate-changesetsare clean.input_token_details, a wrong metric name, dropping zeros or accepting strings each fail a test.providersdirectory passes apart from a 15s timeout inlivekit-plugin.test.ts, which does not touch this code and passes on its own.Things to know
prompt_tokens_details.cached_tokens, so I expect no snapshot drift, but I could not run the e2e scenarios locally. Re-recording against a real OpenAI response could addcompletion_reasoning_tokens: 0to those snapshots.audioentries, service-tier-prefixed keys such asflex_reasoning, and the*_costfields); I kept this to reasoning tokens.