feat: trace reasoning content and offered tools on generations - #37
Open
Ali-Aleph-Alpha wants to merge 1 commit into
Open
Ali-Aleph-Alpha wants to merge 1 commit into
Ali-Aleph-Alpha wants to merge 1 commit into
Conversation
Generation output now carries the model's reasoning as Langfuse thinking blocks next to the answer text: - structured thinking blocks from pi's message content are included in the generation output (previously only in the history input) - reasoning streamed inline as <think> tags (vLLM default, DeepSeek distill, and other OpenAI-compatible servers that do not send a structured reasoning field) is split out of the answer text; an unclosed tag is treated as reasoning until the end of the stream - structured blocks win over inline tags so a model emitting both is not traced twice - thinking content goes through the secret redactor, since models regularly quote file contents (including .env) into their reasoning - thinkingSignature stays untraced (provider replay data) Time to first token now counts thinking tokens, which reasoning models stream before any text. Each generation also records the tool definitions the model was called with (name, description, parameter schema) as available_tools metadata, and the turn root lists the active tool names, so a trace can distinguish 'tool not offered' from 'tool not chosen'. Note: the available_tools part overlaps with langfuse#34 (which attaches tool definitions to the generation input for playground replay). Happy to drop it in favor of langfuse#34 and keep only the reasoning changes.
Ali-Aleph-Alpha
force-pushed
the
feat/reasoning-and-tools
branch
from
September 15, 2026 13:28
af4b7bb to
03a1ff2
Compare
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.
Change
Traces recorded the model's answer text but not its reasoning:
thinkingblocks were extracted for the history input but dropped from the generation output, so a Langfuse trace showed token counts for reasoning (output_reasoning_tokens) without the reasoning itself.Generation output now carries the reasoning as Langfuse thinking blocks (
{ type: "thinking", content }, the same ChatML shape the history input already uses, which Langfuse renders as collapsible reasoning blocks):<think>tags — the vLLM default and common on OpenAI-compatible servers that do not send a structuredreasoningfield — is split out of the answer text. An unclosed tag (aborted stream) is treated as reasoning until the end. Structured blocks win over inline tags so a model emitting both is not traced twice..env) into their reasoning.thinkingSignaturestays untraced (provider replay data; already covered by an existing test).Time to first token now counts thinking tokens, which reasoning models stream before any text — previously TTFT was inflated by the full reasoning phase.
Each generation also records the tool definitions the model was called with (name, description, parameter schema) as
available_toolsmetadata, and the turn root lists the active tool names, so a trace can distinguish "tool not offered" from "tool not chosen".Notes
available_toolspart overlaps with feat: attach the offered tool definitions to every generation #34 (which attaches tool definitions to the generation input for playground replay, closing Attach tool definitions to generations #23). Happy to drop it in favor of feat: attach the offered tool definitions to every generation #34 and keep only the reasoning changes.<think>tags inline.Test plan
pnpm typecheck,pnpm test(111 tests: unit + integration against the real pi CLI with a mock provider and a fake Langfuse ingest)readAvailableToolsfiltering and older-pi fallback, integration assertions for thinking in generation output andavailable_toolsmetadata