hack to return tool call errors back to model

This commit is contained in:
Dax Raad
2025-08-04 11:59:42 -04:00
parent b05decc572
commit 0a42068fbb
4 changed files with 41 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ import {
type ModelMessage,
stepCountIs,
type StreamTextResult,
InvalidToolInputError,
} from "ai"
import PROMPT_INITIALIZE from "../session/prompt/initialize.txt"
@@ -869,7 +870,21 @@ export namespace Session {
messages,
}
},
async experimental_repairToolCall(input) {
if (InvalidToolInputError.isInstance(input.error)) {
return {
...input.toolCall,
input: JSON.stringify({
tool: input.toolCall.toolName,
error: input.error.message,
}),
toolName: "invalid",
}
}
return null
},
maxRetries: 3,
activeTools: Object.keys(tools).filter((x) => x !== "invalid"),
maxOutputTokens: outputLimit,
abortSignal: abort.signal,
stopWhen: stepCountIs(1000),
@@ -962,6 +977,7 @@ export namespace Session {
if (match) {
const part = await updatePart({
...match,
tool: value.toolName,
state: {
status: "running",
input: value.input,