Skip to content

Commit ad13b42

Browse files
authored
✨ feat: improve error handling for duplicate tools (#1395)
Added structured error handling for duplicate tools in chat sessions.
1 parent 387b0d1 commit ad13b42

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

packages/core/src/chat.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,13 +1166,21 @@ export async function executeChatSession(
11661166
(name, index) => toolNames.lastIndexOf(name) !== index
11671167
)
11681168
if (duplicates.length) {
1169-
throw new Error(`duplicate tools: ${duplicates.join(", ")}`)
1169+
chatTrace.error(`duplicate tools: ${duplicates.join(", ")}`)
1170+
return {
1171+
error: serializeError(
1172+
`duplicate tools: ${duplicates.join(", ")}`
1173+
),
1174+
finishReason: "fail",
1175+
messages,
1176+
text: "",
1177+
}
11701178
}
11711179
}
11721180
while (true) {
11731181
stats.turns++
11741182
collapseChatMessages(messages)
1175-
dbg(`chat: turn ${stats.turns}`)
1183+
dbg(`turn ${stats.turns}`)
11761184
if (messages) {
11771185
chatTrace.details(
11781186
`💬 messages (${messages.length})`,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
defTool("mytool", "same", {}, () => {
2+
return "same"
3+
})
4+
// trigger
5+
defTool("mytool", "same", {}, () => {
6+
return "same"
7+
})
8+
$`Show mytool output.`

0 commit comments

Comments
 (0)