Skip to content

fix(server-utils): Map Flue messages and token usage to the gen_ai conventions - #24992

Draft
JPeer264 wants to merge 1 commit into
developfrom
jp/flue-map-messages-conventions
Draft

JPeer264 wants to merge 1 commit into
developfrom
jp/flue-map-messages-conventions

Conversation

@JPeer264

@JPeer264 JPeer264 commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Flue records the messages of its turns in pi-ai's own shape, with a toolResult role and toolCall parts. Sentry's AI views only render the gen_ai conventions shape, so tool calls and tool results were missing from Flue conversations, and the tool result showed up with an invalid role. This maps the input and output messages to the conventions, the way #24352 did for Google GenAI.

The token counts come from pi-ai too. Its input leaves the cached tokens out, while gen_ai.usage.input_tokens includes them by definition, so input tokens and input cost were too low whenever prompt caching was active (the default for Anthropic models). The finish reason is mapped as well (toolUse becomes tool_call), and the tool span now records the result the model receives (Flue's effectiveResult) instead of the internal { content, details } wrapper.

The mapper lives in ai/pi-ai/ because pi-durable sends the same shapes, and its integration uses it too.

🤖 Generated with Claude Code

@JPeer264
JPeer264 added this pull request to stack #25002 October 2, 2026 13:14
@JPeer264
JPeer264 removed this pull request from stack #25002 October 2, 2026 13:31
@JPeer264
JPeer264 added this pull request to stack #25004 October 2, 2026 13:57
…nventions

Flue records its turn messages in pi-ai's shape, with a `toolResult` role
and `toolCall` parts, and Sentry renders neither, so tool calls and tool
results were missing from the conversation views. Its token counts come
from pi-ai too, whose `input` leaves the cached tokens out while the
conventions count them in, so input tokens and input cost were too low
whenever prompt caching was active. A shared pi-ai mapper now translates
messages, usage and the finish reason to the conventions, and the tool
span records the result the model receives instead of Flue's internal
result wrapper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@JPeer264
JPeer264 force-pushed the jp/flue-map-messages-conventions branch from 3a5576b to 203f215 Compare October 3, 2026 16:23
@JPeer264 JPeer264 changed the title fix(server-utils): Map Flue messages to the gen_ai conventions fix(server-utils): Map Flue messages and token usage to the gen_ai conventions Oct 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant