Conversation
milanagm
force-pushed
the
feat/tool-definitions-on-generations
branch
from
September 11, 2026 10:42
5e9dc03 to
360228a
Compare
hassiebp
approved these changes
Sep 14, 2026
hassiebp
left a comment
Collaborator
There was a problem hiding this comment.
LGTM after resolved conflicts 👍
milanagm
force-pushed
the
feat/tool-definitions-on-generations
branch
from
September 15, 2026 11:20
360228a to
39e3d09
Compare
Collaborator
Author
|
@hassiebp resolved |
Ali-Aleph-Alpha
added a commit
to Ali-Aleph-Alpha/pi-observability-plugin
that referenced
this pull request
Sep 15, 2026
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.
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.
Closes #23.
LFE-16207
Change
A trace recorded which tools the model called —
tool_callson the generation output,Tool: <name>spans — but not which tools it was offered, so it could not distinguish "not offered" from "not chosen", and the Langfuse playground had no tools to replay a generation with.Each generation input now carries the definitions of the tools in the request as
toolson its first message, which is where the Langfuse UI reads them and dedupes by name.The set is pi's active tools, which is narrower than the registry. Measured on pi 0.84.2 with a probe on
before_provider_request, readingevent.payload(the real wire request):So
getAllTools()alone would over-report by four tools. The active names drive both membership and order, since that is what goes on the wire; the registry only supplies each schema. Both accessors are optional-chained and the helper never throws, so a pi without them degrades to no tools.The generation input is now a ChatML message array
This is the part that makes the feature actually visible, and it is a fix in its own right.
The generation input was a bare message object. Langfuse normalizes generation input with
ChatMlArraySchema, and its single-message fallback (langfuse#16565) only accepts a message carryingcontentortool_calls. pi's generations after a tool call are{role: "tool", tool_results: [...]}, which match neither — so they fail to parse, fall back to the raw JSON view, and drop the tool definitions entirely.Verified by replaying the real captured payloads of a three-generation turn through Langfuse's own normalizer at current
main, plus the Tools-section logic fromuseChatMLParser:mainrole: "user"role: "tool"role: "tool"Wrapping the message in a one-element array fixes all three, and keeps the input composable with any later change that turns it into a real message list.
Tests
pnpm typecheckclean;pnpm test67 of 67 passed, up from 62 onmain.["read", "bash", "edit", "write"]with their schemas.