saoudrizwan / claude-dev

Autonomous coding agent right in your IDE, capable of creating/editing files, executing commands, and more with your permission every step of the way.
https://marketplace.visualstudio.com/items?itemName=saoudrizwan.claude-dev
MIT License
4.04k stars 381 forks source link

Use streaming to capture partial response when claude fails to complete tool request (missing value for required param) to avoid infinite looping requests #127

Open marksolly opened 3 weeks ago

marksolly commented 3 weeks ago

I switched to another window while an API request was executing, came back several minutes later to find that it had been making the same expensive $0.12 requests in an infinite loop. Need to add a break condition that halts execution if the output token limit is reached.

Excerpt below, full log here: claude_dev_task_aug-18-2024_10-29-26-pm.md

---
**User:**

[Tool Result]
Error: Missing value for required parameter 'content'. Please retry with complete response.

---

**Assistant:**

I deeply apologize for the continued errors. Let me provide the complete content for the `index.js` file with the necessary changes to implement the URL update functionality:
[Tool Use: write_to_file]
Path: www/index.js

---

**User:**

[Tool Result]
Error: Missing value for required parameter 'content'. Please retry with complete response.

---

**Assistant:**

I sincerely apologize for the continued errors. I will now provide the complete content for the `index.js` file, including the changes to implement the URL update functionality:
[Tool Use: write_to_file]
Path: www/index.js

---

**User:**

[Tool Result]
Error: Missing value for required parameter 'content'. Please retry with complete response.
DioCali commented 3 weeks ago

I have exactly the same issue, I am not sure it's cause by the max_token_amount, but it's possible.

Used Openrouter with deepseek/deepseek-coder claude_dev_task_aug-21-2024_2-47-35-pm.md

IncreaseWebDev commented 2 weeks ago

Ran into this issue too while using the Anthropic Claude 3.5 sonnett API:

Error Claude tried to use write_to_file for 'index.html' without value for required parameter 'content'. This is likely due to output token limits. Retrying...

fry69 commented 2 weeks ago

Once your token limit is reached, you get errors back. Those errors will not get charged, but tools like Claude Dev might not know this and continue to count and show costs which do not exist.

You can easily verify this with e.g. looking your account billings page (which tracks real costs) -> https://console.anthropic.com/settings/plans and make a request after you reached your token limit for the day. You will see that you do not get charged.

marksolly commented 2 weeks ago

@fry69 This issue is caused by the output token limit, not the account token limit. If Claude tries to generate output longer than 8096 tokens this loop can be triggered. I have added the following custom instruction to see if it helps, but haven't encountered the loop again yet.

- If error "Error: Missing value for required parameter 'content'" is seen, output a diff of required code changes instead of using the write_to_file tool.
fry69 commented 2 weeks ago

@marksolly That does not change much, if an error gets returned, you will not get charged for it. Do not trust what the output tells you, check the actual account/billing page.

marksolly commented 2 weeks ago

:roll_eyes: Screenshot from 2024-08-24 22-12-08

fry69 commented 2 weeks ago

Thank you. This is indeed not okay and Claude Dev should try generate "infinite output" by putting the incomplete response as a prefill into the next request instead of sending the same request multiple times (I think that is how aider gets around this problem).

ProfessorGuineapig commented 2 weeks ago

I had the same problem. I asked for help with a simple issue, but the response created an infinite loop.claude_dev_task_aug-24-2024_1-01-35-am.md

aaronbferrell commented 2 weeks ago

Same prob

saoudrizwan commented 1 week ago

Claude Dev should try generate "infinite output" by putting the incomplete response as a prefill into the next request instead of sending the same request multiple times

When I get these tool results without values for required params, I don't even get a partial response back since I'm not streaming the request. I think streaming for the sake of capturing partial responses is the right approach here, instead of retrying the request hoping claude will give the full response.

namangupta44 commented 1 week ago

same issue, it should continue just after it reaches max output limit of 8192 tokens and not stuck in infinite loop.

saoudrizwan commented 1 week ago

I haven't addressed the main issue yet, but v1.5.19 now has a new error that prevents the infinite looping requests: Cursor 2024-09-03 21 43 35 This presents after Claude makes 3 mistakes in a row (mistakes mean invalid tool calls or no tool call whatsoever), so this should help you guide him in the right direction e.g. "break the file down into smaller files"

energy3d commented 1 week ago

API Request Failed

{ "error": { "message": "Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'.", "type": "invalid_request_error", "param": "messages.[41].role", "code": null } } And what to do about it? It is impossible to continue even with a change of model with another provider. It is not possible to continue or cancel the task

saoudrizwan commented 1 week ago

@energy3d what api provider/model are you using, and is this a task that you resumed from task history? any additional details how you got this error would be helpful

Update: if this was an older task, it's very possible it was manipulated by a previous context management algorithm that didn't order messages correctly. I suggest exporting the task (export button in the task header) and starting a new task asking claude to read that to get context to continue the task. If this was not an older task, please let me know.

techcow2 commented 1 day ago

@saoudrizwan This might be unrelated, but I wanted to mention that I noticed VS Code created an additional folder in my user directory called "Desktop." This was separate from my usual desktop folder and didn't have a "(1)" in the name. It was able to do this because my environment variables are still set to a OneDrive path for my desktop, even though I no longer use OneDrive. After installing Windows, I uninstalled OneDrive, but Windows still retains that environment variable. So, the path "C:\Users\username\OneDrive\Desktop" points to my actual desktop, while the one VS Code created is "C:\Users\username\Desktop." The key issue here is that I’ve noticed it's sometimes reading from or writing to the wrong path. This could potentially be contributing to the path error. (ref https://github.com/saoudrizwan/claude-dev/issues/146)