Completing a tool call turn with Vercel AI SDK
Unanswered
ascee posted this in #help-forum
asceeOP
I am making an agent that can chain multiple tool calls. Right now I just have 2 simple tools, 1st that lists a bunch of assets available, and 2nd that allows the agent to do something with the asset. It is able to perform 1, mark the tool call state as "result", but it does not change the state of the 2nd to "result" and it hangs at state "call". What can I do to ensure we mark the last tool as complete after the action is performed?
snippet:
snippet:
const handleRemoveFile = (args: RemoveFile) => {
const trackItem = getTrackItemForUpload(
uploads.find((u) => u.id === args.asset_id) as Upload
);
await deleteFile(trackItem)
};
const {
messages,
setMessages,
addToolResult,
handleSubmit,
input,
setInput,
isLoading,
stop,
} = useChat({
api: "http://localhost:8000/v1/chat",
onResponse: (response) => {
console.log("Response:", response);
},
streamProtocol: "data",
onToolCall: (response) => {
console.log("toolcall", response);
const toolName = response.toolCall.toolName as ToolCallName;
if (toolName === "remove_file") {
handleInsertAsset(response.toolCall.args as InsertAssetArgs);
}
if (toolName === "list_all_files") {
// this is done on the server and fed into the context + streamed to the ui to indicate a tool call being done.
return "listed all files, let's ask the user for the next step";
}
},
maxSteps: 3,
id: chatId,
initialMessages: existingMessages,
body: {
project_id: currentProject?.id,
workspace_id: currentProject?.workspace_id,
user_id: user?.id,
chat_id: chatId,
},
});