TypeError with comparison operators when using browser automation agent with OpenAI GPT

Issue Description

I’m building a Python application that processes resume documents and performs web automation for job applications. The script uses OpenAI’s chat models and a browser automation library, but I keep getting a comparison error.

Error Message

TypeError: '>=' not supported between instances of 'int' and 'str'

Sample Code

from langchain_openai import ChatOpenAI
from browser_use import Agent
import asyncio
from dotenv import load_dotenv
import json
import PyPDF2

load_dotenv()

def extract_resume_text(pdf_file):
    try:
        with open(pdf_file, "rb") as document:
            pdf_reader = PyPDF2.PdfReader(document)
            content = ""
            for page_num in pdf_reader.pages:
                extracted_text = page_num.extract_text()
                if extracted_text:
                    content += extracted_text
            return content
    except Exception as error:
        print(f"PDF reading failed: {error}")
        return ""

async def process_application():
    resume_file = "resume.pdf"
    resume_text = extract_resume_text(resume_file)

    if not resume_text:
        print("Failed to extract resume content")
        return

    print("Resume processed:", resume_text)

    automation_agent = Agent(
        task=f"Analyze resume and find relevant job opportunities. Resume data: {resume_text}",
        llm=ChatOpenAI(model="gpt-4"),
    )

    try:
        job_listings = await automation_agent.run("Find data science positions matching the resume profile.")
        print("Job search results:", job_listings)

        if isinstance(job_listings, list):
            for position in job_listings:
                if isinstance(position, dict):
                    if 'compensation' in position:
                        try:
                            position['compensation'] = int(position['compensation'])
                        except (ValueError, TypeError):
                            print(f"Invalid compensation data: {position['compensation']}")
                            position['compensation'] = 0

    except Exception as error:
        print(f"Job search error: {error}")
        return

    try:
        with open("positions.json", "w") as output_file:
            json.dump(job_listings, output_file, indent=2)
        print("Results saved successfully")
    except Exception as error:
        print(f"File save error: {error}")

    for position in job_listings:
        try:
            application_status = await automation_agent.run(f"Submit application for: {position}")
            print(f"Application status for {position}:", application_status)
        except Exception as error:
            print(f"Application error for {position}: {error}")

if __name__ == "__main__":
    asyncio.run(process_application())

Full Stack Trace

Traceback (most recent call last):
  File "service.py", line 468, in run
    for step in range(max_steps):
                ^^^^^^^^^^^^^^^^
TypeError: 'str' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 78, in <module>
    asyncio.run(process_application())
  File "asyncio/runners.py", line 194, in run
    return runner.run(main)
  File "service.py", line 497, in run
    max_steps_reached=self.n_steps >= max_steps,
                      ^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '>=' not supported between instances of 'int' and 'str'

Environment Details

  • Python 3.x
  • Libraries: langchain-openai, browser-use, python-dotenv, PyPDF2
  • Model: gpt-4

The error seems to happen inside the browser automation library when it tries to compare step counts. I tried adding type checking for my data but the issue persists. Has anyone encountered this before?

Hit this exact bug last month with browser_use. Your max_steps parameter is getting passed as a string instead of an integer - probably from an env variable or config file. The library expects an integer for step counting, but it’s getting a string somewhere in your setup. Check for environment variables like MAX_STEPS in your .env file that might be loading as strings. Fix it by converting when you create the Agent: use max_steps=int(os.getenv(‘MAX_STEPS’, 10)) or just hardcode it like max_steps=10. Fixed the comparison error instantly for me since the step counter can actually compare integers properly.

the browser_use Agent constructor is getting max_steps as a string instead of an integer. this usually happens when you pull parameters from config files or env variables without converting the type. try setting max_steps=10 directly when you create the Agent, or if you’re using a config dict, wrap your numeric values with int(). the library tries to run range(max_steps) internally, which breaks when max_steps is “10” instead of 10.