create_new_file fails on pure JSON contents
Before submitting your bug report
- [x] I've tried using the "Ask AI" feature on the Continue docs site to see if the docs have an answer
- [x] I'm not able to find a related conversation on GitHub discussions that reports the same bug
- [x] I'm not able to find an open issue that reports the same bug
- [x] I've seen the troubleshooting guide on the Continue Docs
Relevant environment info
- OS: MacOS
- Continue version: 1.3.24
- IDE version: 1.107
- Model: M2
Description
When the model calls create_new_file, and the contents argument is, itself, valid JSON, the contents argument is an object, not a string, because this snippet in core/context/retrieval/pipelines/BaseRetrievalPipeline.ts:
const parsed = JSON.parse(responseContent);
toolCalls = parsed.tools || [];
Will have deeply parsed the response. This causes getStringArg() to throw an error. Instead, if the type of args[argName] is 'object', it should be coerced back to a string with JSON.stringify()
I'll submit a PR shortly for this
To reproduce
- Enable tool calls
- Ask a model in agent mode: "Create a new file called sample.json"
Log output
Related issues:
- #8510 - Continue keeps sending json object as string as opposed to json.stringify() as parameter to mcp tools
- #8764 - Can't create files (general file creation failures)
- #5067 - builtin_create_new_file tool doesn't create missing folders and exceptions are not propagated to LLM
- #8388 - cant create files and hangs a lot and errors
- #8003 - Create File Fails and Loops when MaxTokens is reached
- #6718 - Fails to create files in VSCodium on Windows due to "Registry key not found" error
@mcowger thanks for the report, not sure the retrieveWithTools method is used for normal file creation, but I could see the tool call parsing logic causing it to try to write json instead of a string. The solution might be just to JSON.stringify in the create file implementation if the arg contents is valid JSON
EDIT I posted this the moment you opened the PR, ignore
Yup that was my implementation in the PR
:tada: This issue has been resolved in version 1.35.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
:tada: This issue has been resolved in version 1.7.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
:tada: This issue has been resolved in version 1.38.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket: