CLI becomes broken after a tool returns an error when using Claude
I was setting up the github mcp and (for some still unknown reason) it's returning a permissions error. When using OpenAI, I see the permissions error, but when using Claude I see this:
2025-03-10T21:05:22.625757Z ERROR goose::agents::truncate: Error: Request failed: Request failed with status: 400 Bad Request. Message: messages.35: Messages containing `tool_use` blocks must be followed by a user message with `tool_result` blocks
at crates/goose/src/agents/truncate.rs:396
Ran into this error: Request failed: Request failed with status: 400 Bad Request. Message: messages.35: Messages containing `tool_use` blocks must be followed by a user message with `tool_result` blocks.
Please retry if you think this is a transient or recoverable error.
No other prompts succeed after hitting this and I have to close the CLI.
To Reproduce Steps to reproduce the behavior:
- Set your config:
GOOSE_PROVIDER: anthropic
GOOSE_MODEL: claude-3-7-sonnet-latest
extensions:
github:
args:
- -y
- '@modelcontextprotocol/server-github'
cmd: npx
enabled: true
envs: {}
name: github
timeout: 300
type: stdio
- Do not set a github auth token
- Make a prompt like "Tell me about this github issue https://github.com/block/fakerepo/issues/1102"
Expected behavior Show the error like the OpenAI provider does:
Execution failed: RPC error: code=-32603, message=Not Found: Resource not found: Not Found
It seems that the GitHub issue you mentioned does not exist or the repository `block/fakerepo` could not be found. Please make sure the repository and issue number are correct, or check if the repository is private and requires appropriate access permissions.
The CLI should still be usable after the error.
Screenshots If applicable, add screenshots to help explain your problem.
Please provide following information:
- OS & Arch: Mac OSX
- Interface: CLI
- Version: v1.0.12
- Extensions enabled: developer, fetch, github, stripe
- Provider & Model: [e.g. Google - gemini-1.5-pro]
Additional context Add any other context about the problem here.
Related #1624 - error handling: tool call errors shouldn't take down the entire session, we should provide a way to recover
hey @trobrock trying to replicate this in a minimal case, but seemingly unable to, i've verified i don't have GITHUB_PERSONAL_ACCESS_TOKEN set either. are you ctrl-cing anywhere in the steps?
goose session
Goose is running! Enter your instructions, or try asking what goose can do.
( O)> Tell me about this github issue https://github.com/block/fakerepo/issues/1102
I'll look up information about this GitHub issue for you. Let me fetch the details.
─── get_issue | github ──────────────────────────
issue_number: 1102
owner: block
repo: fakerepo
Execution failed: RPC error: code=-32603, message=Not Found: Resource not found: Not Found
I apologize, but I wasn't able to find the GitHub issue you're looking for. The issue `https://github.com/block/fakerepo/issues/1102` doesn't appear to exist. This could be due to one of these reasons:
1. The repository "fakerepo" doesn't exist under the Block organization
2. The issue #1102 doesn't exist in that repository
3. The repository might be private and not accessible
Would you like me to:
1. Search for a different issue number?
2. Check if the repository exists?
3. Look for issues in a different repository?
Please provide the correct repository name and issue number, and I'll be happy to look it up for you.
( O)> hello
# Hello!
Welcome! I'm Goose, an AI assistant. How can I help you today? I can assist with a variety of tasks, including:
- Working with GitHub repositories and issues
- Editing and working with code files
- Running shell commands
- Answering questions
Is there something specific you'd like help with? Feel free to let me know what you're working on or what information you need.
( O)>
No I wasn't Ctrl-C'ing at all. You are using Claude for this?
@trobrock yes, was using claude-3.7-sonnet
I got the same error with goose CLI v1.0.15 using:
- provider: openrouter
- model: google/gemini-2.0-flash-001
Error:
2025-03-19T19:48:10.908507Z ERROR goose::agents::truncate: Error: Request failed: Request failed with status: 400 Bad Request. Message: Provider returned error
at crates/goose/src/agents/truncate.rs:461
Ran into this error: Request failed: Request failed with status: 400 Bad Request. Message: Provider returned error.
Please retry if you think this is a transient or recoverable error.
Received the same condition using Bedrock and Claude 3.7 Sonnet.
The actual error notwithstanding, the session is effectively broken at this point and has to be restarted.
2025-03-21T00:43:36.263455Z ERROR goose::agents::truncate: Error: Server error: Failed to call Bedrock: ValidationException(ValidationException { message: Some("Unsupported MIME type: application/x-sh. Retry your request with a supported file type: xlsx, txt, pdf, csv, md, doc, html, xls, docx"), meta: ErrorMetadata { code: Some("ValidationException"), message: Some("Unsupported MIME type: application/x-sh. Retry your request with a supported file type: xlsx, txt, pdf, csv, md, doc, html, xls, docx"), extras: Some({"aws_request_id": "f5cd4d05-a4dd-42e7-99f7-ff53508c37a7"}) } })
at crates/goose/src/agents/truncate.rs:464
Ran into this error: Server error: Failed to call Bedrock: ValidationException(ValidationException { message: Some("Unsupported MIME type: application/x-sh. Retry your request with a supported file type: xlsx, txt, pdf, csv, md, doc, html, xls, docx"), meta: ErrorMetadata { code: Some("ValidationException"), message: Some("Unsupported MIME type: application/x-sh. Retry your request with a supported file type: xlsx, txt, pdf, csv, md, doc, html, xls, docx"), extras: Some({"aws_request_id": "f5cd4d05-a4dd-42e7-99f7-ff53508c37a7"}) } }).
Please retry if you think this is a transient or recoverable error.
Getting the same error. Using Google Vertex AI with claude-3-7-sonnet.
All subsequent requests return the same error. It is most probably happening because the session logs get polluted and then the all the API requests that use those fail.
I interrupted it to add some context using ^C.
^CThe existing call to developer__shell was interrupted. How would you like to proceed?
( O)> the project uses poetry
◓ Encrypting ethereal edges... 2025-03-25T08:52:14.754291Z ERROR goose::agents::truncate: Error: Request failed: Request failed with status 400 Bad Request: Object {"error": Object {"message": String("messages.13: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_vrtx_01Af9xQM3QdRNSdpB98DEpEG. Each `tool_use` block must have a corresponding `tool_result` block in the next message."), "type": String("invalid_request_error")}, "type": String("error")}
at crates/goose/src/agents/truncate.rs:461
Ran into this error: Request failed: Request failed with status 400 Bad Request: Object {"error": Object {"message": String("messages.13: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_vrtx_01Af9xQM3QdRNSdpB98DEpEG. Each `tool_use` block must have a corresponding `tool_result` block in the next message."), "type": String("invalid_request_error")}, "type": String("error")}.
Please retry if you think this is a transient or recoverable error.
After digging into this a bit, there's a couple things going on here.
-
The session is effectively unrecoverable. This happens because the message history is effectively in a bad state and the message ordering is not following what is expected. This is expected, but we can try to do some clean up for this and show the error to the model to retry.
-
The errors are showing up for claude models due to a few reasons. There seems to be a bug in their api that is causing this and has to do with the ordering in their responses. see here. We can adjust that for the Anthropic provider, but this might be a bit tricky for other providers as they may do the translation themselves (e.g. databricks). I've also seen similar errors with parallel tool calling with claude models through other providers.
I believe the next release will fix this
this should be fixed on main now. let me know if not!