fix: preserve tool-call and tool-result parts in gen_ai.input.messages#890
Conversation
The transformPrompts function was converting all message content to text-only
parts, which lost important tool call information. This fix adds a new
processMessageParts function that properly preserves:
- Text parts: { type: "text", content: "..." }
- Tool-call parts: { type: "tool_call", tool_call: { id, name, arguments } }
- Tool-result parts: { type: "tool_result", tool_call_id, tool_name, content }
This allows observability tools to see the full context of tool interactions
in the gen_ai.input.messages attribute, including:
- Which tools were called (tool-call parts)
- What arguments were passed to tools
- What results were returned (tool-result parts)
Fixes traceloop#889
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe changes introduce a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed everything up to 1a9ce66 in 12 seconds. Click for details.
- Reviewed
126lines of code in1files - Skipped
0files when reviewing. - Skipped posting
0draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
Workflow ID: wflow_XT7Ge0XEfelftzf0
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/traceloop-sdk/src/lib/tracing/ai-sdk-transformations.ts`:
- Around line 253-276: In processMessageParts, the v4/v5 precedence is reversed
and a hyphenated-only check is missing for results: change the tool-call
handling to prefer v5 fields (use item.input ?? item.args instead of item.args
?? item.input) and change the tool-result handling to prefer v5 output (use
item.output ?? item.result instead of item.result ?? item.output); also make the
"tool-result" branch accept both "tool-result" and "tool_result" like the
tool-call branch so tool_result is handled symmetrically (update checks around
TYPE_TOOL_CALL / TYPE_TOOL_RESULT and the code that builds tool_call/tool_result
objects).
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/traceloop-sdk/src/lib/tracing/ai-sdk-transformations.ts
- Prefer v5 input over v4 args (item.input ?? item.args) - Prefer v5 output over v4 result (item.output ?? item.result) - Accept both 'tool-result' and 'tool_result' type values for symmetry with tool-call handling
Summary
This PR fixes an issue where the
transformPromptsfunction was converting all message content to text-only parts, which lost important tool call information in thegen_ai.input.messagesattribute.Problem
When using the Vercel AI SDK with traceloop instrumentation, tool interactions are captured in the prompt messages with different part types:
tool-callparts in assistant messages (containing tool name and arguments)tool-resultparts in tool messages (containing the tool output)However, the current
transformPromptsfunction usesprocessMessageContent()which extracts only text, losing all tool-call and tool-result information. This makes it impossible for observability tools to see:Solution
This PR adds a new
processMessagePartsfunction that properly preserves all part types:{ type: "text", content: "..." }{ type: "tool_call", tool_call: { id, name, arguments } }{ type: "tool_result", tool_call_id, tool_name, content }The
transformPromptsfunction now usesprocessMessageParts(msg.content)instead of creating text-only parts.Example
Before (broken)
[ {"role": "user", "parts": [{"type": "text", "content": "What's the weather?"}]}, {"role": "assistant", "parts": [{"type": "text", "content": ""}]}, {"role": "tool", "parts": [{"type": "text", "content": "tool-result"}]} ]After (fixed)
[ {"role": "user", "parts": [{"type": "text", "content": "What's the weather?"}]}, {"role": "assistant", "parts": [{"type": "tool_call", "tool_call": {"id": "call_123", "name": "getWeather", "arguments": "{\"city\": \"Seattle\"}"}}]}, {"role": "tool", "parts": [{"type": "tool_result", "tool_call_id": "call_123", "tool_name": "getWeather", "content": "{\"temp\": 65, \"conditions\": \"sunny\"}"}]} ]Backwards Compatibility
processMessageContentfunction is unchanged (used forgen_ai.prompt.X.content)Related Issue
Fixes #889
Pull Request opened by Augment Code with guidance from the PR author
Important
Fixes
transformPromptsto preserve tool-call and tool-result parts using newprocessMessagePartsfunction.transformPromptsnow usesprocessMessagePartsto preservetool-callandtool-resultparts ingen_ai.input.messages.processMessagePartshandlestext,tool-call, andtool-resultparts, ensuring all are preserved.processMessagePartsto handle message content, preserving tool interaction data.transformPromptsto useprocessMessagePartsinstead ofprocessMessageContent.TYPE_TOOL_RESULTconstant for consistency in part type handling.This description was created by
for 1a9ce66. You can customize this summary. It will automatically update as commits are pushed.
Summary by CodeRabbit