CopilotKit icon indicating copy to clipboard operation
CopilotKit copied to clipboard

🐛 Bug: Agent called multiple times on tool call

Open deepakbatham572 opened this issue 3 weeks ago • 3 comments

♻️ Reproduction Steps

  1. Integrated google adk agent using litellm with openai with copilot kit performed the task using chat window.
  2. When agent used the tool from frontend we are getting "litellm.BadRequestError: OpenAIException"

with this complete message : Background execution error: litellm.BadRequestError: OpenAIException - **An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. The following tool_call_ids did not have response messages: call_eZ7cNEX35wdjtOCrZgqX5ZJg**

however when we check the payload which is sending my copiliotkit it is having name toolCallId and due to the key mismatch we are getting error and not able to interate with fornted tool

Payload:

{"threadId":"335a2c91-74bb-4b61-9779-a89d89c1666d","runId":"dcf78133-d9cc-401b-b7f0-ced83847acd5","tools":[{"name":"uploadTestCaseFileHITL","description":"Ask the user to upload a test case file via a form UI.","parameters":{"type":"object","properties":{},"required":[]}}],"context":[],"forwardedProps":{"config":{},"threadMetadata":{}},"state":{"file_path":"","test_cases":"","json_response":"","similarity_response":"","similarity_explanation_response":"","effectiveness":"","full_report":"","status":"idle","current_agent":"","current_step":0,"total_steps":7,"step_description":"","progress_percentage":0},"messages":[{"id":"ck-e5035828-3b1b-447c-8ae0-57a41657e764","role":"system","content":"\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n```\n\n\n\n```\n\nThey have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.\n\nPlease assist them as best you can.\n\nYou can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.\n\nIf you would like to call a function, call it without saying anything else.\nIn case of a function error:\n- If this error stems from incorrect function parameters or syntax, you may retry with corrected arguments.\n- If the error's source is unclear or seems unrelated to your input, do not attempt further retries.\n\n\nYou are a test optimization assistant. When you receive a file path, analyze the test cases and provide optimization recommendations."},{"id":"ck-5fadf83c-6668-4f00-a268-c69653c37b1a","role":"user","content":"Hi"},{"id":"06248bca-97e6-4d8a-9bb2-b2904bdd3c04","role":"assistant","content":"Hello! \n\nI’m set up specifically to help with **test case analysis and optimization** (e.g., reviewing test cases from a file, structuring them, finding duplicates/overlaps, suggesting optimizations).\n\nRight now your message isn’t a test case analysis request. \nIf you’d like to continue, you can, for example, send:\n\n- A file path to your test cases (CSV/Excel) \n- Or describe what you want analyzed, like: \n “I have a regression suite of 500 test cases in an Excel file at .../tests.xlsx. Help me optimize and de-duplicate them.”\n\nOnce you do, I’ll run the full test optimization flow for you."},{"id":"ck-8d488b67-3025-40aa-b408-a3277bd3091c","role":"user","content":"how to upload file ?"},{"id":"call_eZ7cNEX35wdjtOCrZgqX5ZJg","role":"assistant","toolCalls":[{"id":"call_eZ7cNEX35wdjtOCrZgqX5ZJg","type":"function","function":{"name":"uploadTestCaseFileHITL","arguments":"{}"}}]},{"id":"result-call_eZ7cNEX35wdjtOCrZgqX5ZJg","role":"tool","content":"{\"filePath\":\"C:/NEW/CO_TEST_OPTIMIZE/TestOptimization/uploads/1765377811203-TestCase.xlsx\",\"fileName\":\"TestCase.xlsx\"}","toolCallId":"call_eZ7cNEX35wdjtOCrZgqX5ZJg"}]}

Image

✅ Expected Behavior

keyname should be correct in the paylaod

❌ Actual Behavior

keyname mismatch

𝌚 CopilotKit Version

Γö£ΓöÇΓöÇ @copilotkit/[email protected]
Γö£ΓöÇΓöÇ @copilotkit/[email protected]
Γö£ΓöÇΓöÇ @copilotkit/[email protected]

📄 Logs (Optional)


deepakbatham572 avatar Dec 10 '25 14:12 deepakbatham572

@copilotkit-support

deepakbatham572 avatar Dec 12 '25 09:12 deepakbatham572

Hi @tylerslaton, can you please check this as well ?

deepakbatham572 avatar Dec 12 '25 11:12 deepakbatham572

Hi @tylerslaton, can you help for this one as well
we have tested this again, now the error is resolved from the LiteLLM exception but it is calling 2 times one on tool and one on append message

we have like this HITL funtion

useHumanInTheLoop({ name: "uploadTestCaseFileHITL", description: "Ask the user to upload a test case file via a form UI.", parameters: [], render: ({ respond, status }: { respond?: (result: string) => void; status: string }) => { return ( <form onSubmit={async (e) => { e.preventDefault(); if (!fileRef.current) { alert("Please select a file first."); console.log("Upload attempt with no file selected"); return; } setLocalUploading(true); console.log("Uploading file:", fileRef.current); const formData = new FormData(); formData.append("file", fileRef.current); try { const response = await fetch("/api/upload", { method: "POST", body: formData, }); if (response.ok) { const data = await response.json(); setLocalUploadedPath(data.filepath); console.log("Upload successful, path:", data.filepath); const uploadedFileName = fileRef.current ? fileRef.current.name : (localFile ? localFile.name : ""); fileRef.current = null; _setLocalFile(null); // Reset file after upload setLocalUploading(false); if (respond) { respond(JSON.stringify({ filePath: data.filepath, fileName: uploadedFileName })); } // Also append a message to the chat using useCopilotChat appendMessage && appendMessage(new TextMessage({ role: Role.User, content: Analyze this file: ${data.filepath} })); } else { alert("File upload failed."); console.log("Upload failed: response not ok"); } } catch (err) { alert("File upload failed."); console.log("Upload failed: error", err); } setLocalUploading(false); }} className="flex flex-col items-center justify-center p-4" > <div className="relative rounded-xl w-full max-w-md p-6 shadow-lg backdrop-blur-sm bg-gradient-to-br from-white via-gray-50 to-white border border-gray-200/80"> <h3 className="text-lg font-bold bg-gradient-to-r from-blue-600 to-purple-600 bg-clip-text text-transparent mb-4"> Please Upload Test Case File Here, so that I can help you optimize it! <input type="file" accept=".csv,.xlsx,.xls" onChange={e => { if (e.target.files && e.target.files[0]) { console.log("File selected:", e.target.files[0]); fileRef.current = e.target.files[0]; _setLocalFile(e.target.files[0]); } }} className="mb-4 block w-full text-sm text-gray-700 file:mr-4 file:py-2 file:px-4 file:rounded-lg file:border-0 file:text-sm file:font-semibold file:bg-gradient-to-r file:from-blue-500 file:to-indigo-600 file:text-white hover:file:from-blue-600 hover:file:to-indigo-700 file:cursor-pointer file:transition-all file:duration-200 file:shadow-md hover:file:shadow-lg" /> {localFile && ( <div className="mb-4 p-3 bg-blue-50 rounded-lg border border-blue-200"> <p className="text-sm text-gray-700 flex items-center gap-2"> <svg className="w-4 h-4 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" /> <span className="font-medium">Selected: <span className="font-semibold text-blue-800">{localFile.name}

)} <button type="submit" disabled={localUploading} className="w-full px-6 py-3 rounded-lg font-semibold transition-all duration-200 bg-gradient-to-r from-green-500 to-emerald-600 hover:from-green-600 hover:to-emerald-700 text-white shadow-lg hover:shadow-xl hover:scale-105 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:scale-100 flex items-center justify-center gap-2" > {localUploading ? ( <> <div className="animate-spin rounded-full h-4 w-4 border-2 border-white border-t-transparent"> Uploading... </> ) : ( <> <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12" /> Upload & Analyze </> )} {localUploadedPath && ( <div className="mt-4 p-3 bg-green-50 rounded-lg border border-green-200"> <p className="text-sm text-green-700 flex items-center gap-2"> <svg className="w-4 h-4 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" /> <span className="font-medium">Upload successful! )} ); }, });

on calling the tool it is calling agent and that is not working , once agent task done then it is going to append message then it's working

previously due to the litellm error the tool call is not happening that's why it was working one time for tool call message error and for append message it was calling agent

but not for both it is calling agent 1st with empty result and for 2nd corrent result adding full traces log file as well .

newe_log_file.log

deepakbatham572 avatar Dec 13 '25 17:12 deepakbatham572