Skip to content

Commit bad62bd

Browse files
authored
Merge pull request #223 from langchain-ai/fix-write-file
fix(deepagents): prevent write_file crash when model omits content
2 parents 310f6fc + bfa843d commit bad62bd

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

.changeset/happy-flowers-mix.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"deepagents": patch
3+
---
4+
5+
fix(deepagents): prevent write_file crash when model omits content
6+
- Default the content parameter to an empty string so a missing argument doesn't crash the entire agent run via Zod validation failure.

libs/deepagents/src/middleware/fs.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,4 +727,22 @@ describe("createFilesystemMiddleware", () => {
727727
}
728728
});
729729
});
730+
731+
describe("tools", () => {
732+
it("write_file schema should accept missing content and default to empty string", () => {
733+
const middleware = createFilesystemMiddleware({
734+
backend: createMockBackend(),
735+
});
736+
737+
const writeFileTool = middleware.tools!.find(
738+
(t: any) => t.name === "write_file",
739+
) as any;
740+
expect(writeFileTool).toBeDefined();
741+
742+
// Parse with only file_path, no content — simulates the model omitting it
743+
const parsed = writeFileTool.schema.parse({ file_path: "/app/test.c" });
744+
expect(parsed.file_path).toBe("/app/test.c");
745+
expect(parsed.content).toBe("");
746+
});
747+
});
730748
});

libs/deepagents/src/middleware/fs.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,10 @@ function createWriteFileTool(
522522
description: customDescription || WRITE_FILE_TOOL_DESCRIPTION,
523523
schema: z.object({
524524
file_path: z.string().describe("Absolute path to the file to write"),
525-
content: z.string().describe("Content to write to the file"),
525+
content: z
526+
.string()
527+
.default("")
528+
.describe("Content to write to the file"),
526529
}),
527530
},
528531
);

0 commit comments

Comments
 (0)