browser-use: could not parse response

Bug Description

Here , Most of the time it failed sometime at 4 step and sometimes at 15 or 20, but never generated full test script that is executable Can you Please tell me why the most of time it failed.

Reproduction Steps

Just run this python file.

Code Sample

import asyncio
import os
from dotenv import load_dotenv
from langchain_aws import ChatBedrock
from browser_use import Agent, Controller
from browser_use.browser.context import BrowserContext

# Load environment variables
load_dotenv()
response = ""
# Initialize Controller and Browser
controller = Controller()

# Initialize the ChatBedrock model for AI task execution
model = ChatBedrock(
    model_id="anthropic.claude-3-5-sonnet-20240620-v1:0",
    region_name=os.getenv("AWS_REGION"),
    aws_access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
    aws_secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"),
)

# Define the browser configuration

username= "faizan.hameed@virtual-force.com"
password = "*******"
url = "https://kualitee_defects.kualitee.com/"
# Define the task for generating Java Selenium test scripts
reference = """
import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class KualiteeLoginTest {
    public static void main(String[] args) {
        // Set up WebDriver
//        System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
        WebDriver driver = new ChromeDriver();
        WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

        try {
            // Navigate to Kualitee demo page
            driver.get("https://kualiteedemo.kualitee.com/");

            // Test Case 1: Verify login with valid credentials
            driver.findElement(By.xpath("//input[@placeholder='Ex. johndoe@mail.com']")).sendKeys("faizan.ahmad@kualitee.com");
            driver.findElement(By.xpath("//input[@placeholder='***********']")).sendKeys("********");
            driver.findElement(By.xpath("//input[@value='Log in']")).click();
            wait.until(ExpectedConditions.urlContains("/dashboard"));

            // Test Case 2: Verify login with invalid credentials
            driver.findElement(By.xpath("//input[@placeholder='Ex. johndoe@mail.com']")).clear();
            driver.findElement(By.xpath("//input[@placeholder='Ex. johndoe@mail.com']")).sendKeys("invalid@mail.com");
            driver.findElement(By.xpath("//input[@placeholder='***********']")).clear();
            driver.findElement(By.xpath("//input[@placeholder='***********']")).sendKeys("invalidPassword");
            driver.findElement(By.xpath("//input[@value='Log in']")).click();
            WebElement errorMessage = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(text(),'Invalid credentials')]")));

            // Test Case 3: Verify 'Keep me signed in' checkbox
            WebElement checkbox = driver.findElement(By.name("remember"));
            if (!checkbox.isSelected()) {
                checkbox.click();
            }

            // Test Case 4: Verify 'Forgot Password?' link
            driver.findElement(By.linkText("Forgot Password?")).click();
            wait.until(ExpectedConditions.urlContains("/forgot-password"));

            // Test Case 5: Verify alternative login options
            driver.findElement(By.linkText("Login with Azure AD")).click();
            wait.until(ExpectedConditions.urlContains("/azure-login"));

            driver.navigate().back();
            driver.findElement(By.linkText("Login with Google")).click();
            wait.until(ExpectedConditions.urlContains("/google-login"));

            driver.navigate().back();
            driver.findElement(By.linkText("SAML login with Okta")).click();
            wait.until(ExpectedConditions.urlContains("/saml-login"));

            System.out.println("All test cases executed successfully.");

        } finally {
            // Close the browser
            driver.quit();
        }
    }
}

"""
task = (
    "Generate comprehensive potential possible test cases Java Selenium test scripts. Each method must test a unique functionality."
    "Write all test cases script as java methods, assume these to be in one file."
    "Each functionality should be tested only once, with no duplicate methods or overlapping test cases."
    "Use the following login credentials to access the website:"
    "Email: faizan.hameed@virtual-force.com"
    "Password: ***********"
    "Website URL: https://kualitee_defects.kualitee.com/"
    
)
response = ""
# Action to append the test scripts to a file
@controller.action("Append generated Java test scripts to a file")
async def append_test_scripts(result: str):
    print("Response is \n "+result)
    with open("Generated3.java", "a") as java_file:
        java_file.write(result + "\n")  # Ensure each test case is on a new line or separated properly
    return "Test script appended to Generated1.java"

# Define the agent to generate the test scripts
async def run_agent():
    """
    Function to run the agent and get the test scripts in Java Selenium.
    """
    agent = Agent(
        task=task,
        llm=model,
        controller=controller,
        
    )

    try:
        # Run the agent to generate the test cases
        result = await agent.run()
        
        if result:
            print("Agent successfully generated the test scripts.")
            await append_test_scripts(result)
        else:
            print("No result generated by the agent.")
    except Exception as e:
        print(f"An error occurred while running the agent: {e}")

# Run the main function to start the process
async def main():
    print("Running the agent to generate test scripts...")
    await run_agent()

if __name__ == "__main__":

    asyncio.run(main())

Version

latest

LLM Model

Claude 3.5 Sonnet

Operating System

windows 11

Relevant Log Output

INFO     [agent]
πŸ“ Step 16
ERROR    [agent] ❌ Result failed 1/3 times:
 Could not parse response.
INFO     [agent] 
πŸ“ Step 16
ERROR    [agent] ❌ Result failed 2/3 times:
 Could not parse response.
INFO     [agent]
πŸ“ Step 16
ERROR    [agent] ❌ Result failed 3/3 times:
 Could not parse response.
ERROR    [agent] ❌ Stopping due to 3 consecutive failures
INFO     [agent] Created GIF at agent_history.gif
Agent successfully generated the test scripts.
An error occurred while running the agent: can only concatenate str (not "AgentHistoryList") to str

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 19 (5 by maintainers)

Most upvoted comments

I am also getting the same error but from ollama for all models of ollama in my local machine running on CPU.

@j0yk1ll @MagMueller Still getting same error when running qwen from ollama. Also, with deepseek-r1 Code which is given in example. Using latest browser-use-0.1.29

py .\examples\models\qwen.py INFO [browser_use] BrowserUse logging setup complete with level info INFO [root] Anonymized telemetry enabled. See https://github.com/browser-use/browser-use for more information. INFO [agent] πŸš€ Starting task: 1. Go to https://www.reddit.com/r/LocalLLaMA2. Search for β€˜browser use’ in the search bar3. Click search4. Call done INFO [agent] πŸ“ Step 1 ERROR [agent] ❌ Result failed 1/6 times: Could not parse response. INFO [agent] πŸ“ Step 1 INFO [agent] 🀷 Eval: Unknown - No previous actions to evaluate. INFO [agent] 🧠 Memory: INFO [agent] 🎯 Next goal: Start browser and navigate to Reddit page INFO [agent] πŸ› οΈ Action 1/1: {} INFO [agent] πŸ“ Step 2 ERROR [agent] ❌ Result failed 1/6 times: Could not parse response. INFO [agent] πŸ“ Step 2 ERROR [agent] ❌ Result failed 2/6 times: Could not parse response. INFO [agent] πŸ“ Step 2 INFO [agent] 🀷 Eval: Current url is about:blank - Navigating to Reddit page. INFO [agent] 🧠 Memory: Navigated to r/LocalLLaMA on Reddit. INFO [agent] 🎯 Next goal: Search for β€˜browser use’ in the search bar and click search. INFO [agent] πŸ› οΈ Action 1/1: {} INFO [agent] πŸ“ Step 3 INFO [agent] 🀷 Eval: Current url is about:blank - Navigating to Reddit page. INFO [agent] 🧠 Memory: Navigated to r/LocalLLaMA on Reddit. INFO [agent] 🎯 Next goal: Search for β€˜browser use’ in the search bar and click search. INFO [agent] πŸ› οΈ Action 1/1: {β€œgo_to_url”:{β€œurl”:β€œhttps://www.reddit.com/r/LocalLLaMA/”}} INFO [controller] πŸ”— Navigated to https://www.reddit.com/r/LocalLLaMA/ INFO [agent] πŸ“ Step 4 ERROR [agent] ❌ Result failed 1/6 times: Could not parse response. INFO [agent] πŸ“ Step 4 ERROR [agent] ❌ Result failed 2/6 times: Could not parse response. INFO [agent] πŸ“ Step 4 ERROR [agent] ❌ Result failed 3/6 times: Could not parse response. INFO [agent] πŸ“ Step 4 ERROR [agent] ❌ Result failed 4/6 times: Could not parse response. INFO [agent] πŸ“ Step 4 ERROR [agent] ❌ Result failed 5/6 times: Could not parse response. INFO [agent] πŸ“ Step 4 ERROR [agent] ❌ Result failed 6/6 times: Could not parse response. ERROR [agent] ❌ Stopping due to 6 consecutive failures WARNING [agent] No history or first screenshot to create GIF from

Code

async def run_search():
	agent = Agent(
		task=(
			'1. Go to https://www.reddit.com/r/LocalLLaMA'
			"2. Search for 'browser use' in the search bar"
			'3. Click search'
			'4. Call done'
		),
		llm=ChatOllama(
			# model='qwen2.5:32b-instruct-q4_K_M',
			# model='qwen2.5:14b',
			model='qwen2.5:latest',
			base_url="http://localhost:11434",
		),
		max_actions_per_step=1,
	    tool_calling_method="json_schema",
        max_failures=6,
        use_vision=False
	)

Another one with deepseek-r1 with ollama.

INFO [browser_use] BrowserUse logging setup complete with level info INFO [root] Anonymized telemetry enabled. See https://github.com/browser-use/browser-use for more information. INFO [agent] πŸš€ Starting task: 1. Go to https://www.reddit.com/r/LocalLLaMA2. Search for β€˜browser use’ in the search bar3. Click search4. Call done INFO [agent] πŸ“ Step 1 ERROR [agent] ❌ Result failed 1/6 times: deepseek-r1:latest does not support tools (status code: 400) INFO [agent] πŸ“ Step 1 ERROR [agent] ❌ Result failed 2/6 times: deepseek-r1:latest does not support tools (status code: 400) INFO [agent] πŸ“ Step 1 ERROR [agent] ❌ Result failed 3/6 times: deepseek-r1:latest does not support tools (status code: 400) INFO [agent] πŸ“ Step 1 ERROR [agent] ❌ Result failed 4/6 times: deepseek-r1:latest does not support tools (status code: 400) INFO [agent] πŸ“ Step 1 ERROR [agent] ❌ Result failed 5/6 times: deepseek-r1:latest does not support tools (status code: 400) INFO [agent] πŸ“ Step 1 ERROR [agent] ❌ Result failed 6/6 times: deepseek-r1:latest does not support tools (status code: 400) ERROR [agent] ❌ Stopping due to 6 consecutive failures WARNING [agent] No history or first screenshot to create GIF from

### Code:

async def run_search():
	agent = Agent(
		task=(
			'1. Go to https://www.reddit.com/r/LocalLLaMA'
			"2. Search for 'browser use' in the search bar"
			'3. Click search'
			'4. Call done'
		),
		llm=ChatOllama(
			# model='qwen2.5:32b-instruct-q4_K_M',
			# model='qwen2.5:14b',
			model='deepseek-r1:latest',
			base_url="http://localhost:11434",
		),
		max_actions_per_step=1,
	    tool_calling_method="json_schema",
        max_failures=6,
        use_vision=False
	)

I am running ollama on GPU.

I can’t use browser-use with ollama without docker… With Docker it works with Ollama and local model llama3.1:8b

@j0yk1ll are you sure the local models are so bad?

I have now resolved my problem: https://github.com/AgenticA5/A5-Browser-Use/ simply had browser-use v0.1.21 in requirements.txt, and in that older version, the model responses were sometimes in content and sometimes in tool_calls, which was causing errors.

After an upgrade to v0.1.30, I have no issues, so it seems qwen2.5:32b-instruct-q4_K_M is adhering to the schema well. No other models tested so far.

@faizanhameed-vf @agg24ankit @surajpenugonda1 should be fixed in my fork https://github.com/j0yk1ll/open-operator

the issue stems from the go_back action. The model returns something like

{
  "action": [
    {
      "go_back": "" 
    }
  ]
}

but the go_back action doesn’t accept any input, causing an error.