All jobs

Migrate a Streamlit App to the Anthropic Messages API from a Linear Issue

Yes. An agent ports a Streamlit page off Anthropic's removed Text Completions client to the Messages API, replaces the retired model, adds a test and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent finds the call that no longer works and reads everything around it. In an app shaped like streamlit/llm-examples, pages/1_File_Q&A.py uploads a .txt or .md file, takes a question, and builds a prompt string from anthropic.HUMAN_PROMPT, the article wrapped in <article> tags, the question and anthropic.AI_PROMPT. It then calls anthropic.Client(api_key=...).completions.create(prompt=..., stop_sequences=[anthropic.HUMAN_PROMPT], model="claude-v1", max_tokens_to_sample=100) and renders response.completion. requirements.txt pins anthropic>=0.3.0, which lets pip install a current release where completions, HUMAN_PROMPT and AI_PROMPT no longer exist, so the page fails at import or at the call. app_test.py covers Chatbot.py and pages/3_Langchain_Quickstart.py with streamlit.testing.v1.AppTest, patching the OpenAI and LangChain calls, but has no test for this page. .github/workflows/app-testing.yml runs streamlit/streamlit-app-action on Python 3.11 with ruff: true and pytest, and .ruff.toml sets line-length = 105.

The agent rewrites the call as the Messages API expects. The client becomes anthropic.Anthropic(api_key=anthropic_api_key). The prompt string loses its HUMAN_PROMPT and AI_PROMPT markers and becomes the content of one {"role": "user", ...} message, still wrapping the article in <article> tags so the question is clearly separate from the document. max_tokens_to_sample becomes max_tokens, raised from 100, which cuts a summary off mid-sentence, to a value large enough for an answer about an uploaded article; stop_sequences goes, because the Messages API ends the turn itself. The answer is the joined text of the text blocks in message.content, not a .completion attribute. The model string claude-v1 is retired, so the agent moves the model id into one constant at the top of the file set to a current model, claude-opus-5-5, and says in the pull request that the choice is the team's to change. It also drops the stale # "claude-2" for Claude 2 model comment and bumps requirements.txt to the current release of anthropic, so the pin matches the code.

Then it adds test_File_QA to app_test.py in the style of the two tests already there: AppTest.from_file("pages/1_File_Q&A.py"), patch anthropic.resources.messages.Messages.create to return a Message whose content is one TextBlock, set the API key in the sidebar input, upload a small text file through the uploader's test method, set the question, run, and assert the ### Answer heading and the mocked text appear and at.exception is empty. It also keeps the behaviour of the three st.info guards (no file, no question, no key) unchanged.

Before opening the pull request it runs pip install -r requirements.txt, ruff check . and ruff format --check . with the repository's line length, and pytest -v, the same commands the app-testing workflow runs, and pastes the pytest output in the description. No real API call is made; the only Anthropic traffic in the run is the mocked one in the test.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Migrate pages/1_File_Q&A.py from Anthropic's removed Text Completions client to the Messages API and open a pull request. Read that page, requirements.txt, app_test.py, .ruff.toml and .github/workflows/app-testing.yml first. Replace anthropic.Client and client.completions.create with anthropic.Anthropic and client.messages.create: the HUMAN_PROMPT and AI_PROMPT markers go away and the article, still wrapped in <article> tags, plus the question become the content of a single user message; max_tokens_to_sample becomes max_tokens and is raised from 100 so an answer about an article is not cut off; stop_sequences is removed; the answer is the joined text of the text blocks in message.content. The claude-v1 model is retired: put the model id in one constant at the top of the file set to claude-opus-5-5 and say in the pull request that it is the team's choice. Keep the three st.info guards exactly as they are. Bump the anthropic pin in requirements.txt to the current release. Add test_File_QA to app_test.py in the style of the existing tests, using AppTest.from_file on the page, patching anthropic.resources.messages.Messages.create to return a Message with one TextBlock, uploading a small text file, setting the key and the question, and asserting the Answer heading and the mocked text render with no exception. Run pip install -r requirements.txt, ruff check and ruff format --check with the repository's config, and pytest -v, and paste the pytest output in the pull request description. Make no real API calls and change no other page.",
  "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 with three changed files: pages/1_File_Q&A.py on the Messages API with a MODEL constant and a larger max_tokens, requirements.txt with the anthropic pin raised to the current release, and app_test.py with a new test_File_QA alongside the two existing tests. The description quotes the pytest -v output from the sandbox, the ruff results, and a short note on the model choice and how to change it.

The App testing workflow runs on the pull request, so ruff and the three AppTests, including the new one, report as a check before merge. A reviewer confirms the article is still wrapped in <article> tags inside the user message, that the three st.info guards fire in the same order as before, and that the mocked test asserts on the rendered answer rather than on the mock itself. Then they decide whether claude-opus-5-5 is the model they want or swap the constant.

Run it on every Linear issue labelled agent

In the console, an automation with a linear trigger on linear.issue.labeled and the label agent starts one run per labelled issue, with the issue as its context, in the Project that has the repository. An issue that says File Q&A page broken: completions API removed with this prompt in its description is enough; changes made by an app integration never fire the trigger, so the agent's own comment on the issue does not start a second run.

From your own server, the same run is one POST /o/{org}/sessions per issue: the repository in resources, plus the issue's https://linear.app/<workspace>/issue/<ID> URL there too, read through your Linear connection into the prompt. A webhook on the API key posts run.completed or run.failed when the turn finishes, with the session_url to read the pull request link.

The use case this job follows, with its automation and trigger: Turn a Linear label into a PR.

Why run it on Rush?

An SDK migration like this is small but exact: four parameters change shape, one attribute moves, one model id is gone, and a loose pin in requirements.txt is what let the breakage in. Getting it right means running the page, not reading about it. The agent installs the current package in its own sandbox, runs the app through AppTest with the API call mocked, runs the same ruff and pytest commands the workflow runs, and keeps the output in the run's record so the reviewer sees the page render rather than a promise that it does.

The added test is the lasting part. The two pages that already had an AppTest were the two that stayed green; this one did not, and now it has one that pins the Messages API call shape, so the next SDK or model change shows up in CI instead of in a user's browser.

Frequently asked questions

Will it touch the OpenAI and LangChain pages too?

No. The prompt limits the change to pages/1_File_Q&A.py, its test and the anthropic pin. The other pages pin other libraries and have their own upgrade questions, which the pull request mentions but does not act on.

Which model does it use, and can we change it?

claude-v1 is retired, so the agent sets one MODEL constant at the top of the page to claude-opus-5-5 and says so in the pull request. Changing the model is a one-line edit of that constant, and the test does not depend on the model string.

Does the test call Anthropic?

No. It patches anthropic.resources.messages.Messages.create to return a Message with a single TextBlock, the same approach app_test.py already takes with the OpenAI client, so the suite runs offline in CI with no key and no cost.

Why raise max_tokens from 100?

Because max_tokens_to_sample=100 cut a summary of an uploaded article off mid-sentence, and the Messages API's max_tokens is a hard ceiling with the same effect. The agent picks a value large enough for an answer about a document and leaves it as a plain argument in the call, so the team can tune it.

Why does the article stay in <article> tags?

The tags separate the document from the question inside one user message, which is the same job the old prompt string did with them. Keeping that structure means the page behaves as before for the user while the transport underneath changes.

More Streamlit jobs

More jobs like this: Turn a Linear label into a PR

Keep reading