# Upgrade LangChain in a Streamlit App

Yes. An agent moves your Streamlit app off a pinned pre-1.0 LangChain to the current packages, rewrites imports and agent calls, keeps tests passing and opens a PR.

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

## What the agent does

The agent clones the app into its own cloud sandbox and reads what the pins hold it to. In a Streamlit app like streamlit/llm-examples, `requirements.txt` pins `langchain==0.0.350` and `langchain-community==0.0.3` beside `streamlit>=1.28` and `openai>=1.2`, and three of the six pages import from paths those versions still had: `pages/2_Chat_with_search.py` uses `langchain.chat_models.ChatOpenAI`, `langchain.tools.DuckDuckGoSearchRun`, `initialize_agent` with `AgentType.ZERO_SHOT_REACT_DESCRIPTION` and `StreamlitCallbackHandler` from `langchain.callbacks`; `pages/3_Langchain_Quickstart.py` and `pages/4_Langchain_PromptTemplate.py` use `langchain.llms.OpenAI` and `langchain.prompts.PromptTemplate` and call the model object directly as a function. `app_test.py` patches `langchain.llms.OpenAI.__call__`, and `.github/workflows/app-testing.yml` runs that test file with `ruff` and `pytest` on Python 3.11 through `streamlit-app-action`.

The agent installs the current `langchain` release in a fresh virtual environment with `langchain-openai` and `langchain-community`, then reads the deprecation and removal notes for each symbol the pages use instead of guessing. It moves `ChatOpenAI` and `OpenAI` to `langchain_openai`, `PromptTemplate` to `langchain_core.prompts`, `DuckDuckGoSearchRun` to `langchain_community.tools` and the Streamlit callback handler to `langchain_community.callbacks.streamlit`, replaces the direct `llm(text)` calls with `invoke`, and rebuilds the search agent on the agent constructor the current release provides, keeping the callback handler so the agent's thoughts still render in `st.container()` as the page's text promises.

Two things in the pages are not import changes and the agent treats them differently. `pages/4_Langchain_PromptTemplate.py` names `text-davinci-003`, a model the provider no longer serves, so the page would fail at runtime regardless of the upgrade; the agent switches it to the chat model the other pages use and says so in the pull request as a behaviour change, not a mechanical one. `pages/1_File_Q&A.py` uses the Anthropic SDK and not LangChain, so it is outside this upgrade; the agent leaves it untouched and notes it as a separate item.

Then it proves the result the way CI would. It updates `app_test.py` so `test_Langchain_Quickstart` patches the new class's `invoke` instead of `__call__`, runs `ruff check .` under the repository's `.ruff.toml` with its 105-character line length, runs `pytest app_test.py`, and starts `streamlit run Chatbot.py` headless to open each changed page in the sandbox's browser and confirm it renders with no key set and shows the "Please add your OpenAI API key" notice rather than an import error. The new pins go into `requirements.txt` as exact versions read from the environment it tested in, so the next run of this upgrade knows what it is upgrading from.

## Start it with one API call

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

```json
{
  "agent": "codex",
  "input": "Upgrade LangChain in this Streamlit app to the current release. Read requirements.txt, requirements-dev.txt, Chatbot.py, every file under pages/, app_test.py, .ruff.toml and .github/workflows/app-testing.yml first. Install the current langchain, langchain-openai and langchain-community in a fresh virtual environment and read their deprecation notes for every symbol the pages import. Move the imports to their current packages, replace direct model calls with invoke, rebuild the search agent on the current agent constructor while keeping the Streamlit callback handler, and replace any model name the provider no longer serves, calling that out as a behaviour change. Leave the File Q&A page alone since it does not use LangChain. Update app_test.py to patch the new class and method, run ruff check . and pytest app_test.py, start streamlit run Chatbot.py headless and open each changed page in a browser to confirm it renders without an API key. Pin the versions you tested in requirements.txt and open a pull request listing every import moved, the test output and the one behaviour change.",
  "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

What comes back is a pull request on its own branch changing `requirements.txt`, `pages/2_Chat_with_search.py`, `pages/3_Langchain_Quickstart.py`, `pages/4_Langchain_PromptTemplate.py` and `app_test.py`, with `Chatbot.py`, `pages/1_File_Q&A.py` and `pages/5_Chat_with_user_feedback.py` untouched because they call the OpenAI SDK directly or use no LangChain at all. The description has one line per import moved, from old path to new, the agent constructor used in the search page, and a separate paragraph for the model-name change.

The transcript at `GET /o/{org}/sessions/{id}/messages` holds the `pip install` output with the versions resolved, the `ruff check` and `pytest` runs, and the browser steps against the running app, so a reviewer can see that each page rendered. The pull request's checks run the same `ruff` and `pytest` through `streamlit-app-action` on the pull request branch.

Before merging, a reviewer checks that the search agent still streams its steps into the Streamlit container, that the patched target in `app_test.py` is the method the page actually calls, and that the behaviour change is acceptable. A message on the same session can extend the test file to cover the search page, which the current suite does not.

## Run it on every Monday morning

Add an automation to the Project with this prompt and a `schedule` trigger with `cron` set to early Monday in your `timezone`. Each week a run installs the current packages, reads what changed since the pins in `requirements.txt`, and opens a pull request only when there is something to move; when the current release is already pinned, the run says so and pushes nothing. An automation starts at most `max_runs_per_hour` runs in an hour, which a weekly schedule never reaches.

From your own server, the same body goes to `POST /o/{org}/sessions` with the repository in `resources` and a `request_id` that is a UUID v5 of the week number, so a retried request returns the run already started. Give the key a `webhook_url` and every run the key starts posts `run.completed` with `data.session_url`, which a handler reads for the pull request link.

## Why run it on Rush?

Jumping a library across its major rewrite is a reading job as much as a coding one: which symbols moved, which were removed, and which old model names will fail at runtime. The agent installs the real packages in its own sandbox, reads the real deprecation messages, and proves each page by rendering it in a browser, which is more than a dependency bot does and more than most people do on a Monday.

The `pip install`, `ruff`, `pytest` and browser output stay in the run's transcript, so the pull request's statement that every page renders can be checked line by line. The behaviour change is isolated and named, so the reviewer decides on it on its own rather than finding it inside a diff of import lines.

## Frequently asked questions

### Will the search page still show the agent's reasoning steps?

Yes. The Streamlit callback handler moved packages but still exists, and the agent keeps it attached when it rebuilds the search agent on the current constructor, so the thoughts and tool calls render in the `st.container()` as before. The browser check in the sandbox opens that page to confirm it loads.

### Why does the pull request change a model name?

Because `pages/4_Langchain_PromptTemplate.py` names a completion model the provider has retired, so the page would fail at runtime whatever LangChain version is installed. The agent switches it to the chat model the other pages use and labels the change as behavioural so you can reject it separately.

### Does it touch the pages that call OpenAI or Anthropic directly?

No. `Chatbot.py` and `pages/5_Chat_with_user_feedback.py` use the OpenAI SDK, and `pages/1_File_Q&A.py` uses the Anthropic SDK; none of them imports LangChain. The pull request lists them as unchanged and notes that the Anthropic page would need its own upgrade.

### Why pin exact versions instead of ranges?

So the next scheduled run knows exactly what it is upgrading from, and so CI installs what the agent tested. The old file already pinned LangChain exactly; the agent keeps that convention and records the versions it resolved in the sandbox.

## More Streamlit jobs

- [Upgrade Python Dependencies in a Streamlit App](https://getrush.ai/run/upgrade-python-dependencies/streamlit/)
- [Write Tests for a Streamlit App](https://getrush.ai/run/write-apptest-tests/streamlit/)
- [Add LLM API Error Handling to a Streamlit App](https://getrush.ai/run/add-api-error-handling/streamlit/)

## More jobs like this: Upgrade dependencies weekly

- [Upgrade marshmallow 2 to marshmallow 3 (strict, .data and Hook Signatures)](https://getrush.ai/run/upgrade-marshmallow/marshmallow/)
- [Upgrade Mongoose 5 to the Current Major in an Express API](https://getrush.ai/run/upgrade-mongoose/mongoose/)
- [Upgrade an Express App to Node 24](https://getrush.ai/run/upgrade-node-version/express/)

## 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/)
