Skip to content

fix(deepagents): use file_path in read_file prompt examples - #644

Open
Mike Frolov (TrueNight) wants to merge 1 commit into
langchain-ai:mainfrom
TrueNight:truenight/fix-read-file-file-path
Open

fix(deepagents): use file_path in read_file prompt examples#644
Mike Frolov (TrueNight) wants to merge 1 commit into
langchain-ai:mainfrom
TrueNight:truenight/fix-read-file-file-path

Conversation

@TrueNight

Copy link
Copy Markdown

Problem

The read_file tool schema requires the argument file_path, but two built-in prompts illustrate the call with an argument named path:

  • READ_FILE_TOOL_DESCRIPTION in libs/deepagents/src/middleware/fs.ts (read_file(path, limit=...), read_file(path, offset=..., limit=...))
  • the skills workflow prompt in libs/deepagents/src/middleware/skills.ts (read_file(path, limit=...))

Models that copy the example emit a path argument and fail schema validation on the very first read:

Error invoking tool 'read_file' with kwargs {"path":".../SKILL.md","limit":1000}
Error: Received tool input did not match expected schema
Invalid input: expected string, received undefined
  -> at file_path

Change

Align the four example lines with the actual schema by renaming the example argument pathfile_path. This is a prompt/documentation fix only — the tool schema (file_path) is unchanged, so there is no API/behavior change for callers.

Test

Adds one test under createFilesystemMiddleware › tools in fs.test.ts that derives the allowed argument names from the read_file tool's schema (schema.toJSONSchema().properties) and asserts every argument shown in the tool description's read_file(...) examples is one of them. It fails if an example ever references an argument the tool does not accept (verified red before this change, green after).

Verification

  • pnpm build — passes
  • pnpm --filter deepagents typecheck — passes
  • pnpm --filter deepagents test:unit — 1177 passed

A patch changeset is included.

The read_file tool schema requires `file_path`, but the built-in tool
description and the skills workflow prompt illustrated the call as
`read_file(path, ...)`. Models copying the example emitted a `path`
argument and failed schema validation:

    Invalid input: expected string, received undefined
      -> at file_path

Align the four example lines in fs.ts and skills.ts with the schema, and
guard the read_file examples with a test that derives the allowed
argument names from the tool's schema (so the examples can never again
name a parameter the tool does not accept).
@changeset-bot

changeset-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 15d9263

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
deepagents Patch
deepagents-acp Patch
@deepagents/evals Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jul 3, 2026

Copy link
Copy Markdown

Mike Frolov (@TrueNight) is attempting to deploy a commit to the LangChain Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new

pkg-pr-new Bot commented Jul 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

deepagents-acp

npm i https://pkg.pr.new/deepagents-acp@644

deepagents

npm i https://pkg.pr.new/deepagents@644

@langchain/sandbox-standard-tests

npm i https://pkg.pr.new/@langchain/sandbox-standard-tests@644

@langchain/daytona

npm i https://pkg.pr.new/@langchain/daytona@644

@langchain/deno

npm i https://pkg.pr.new/@langchain/deno@644

@langchain/modal

npm i https://pkg.pr.new/@langchain/modal@644

@langchain/node-vfs

npm i https://pkg.pr.new/@langchain/node-vfs@644

@langchain/quickjs

npm i https://pkg.pr.new/@langchain/quickjs@644

commit: 15d9263

Colin Francis (colifran) pushed a commit that referenced this pull request Jul 8, 2026
…th atomic update support and testing (#659)

## Problem
Addresses #658.

When using weaker or custom LLMs (e.g., smaller open-source models) in
`deepagents` and consumers like `openwiki`, the agent immediately
crashes with a schema validation error on the first filesystem tool
call:


This occurs because:
1. `ls` defines its directory argument as `path`, but `read_file`,
`write_file`, and `edit_file` expect `file_path`. Models often default
to `path` across all filesystem tools.
2. The description prompt examples in `fs.ts` and `skills.ts` show
`read_file(path, ...)`, instructing models to use the wrong parameter
name.

## Proposed Changes
This PR solves both prompt inconsistencies and schema validation
failures with a fully backward-compatible input normalization helper:

1. **Prompt Alignment**: Fixed references in `fs.ts` and `skills.ts` to
instruct the model to use `file_path` (aligned with the prompt fixes in
#644).
2. **Schema Input Normalization**: Added a `normalizeFilePathInput`
preprocessor helper to the `read_file`, `write_file`, and `edit_file`
Zod schemas using `z.preprocess`. This dynamically maps the `path` key
to `file_path` if the model still passes `path`.

## Verification & Tests
- Added unit tests in `fs.test.ts` to assert that:
- `path` parameter normalization maps correctly to `file_path` for
`read_file`, `write_file`, and `edit_file`.
  - All instruction examples contain only valid schema fields.
- Verified that `zod-to-json-schema` unwraps the `z.preprocess` layer
perfectly, preserving the original schema descriptions and definitions
sent to the LLM.
- Ran all filesystem tests successfully (`npx vitest run
src/middleware/fs.test.ts` passes).
@TrueNight

Copy link
Copy Markdown
Author

Hi Hunter Lovell (@hntrl)! Could you take a look at this PR when you have a moment? It’s ready for review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant