Skip to content

Commit 74c87ef

Browse files
authored
Remove double stringify for string tool result (#537)
1 parent 93fb927 commit 74c87ef

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

.changeset/olive-ears-live.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@livekit/agents-plugin-openai': patch
3+
---
4+
5+
remove duplicated stringify for string tool output

plugins/openai/src/llm.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,9 @@ const buildMessage = async (msg: llm.ChatMessage, cacheKey: any) => {
638638

639639
if (msg.role === llm.ChatRole.TOOL) {
640640
try {
641-
const toolCallOutput = JSON.stringify(msg.content);
642-
oaiMsg.content = toolCallOutput;
641+
const serializedContent =
642+
typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content);
643+
oaiMsg.content = serializedContent;
643644
} catch (e) {
644645
throw Error(`Tool call output is not JSON serializable: ${e}`);
645646
}

0 commit comments

Comments
 (0)