# Fix Deprecated APIs in a LangChain.js App

Yes. An agent finds each deprecated LangChain.js call in your app from the installed typings, moves it to the current API, builds, tests and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/fix-deprecated-apis/langchain/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent builds its list from the packages that are installed, not from memory of a changelog. In an app like langchain-ai/langchain-nextjs-template, `yarn.lock` resolves `langchain` 1.5.9, `@langchain/core` 1.2.14 and `@langchain/langgraph` 1.4.10, and the `.d.ts` files under `node_modules` carry a `@deprecated` note on each retired member with its replacement. Neither `yarn build` nor `yarn lint` reports any of them: the TypeScript compiler does not fail on a deprecated call, and `eslint.config.mjs` extends only `eslint-config-next/core-web-vitals`. So the agent searches the source for each deprecated name and reads the note beside it.

In this repository the list is short and specific. `app/api/chat/agents/route.ts` and `app/api/chat/retrieval_agents/route.ts` both import `createReactAgent` from `@langchain/langgraph/prebuilt`, whose typings say it has moved to the `langchain` package as `createAgent`, and both pass `messageModifier`, marked `Use prompt instead`. The same two files call `message._getType()` three times each; the base message class marks that method deprecated, and `getType()` after it, in favour of the `type` property. `app/ai_sdk/agent/action.ts` imports `AgentExecutor` and `createToolCallingAgent` from `@langchain/classic/agents` and fetches its prompt from the hub with `pull` at request time, and the retrieval agent takes `createRetrieverTool` from `@langchain/classic/tools/retriever`.

It changes one kind of call per commit, so each can be reviewed and reverted alone. The two routes move to `createAgent` from `langchain` with the system message passed as `systemPrompt`, and the three `_getType()` branches in each become comparisons on `.type`. The `@langchain/classic` imports are the legacy package, not deprecated members, so the agent reports them and replaces the executor only if the prompt asks. It leaves `data/DefaultRetrievalText.ts` alone: that file mentions `initializeAgentExecutorWithOptions` and `gpt-3.5-turbo`, but it is sample text for the retrieval demo to ingest, not code that runs.

Proof has three parts. `yarn build` runs `next build --webpack`, and since all six route files declare `runtime = "edge"`, an import that needs Node APIs fails there first. The README's test command, `node --experimental-strip-types --test utils/integrations.test.mjs`, still has to pass. For the changed routes the agent adds a test that drives the new agent with a fake tool-calling model from the library's testing exports, checks that `streamEvents` still emits `on_chat_model_stream` chunks with content, and checks the JSON shape returned when `show_intermediate_steps` is set. Finally it adds `@typescript-eslint/no-deprecated` to the ESLint config with type information, so `yarn lint` reports the next deprecated call when a dependency update introduces one.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Replace the deprecated LangChain.js APIs in this app. Read package.json, yarn.lock, eslint.config.mjs, tsconfig.json, the README and every file under app/api, app/ai_sdk, app/langgraph and utils first. Install with yarn and record a baseline: yarn build, yarn lint and the README's node test command. Build the list of deprecated calls from the @deprecated notes in the installed .d.ts files of langchain, @langchain/core, @langchain/langgraph and @langchain/openai, not from memory: for each, give the file, line, the note's text and the replacement it names. Replace them one kind per commit: createReactAgent from @langchain/langgraph/prebuilt with createAgent from langchain, messageModifier with the prompt option the new function takes, and _getType() with the type property. Keep each route's request and response shape exactly as it is, including the x- headers and the JSON returned for intermediate steps. List the @langchain/classic imports and stale documentation links you find but do not rewrite them, and do not touch data/DefaultRetrievalText.ts. Add a test for the two agent routes' logic that uses a fake tool-calling model from the library's testing exports and needs no API key. Add the type-aware @typescript-eslint/no-deprecated rule to the ESLint config as an error and make yarn lint pass. Run the baseline commands again. Do not call OpenAI or Tavily. Open a pull request with the table of calls replaced, the list of things reported and left, and the before and after output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The pull request has a few small commits: one for the agent constructor, one for the message type checks, one for the lint rule and one for the test. Its description opens with a table of every deprecated call found, with file and line, the text of the `@deprecated` note it was matched to, and the replacement. A second list holds what was seen and deliberately left: the `@langchain/classic` executor and hub prompt, comment links that still point at `js.langchain.com/v0.2`, and `.env.example`, which names `SERPAPI_API_KEY` for the agent example while the README and the code read `TAVILY_API_KEY`.

Below that are the commands before and after: `yarn build`, `yarn lint` and the node test run. The lint output is the useful part. Before the change it is clean because nothing looks for deprecations; after it, the new rule is on and it is clean because the calls are gone. Anyone who adds a deprecated call later gets an error with the same note the agent worked from.

A reviewer checks behaviour the build cannot. The system prompt must reach the model exactly once, the stream must still carry only the final answer's text, and the non-streaming branch must return the same `role`, `content` and `tool_calls` fields as before. The description says no real model was called, so one manual chat through each agent page with your own key is the last check before merging.

## Run it on every first of the month

Deprecations arrive with dependency updates, and this repository's `.github/dependabot.yml` asks for npm updates weekly. Create an automation in the Project that holds the repository with a `schedule` trigger whose `cron` is `0 9 1 * *` in your `timezone`, and a prompt that says: run `yarn lint`; if the deprecation rule reports anything, replace each call as its note says, run the build and the tests, and open a pull request; if it reports nothing, end with one line. Once the lint rule from this page is merged, that monthly run is a short one.

For several LangChain.js services, send this page's body once per repository to `POST /o/{org}/sessions` with that repository in `resources` and a `request_id` that is a UUID v5 of the repository's full name. Each run reads its own lockfile, so a service two minors behind gets a different list than one that is current. The key's `webhook_url` reports each run it starts when it finishes, with the final answer and a `session_url`.

## Why run it on Rush?

LangChain's API has moved quickly, and what a developer or a model remembers about it is often one version out of date. The reliable source is the typings of the exact versions in the lockfile, which name each replacement. Reading them means installing the dependencies and searching `node_modules`, which the agent does in its sandbox on a fresh clone, so the list in the pull request matches what your build resolves and not what a blog post said last year.

It is also a chore that is easy to start in a terminal and abandon. Each replacement is small, but proving that a streaming route still streams takes a build, a test with a fake model and a careful read of the response shape. Handing it off means that work happens in the background with every command and its output kept in the run's transcript, and you get one pull request to review when it is done.

## Frequently asked questions

### Why doesn't my build already warn about deprecated calls?

A `@deprecated` note in a type definition is shown by editors as a strikethrough and ignored by `tsc` and by `next build`. It only becomes an error if a linter is told to look, which `eslint-config-next` alone does not do. The agent adds the type-aware `@typescript-eslint/no-deprecated` rule so the build pipeline sees what the editor sees.

### Does it need an OpenAI key?

No. The request forbids calling OpenAI or Tavily, and the new test uses a fake model. If you want a live check as well, store a key as a secret in a Project, start the session in that Project and say so in the prompt; the agent then sends one message through each changed route and includes the response.

### Will it remove @langchain/classic?

Not by default. That package is where the older agent executor, hub and retriever tool live, and using it is supported. Replacing `AgentExecutor` with the newer agent changes how the AI SDK example streams events to the page, so the agent lists those imports and waits for you to ask.

### What if a replacement does not behave the same?

Then the commit for that call says so and the test shows the difference. The request requires each route's request and response shape to stay exactly as it is. Where the new API cannot do that, the agent keeps the old call, leaves a lint exception on that one line with the reason, and reports it.

### Does it also upgrade the packages?

No. It works against the versions in `yarn.lock` so the diff is only call sites. Upgrading first and fixing deprecations second are two pull requests, and Dependabot is already configured to open the first kind.

## More LangChain.js jobs

- [Write Unit Tests for a LangChain.js App](https://getrush.ai/run/write-unit-tests/langchain/)
- [Fix "ImportError: cannot import name 'ChatOpenAI' from 'langchain.chat_models'" in LangChain 1.0](https://getrush.ai/run/fix-cannot-import-name-chatopenai-from-langchain-chat-models/langchain/)

## The same job on other stacks

- [Fix Deprecated Zod 4 APIs in a TypeScript API](https://getrush.ai/run/fix-deprecated-apis/zod/)
- [Fix Deprecations in an Ember App](https://getrush.ai/run/fix-deprecated-apis/ember/)
- [Replace Deprecated Flutter APIs Across an App and Make the Analyzer Catch the Next Ones](https://getrush.ai/run/fix-deprecated-apis/flutter/)

## More jobs like this: Hand off a long task

- [Fix "AttributeError: 'EntryPoints' object has no attribute 'get'" on Python 3.12](https://getrush.ai/run/fix-entrypoints-object-has-no-attribute-get/importlib-metadata/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
