Skip to content

Commit 3112d75

Browse files
authored
fix(traceloop-sdk): ai sdk transform response tool calls (#866)
1 parent c6655da commit 3112d75

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

packages/traceloop-sdk/src/lib/tracing/ai-sdk-transformations.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -145,25 +145,23 @@ const transformResponseToolCalls = (attributes: Record<string, any>): void => {
145145

146146
const toolCallParts: any[] = [];
147147
toolCalls.forEach((toolCall: any, index: number) => {
148-
if (toolCall.toolCallType === "function") {
149-
// Support both v4 (args) and v5 (input) formats
150-
// Prefer v5 (input) if present
151-
const toolArgs = toolCall.input ?? toolCall.args;
152-
153-
attributes[`${ATTR_GEN_AI_COMPLETION}.0.tool_calls.${index}.name`] =
154-
toolCall.toolName;
155-
attributes[
156-
`${ATTR_GEN_AI_COMPLETION}.0.tool_calls.${index}.arguments`
157-
] = toolArgs;
158-
159-
toolCallParts.push({
160-
type: TYPE_TOOL_CALL,
161-
tool_call: {
162-
name: toolCall.toolName,
163-
arguments: toolArgs,
164-
},
165-
});
166-
}
148+
// Support both v4 (args) and v5 (input) formats
149+
// Prefer v5 (input) if present
150+
const toolArgs = toolCall.input ?? toolCall.args;
151+
152+
attributes[`${ATTR_GEN_AI_COMPLETION}.0.tool_calls.${index}.name`] =
153+
toolCall.toolName;
154+
attributes[
155+
`${ATTR_GEN_AI_COMPLETION}.0.tool_calls.${index}.arguments`
156+
] = toolArgs;
157+
158+
toolCallParts.push({
159+
type: TYPE_TOOL_CALL,
160+
tool_call: {
161+
name: toolCall.toolName,
162+
arguments: toolArgs,
163+
},
164+
});
167165
});
168166

169167
if (toolCallParts.length > 0) {

0 commit comments

Comments
 (0)