browser-use使用 DeepSeek操作浏览器,实现自动搜索

manus 项目本质是通过 Agent 调用工具集,完成用户的任务,产品体验好,但本身没有多大的技术门槛。依赖开源的工具集和已有的大模型服务,复刻 manus 的难度不大。 智能体(Agent)调用工具,常见场景之一是自动化、智能化地浏览器。manus 的开源复现项目 openmanus,就是使用开源的 browser-use 框架进行浏览器操作的

manus 项目带火了 browser-use 项目 。browser-use 是一款基于 Python 的开源 AI 自动化工具,旨在通过集成大型语言模型(LLM)与浏览器操作,实现网页任务自动化、智能化。browser-use 可以作为智能体操作浏览器的工具框架进行使用,是智能体应用开发者值得关注学习的项目。

本文主要内容如下:

  1. 项目介绍:核心功能、面向人群。
  2. 项目代码模块分析、核心组件、执行流程时序分析。
  3. 安装步骤。
  4. 运行示例(附 python 代码):(1)搜索并总结《提振消费专项行动方案》的值得关注的内容;(2)获取豆瓣上深度学习相关 top 10 书籍信息,以结构化形式返回。

项目介绍

bowser-use 是一个允许 AI 智能体控制浏览器的 Python 库,它提供了一个简单的接口,使 AI 代理能够执行各种浏览器操作,如导航、点击、输入文本等。核心功能如下:

  • 浏览器自动化:支持网页导航、表单填写、数据抓取等操作,结合 Playwright 实现高效的浏览器控制。
  • AI 决策能力:通过 LangChain 框架兼容多种 LLM(如 GPT-4ClaudeDeepseek 等),利用模型生成操作指令并处理复杂逻辑。
  • ️ 多标签页管理:自动切换和管理多个浏览器标签页,提升多任务处理效率。
  • 自我纠正机制:在操作遇到错误时自动调整策略或重试,提高任务成功率。
  • WebUI 界面:基于 Gradio 提供图形化操作界面,支持实时查看浏览器交互和屏幕录制功能。
  • 跨平台与自定义:支持本地或 Docker 部署,允许用户使用自己的浏览器实例(如 Chrome),保留登录状态和历史记录。

bowser-use 通过结合 AI 模型与浏览器自动化技术,显著降低了复杂网页任务的开发门槛,适用于开发者、测试工程师及数据分析师等群体。其模块化设计和开放生态也使其具备较高的扩展性。

项目模块分析

各组件的相互关系

  • Agent 是核心协调者:Agent 负责协调所有组件的工作,是整个流程的中心
  • Controller 是动作执行者:Controller 负责执行各种浏览器操作,是 Agent 和 Browser 之间的桥
  • Browser 是操作对象:Browser 负责实际的浏览器操作,与网页进行交互
  • DomService 是 DOM 处理者:DomService 负责提取和处理 DOM 元素,为 Browser 提供支持
  • MessageManager 是消息管理者:MessageManager 负责管理与 LLM 的消息交互
  • LLM 是决策者:LLM 负责根据当前状态决定下一步操作
  • ProductTelemetry 是记录者:ProductTelemetry 负责记录各种事件,用于分析和改进

各组件关系,如下图所示(实线箭头表示主动调用关系,虚线箭头表示返回/被动关系。Agent作为核心协调者,管理各组件间的交互):

项目代码结构

Browser-Use 项目代码结构如下:

browser-use/
├── browser_use/           # 主要代码目录
│   ├── agent/             # AI 代理相关代码
│   ├── browser/           # 浏览器控制相关代码
│   ├── controller/        # 控制器和动作注册相关代码
│   ├── dom/               # DOM 操作和解析相关代码
│   └── telemetry/         # 遥测和数据收集相关代码
├── docs/                  # 文档
├── examples/              # 使用示例
├── static/                # 静态资源
├── tests/                 # 测试代码
└── eval/                  # 评估代码

agent 模块

agent 包是 Browser-Use 项目的核心组件,负责协调 LLM(大型语言模型)、浏览器和控制器之间的交互,实现 AI 代理控制浏览器的功能。其主要功能包括:

  • 任务规划与执行:根据用户提供的任务描述,规划并执行一系列浏览器操作。
  • 状态管理:维护代理的状态信息,包括执行步骤、历史记录等。
  • 消息管理:管理与 LLM 的消息交互,包括系统提示、用户消息和模型响应。
  • 错误处理:处理执行过程中的各种错误,并提供重试机制。
  • 历史记录:记录代理执行的每一步操作及其结果,便于分析和调试。
  • GIF 生成:可选功能,将代理操作过程记录为 GIF 动画。

controller 模块

controller 模块负责注册、管理和执行各种浏览器操作动作。它充当了 agent 包和 browser 包之间的桥梁,将 LLM 生成的指令转换为具体的浏览器操作。其主要功能包括:

  • 动作注册:提供装饰器机制,允许开发者注册自定义动作。
  • 动作执行:执行已注册的动作,处理参数验证和错误处理。
  • 动作管理:维护已注册动作的列表,提供动作描述和帮助信息。
  • 参数验证:使用 Pydantic 模型验证动作参数,确保参数类型和格式正确。
  • 默认动作提供:内置了一系列常用的浏览器操作,如导航、点击、输入文本等。
  • 异步支持:支持同步和异步动作,自动将同步动作包装为异步

browser 模块

browser 模块负责浏览器的初始化、配置和控制。它封装了 Playwright 库的功能,提供了更高级的浏览器操作接口。其主要功能包括:

  • 浏览器初始化与配置:负责初始化浏览器实例,并根据配置设置浏览器参数。
  • 浏览器上下文管理:创建和管理浏览器上下文,支持多标签页操作。
  • 页面导航与交互:提供页面导航、元素交互等功能。
  • 状态管理:维护浏览器状态,包括当前 URL、标题、标签页信息等。
  • DOM 操作:通过与 DOM 包的集成,提供 DOM 元素的查找、操作功能。
  • 错误处理:处理浏览器操作过程中的各种错误。

dom 模块

dom 模块负责处理和表示浏览器的文档对象模型(Document Object Model),提供了以下主要功能:

  • DOM树构建与管理:通过DomService类,从浏览器页面中提取DOM结构并构建成树形结构。
  • 可点击元素识别:识别和管理页面中的可点击元素,支持用户交互。
  • DOM历史记录处理:通过HistoryTreeProcessor服务,处理DOM元素的历史记录,支持元素的跟踪和比较。
  • 视口信息管理:跟踪元素在视口中的位置和可见性。

telemetry 模块

telemetry 模块是 Browser-Use 项目的辅助组件,负责收集和发送匿名使用数据,帮助开发者了解项目的使用情况和性能表现。其主要功能包括:

  • 匿名数据收集:收集用户的匿名使用数据,如代理运行情况、步骤执行、注册的功能等。
  • 事件跟踪:定义和跟踪各种遥测事件,如代理启动、步骤执行、代理结束等。
  • 数据发送:将收集的数据发送到 PostHog 分析平台。
  • 用户隐私保护:提供禁用遥测功能的选项,尊重用户隐私。
  • 用户标识管理:生成和管理匿名用户标识符,用于关联同一用户的数据。

执行流程时序分析

初始化阶段

初始化阶段主要包括以下步骤:

  1. 用户创建代理:用户提供任务描述、语言模型和浏览器实例,创建 Agent 对象
  2. 初始化消息管理器:Agent 初始化 MessageManager,设置系统提示和任务消息
  3. 初始化控制器:Agent 初始化 Controller,注册各种浏览器操作
  4. 记录遥测事件:Agent 通过 ProductTelemetry 记录代理启动事件
  5. 完成初始化:Agent 向用户返回初始化完成的信息

这个阶段建立了代理运行所需的所有组件和环境。

执行循环阶段

执行循环阶段是整个流程的核心,代理会重复执行以下步骤,直到任务完成或达到最大步骤数:

  1. 获取浏览器状态:
  • Agent 从 Browser 获取当前状态
  • Browser 通过 DomService 获取 DOM 元素和可点击元素
  • Browser 返回浏览器状态给 Agent

2. 准备 LLM 输入:

    • Agent 将浏览器状态添加到 MessageManager
    • Agent 从 MessageManager 获取完整的消息列表

3. 获取下一步操作:

    • Agent 将消息发送给 LLM
    • LLM 返回 AgentOutput,包含思考过程和要执行的动作
    • Agent 将模型输出添加到 MessageManager

4. 执行动作:

    • Agent 通过 Controller 执行动作
    • Controller 根据动作类型调用 Browser 的不同方法:
      • 导航操作:导航到指定 URL
      • 点击操作:点击页面上的元素
      • 输入操作:在元素中输入文本
      • 完成操作:标记任务完成
    • Controller 返回 ActionResult 给 Agent

5. 记录和更新状态:

    • Agent 通过 ProductTelemetry 记录步骤执行事件
    • Agent 更新自身状态,包括成功/失败状态

这个循环体现了 Browser-Use 项目的核心功能:通过 LLM 理解当前浏览器状态,决定下一步操作,并通过控制器执行操作,实现自动化浏览器任务。

结束阶段

当任务完成或达到最大步骤数时,代理会执行以下步骤:

  1. 记录结束事件:Agent 通过 ProductTelemetry 记录代理结束事件。
  2. 返回历史记录:Agent 向用户返回 AgentHistoryList,包含所有步骤的详细信息。
  3. 可选生成 GIF:如果启用了 GIF 生成功能,Agent 会处理历史记录和截图,生成一个展示整个过程的 GIF 文件。

安装

创建 python 虚拟环境:

conda create --name browser_use python=3.11
conda activate browser_use

安装 browser-use 包:

pip install browser-use -i https://pypi.tuna.tsinghua.edu.cn/simple

运行以下命令,安装 playwright:

playwright install

根据使用的大模型服务,在环境变量设置里配置相应的 API key:

  • OPENAI_API_KEY(gpt-4o 模型)
  • ANTHROPIC_API_KEY(claude 模型)
  • GEMINI_API_KEY(gemini 模型)
  • DEEPSEEK_API_KEY(deepseek 的 r1、v3 模型)

项目目录如下,.env文件中配置各平台api的key,browser_use目录为官网下载的browser use包

 

deepseek的api的key可以从https://platform.deepseek.com/api_keys中获取

 

 

运行示例:用百度搜索browser use

 python 代码-调用 deepseek 的 v3 模型:

        from dotenv import load_dotenv
        load_dotenv()
        from langchain_openai import ChatOpenAI
        from browser_use import Agent, BrowserConfig, Browser
        import asyncio
        import os
        from pydantic import SecretStr

        extend_system_message = ""

        # 配置浏览器
        config = BrowserConfig(
            chrome_instance_path=r"C:\Program Files\Google\Chrome\Application\chrome.exe",  # 可选:指定 Chrome 路径
            headless=False  # 可选:是否无头模式
        )

        api_key = os.getenv('DEEPSEEK_API_KEY')

        async def run_ai():
            browser = Browser(config=config)
            llm = ChatOpenAI(base_url='https://api.deepseek.com', model='deepseek-chat', api_key=SecretStr(api_key))
            agent = Agent(
                browser=browser,
                task=(
                    '1. 打开https://wwww.baidu.com '
                    "2. 查询'browser use'"
                    '3. 打开第一个结果'
                ),
                llm=llm,
                use_vision=False,
                message_context=extend_system_message
                # temperature = 0.7,  # 可选:调整生成温度
            )
            result = await agent.run()
            logger.debug(result)

        asyncio.run(run_ai())

 

执行结果如下:

 

执行日志:

INFO     [telemetry] Anonymized telemetry enabled. See https://docs.browser-use.com/development/telemetry for more information.
WARNING  [agent] ⚠️ DeepSeek models do not support use_vision=True yet. Setting use_vision=False for now...
INFO     [agent] 🧠 Starting an agent with main_model=deepseek-chat +tools +memory, planner_model=None, extraction_model=deepseek-chat 
WARNING  [agent] ❌ Expected LLM API Key environment variables might be missing for ChatOpenAI: OPENAI_API_KEY
INFO     [mem0.vector_stores.faiss] Loaded FAISS index from /tmp/mem0_1536_faiss/mem0.faiss with 0 vectors
INFO     [mem0.vector_stores.faiss] Loaded FAISS index from C:\Users\user\.mem0\migrations_faiss/mem0_migrations.faiss with 4 vectors
INFO     [mem0.vector_stores.faiss] Inserted 1 vectors into collection mem0_migrations
INFO     [agent] 🚀 Starting task: 1. 打开https://wwww.baidu.com 2. 查询'browser use'3. 打开第一个结果4. 返回结果
INFO     [agent] 📍 Step 1
INFO     [browser] 🔌  Reusing existing browser found running on http://localhost:9242
INFO     [agent] 🤷 Eval: Unknown - The browser is currently on a blank page (about:blank). No previous actions have been taken yet.
INFO     [agent] 🧠 Memory: Starting the task: 1. Open https://www.baidu.com. 2. Search for 'browser use'. 3. Open the first result. 4. Return the result. Currently at step 1/100.
INFO     [agent] 🎯 Next goal: Navigate to https://www.baidu.com to begin the task.
INFO     [agent] 🛠️  Action 1/1: {"go_to_url":{"url":"https://www.baidu.com"}}
INFO     [controller] 🔗  Navigated to https://www.baidu.com
INFO     [agent] 📍 Step 2
INFO     [agent] 👍 Eval: Success - Successfully navigated to https://www.baidu.com as the first step of the task.
INFO     [agent] 🧠 Memory: Task progress: 1. Opened https://www.baidu.com. 2. Next, search for 'browser use'. Currently at step 2/100.
INFO     [agent] 🎯 Next goal: Input 'browser use' into the search bar and submit the search.
INFO     [agent] 🛠️  Action 1/2: {"input_text":{"index":14,"text":"browser use"}}
INFO     [agent] 🛠️  Action 2/2: {"click_element_by_index":{"index":15}}
INFO     [controller] ⌨️  Input browser use into index 14
INFO     [agent] Element index changed after action 1 / 2, because page changed.
INFO     [agent] 📍 Step 3
INFO     [agent] 👍 Eval: Success - Successfully input 'browser use' into the search bar, but the page changed unexpectedly after the input.
INFO     [agent] 🧠 Memory: Task progress: 1. Opened https://www.baidu.com. 2. Input 'browser use' into the search bar. 3. Next, submit the search by clicking the search button. Currently at step 3/100.
INFO     [agent] 🎯 Next goal: Click the search button (index 8) to submit the search query 'browser use'.
INFO     [agent] 🛠️  Action 1/1: {"click_element_by_index":{"index":8}}
INFO     [controller] 🖱️  Clicked button with index 8: 
INFO     [agent] 📍 Step 4
INFO     [agent] 👍 Eval: Success - Successfully submitted the search query 'browser use' on Baidu, and the search results are now displayed.
INFO     [agent] 🧠 Memory: Task progress: 1. Opened https://www.baidu.com. 2. Input 'browser use' into the search bar. 3. Submitted the search. 4. Next, open the first search result. Currently at step 4/100.
INFO     [agent] 🎯 Next goal: Open the first search result (index 39) to proceed with the task.
INFO     [agent] 🛠️  Action 1/1: {"click_element_by_index":{"index":39}}
WARNING  [controller] Element not clickable with index 39 - most likely the page changed
INFO     [agent] 📍 Step 5
INFO     [agent] ⚠ Eval: Failed - Attempted to click the first search result (index 39) but encountered an error: the element was not found.
INFO     [agent] 🧠 Memory: Task progress: 1. Opened https://www.baidu.com. 2. Input 'browser use' into the search bar. 3. Submitted the search. 4. Attempted to open the first search result but failed. Currently at step 4/100.
INFO     [agent] 🎯 Next goal: Retry clicking the first search result or find an alternative method to proceed.
INFO     [agent] 🛠️  Action 1/2: {"scroll_down":{}}
INFO     [agent] 🛠️  Action 2/2: {"click_element_by_index":{"index":39}}
INFO     [controller] 🔍  Scrolled down the page by one page
INFO     [agent] Element index changed after action 1 / 2, because page changed.
INFO     [agent] 📍 Step 6
INFO     [agent] 👍 Eval: Success - Scrolled down the page to view more search results, but the first result (index 39) is still not visible or interactive.
INFO     [agent] 🧠 Memory: Task progress: 1. Opened https://www.baidu.com. 2. Input 'browser use' into the search bar. 3. Submitted the search. 4. Attempted to open the first search result but failed. 5. Scrolled down to find the first result. Currently at step 5/100.
INFO     [agent] 🎯 Next goal: Extract the content of the first search result (index 17) to proceed with the task.
INFO     [agent] 🛠️  Action 1/1: {"extract_content":{"goal":"Extract the first search result (index 17) for 'browser use'","should_strip_link_urls":true}}
INFO     [controller] 📄  Extracted from page
: browser use\_百度搜索
<style data-for="result" type="text/css" >html{font-size:100px}html body{font-size:.14rem;font-size:14px}body{color:#333;background:#fff;padding:6px 0 0;margin:0;position:relative}body,th,td,.p1,.p2{fo
nt-family:arial}p,form,ol,ul,li,dl,dt,dd,h3{margin:0;padding:0;list-style:none}input{padding-top:0;padding-bottom:0;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}table,
img{border:0}td{font-size:9pt;line-height:18px}em{font-style:normal}em{font-style:normal;color:#c00}a em{text-decoration:underline}cite{font-style:normal;color:green}.m,a.m{color:#666}a.m:visited{color
:#606}.g,a.g{color:green}.c{color:#77c}.f14{font-size:14px}.f10{font-size:10.5pt}.f16{font-size:16px}.f13{font-size:13px}.bg{background-image:url(https://pss.bdstatic.com/r/www/cache/static/protocol/ht
tps/global/img/icons\_441e82f.png);\_background-image:url(https://pss.bdstatic.com/r/www/cache/static/protocol/https/global/img/icons\_d5b04cc.gif);background-repeat:no-repeat}#u,#head,#tool,#search,#f
oot{font-size:12px}.logo{width:117px;height:38px;cursor:pointer}.p1{line-height:120%;margin-left:-12pt}.p2{width:100%;line-height:120%;margin-left:-12pt}#wrapper{\_zoom:1}#container{word-break:break-al
l;word-wrap:break-word;position:relative}.container\_s{width:1002px}.container\_l{width:1222px}#content\_left{width:636px;float:left;padding-left:35px}#content\_right{border-left:1px solid #e1e1e1;floa
t:right}.container\_s #content\_right{width:271px}.container\_l #content\_right{width:434px}.content\_none{padding-left:35px}#u{color:#999;white-space:nowrap;position:absolute;right:10px;top:4px;z-inde
x:299}#u a{color:#00c;margin:0 5px}#u .reg{margin:0}#u .last{margin-right:0}#u .un{font-weight:700;margin-right:5px}#u ul{width:100%;background:#fff;border:1px solid #9b9b9b}#u li{height:25px}#u li a{w
idth:100%;height:25px;line-height:25px;display:block;text-align:left;text-decoration:none;text-indent:6px;margin:0;filter:none\9}#u li a:hover{background:#ebebeb}#u li.nl{border-top:1px solid #ebebeb}#
user{display:inline-block}#user\_center{position:relative;display:inline-block}#user\_center .user\_center\_btn{margin-right:5px}.userMenu{width:64px;position:absolute;right:7px;\_right:2px;top:15px;to
p:14px\9;\*top:15px;padding-top:4px;display:none;\*background:#fff}#head{padding-left:35px;margin-bottom:20px;width:900px}.fm{clear:both;position:relative;z-index:297}.nv a,.nv b,.btn,#more{font-size:1
4px}.s\_nav{height:45px}.s\_nav .s\_logo{margin-right:20px;float:left}.s\_nav .s\_logo img{border:0;display:block}.s\_tab{line-height:18px;padding:20px 0 0;float:left}.s\_nav a{color:#00c;font-size:14p
x}.s\_nav b{font-size:14px}.s\_ipt\_wr{width:536px;height:30px;display:inline-block;margin-right:5px;background-position:0 -96px;border:1px solid #b6b6b6;border-color:#7b7b7b #b6b6b6 #b6b6b6 #7b7b7b;ve
rtical-align:top}.s\_ipt{width:523px;height:22px;font:16px/18px arial;line-height:22px;margin:5px 0 0 7px;padding:0;background:#fff;border:0;outline:0;-webkit-appearance:none}.s\_btn{width:95px;height:
32px;padding-top:2px\9;font-size:14px;padding:0;background-color:#ddd;background-position:0 -48px;border:0;cursor:pointer}.s\_btn\_h{background-position:-240px -48px}.s\_btn\_wr{width:97px;height:34px;
display:inline-block;background-position:-120px -48px;\*position:relative;z-index:0;vertical-align:top}.yy\_fm .s\_ipt\_wr,.yy\_fm .s\_ipt\_wr.iptfocus,.yy\_fm .s\_ipt\_wr:hover,.yy\_fm .s\_ipt\_wr.ipt
hover{border-color:#e10602 transparent #e10602 #e10602;animation:yy-ipt .2s;-moz-animation:yy-ipt .2s;-webkit-animation:yy-ipt .2s;-o-animation:yy-ipt .2s}.yy\_fm .s\_btn{background-color:#e10602;borde
r-bottom:1px solid #c30602;animation:yunying .2s;-moz-animation:yunying .2s;-webkit-animation:yunying .2s;-o-animation:yunying .2s}.yy\_fm\_blue .s\_ipt\_wr,.yy\_fm\_blue .s\_ipt\_wr.iptfocus,.yy\_fm\_
blue .s\_ipt\_wr:hover,.yy\_fm\_blue .s\_ipt\_wr.ipthover{animation:yy-ipt-blue .2s;border-color:#4791ff transparent #4791ff #4791ff}.yy\_fm\_blue .s\_btn{animation:yunying-blue .2s;background-color:#3
385ff;border-bottom:1px solid #2d78f4}@keyframes yy-ipt{0%{border-color:#4791ff transparent #4791ff #4791ff}100%{border-color:#e10602 transparent #e10602 #e10602}}@-moz-keyframes yy-ipt{0%{border-color
:#4791ff transparent #4791ff #4791ff}100%{border-color:#e10602 transparent #e10602 #e10602}}@-webkit-keyframes yy-ipt{0%{border-color:#4791ff transparent #4791ff #4791ff}100%{border-color:#e10602 trans
parent #e10602 #e10602}}@-o-keyframes yy-ipt{0%{border-color:#4791ff transparent #4791ff #4791ff}100%{border-color:#e10602 transparent #e10602 #e10602}}@keyframes yy-ipt-blue{0%{border-color:#e10602 tr
ansparent #e10602 #e10602}100%{border-color:#4791ff transparent #4791ff #4791ff}}@-moz-keyframes yy-ipt-blue{0%{border-color:#e10602 transparent #e10602 #e10602}100%{border-color:#4791ff transparent #4
791ff #4791ff}}@-webkit-keyframes yy-ipt-blue{0%{border-color:#e10602 transparent #e10602 #e10602}100%{border-color:#4791ff transparent #4791ff #4791ff}}@-o-keyframes yy-ipt-blue{0%{border-color:#e1060
2 transparent #e10602 #e10602}100%{border-color:#4791ff transparent #4791ff #4791ff}}@keyframes yunying{0%{background-color:#3385ff;border-bottom:1px solid #2d78f4}100%{background-color:#e10602;border-
bottom:1px solid #c30602}}@-moz-keyframes yunying{0%{background-color:#3385ff;border-bottom:1px solid #2d78f4}100%{background-color:#e10602;border-bottom:1px solid #c30602}}@-webkit-keyframes yunying{0
%{background-color:#3385ff;border-bottom:1px solid #2d78f4}100%{background-color:#e10602;border-bottom:1px solid #c30602}}@-o-keyframes yunying{0%{background-color:#3385ff;border-bottom:1px solid #2d78
f4}100%{background-color:#e10602;border-bottom:1px solid #c30602}}@keyframes yunying-blue{0%{background-color:#e10602;border-bottom:1px solid #c30602}100%{background-color:#3385ff;border-bottom:1px sol
id #2d78f4}}@-moz-keyframes yunying-blue{0%{background-color:#e10602;border-bottom:1px solid #c30602}100%{background-color:#3385ff;border-bottom:1px solid #2d78f4}}@-webkit-keyframes yunying-blue{0%{ba
ckground-color:#e10602;border-bottom:1px solid #c30602}100%{background-color:#3385ff;border-bottom:1px solid #2d78f4}}@-o-keyframes yunying-blue{0%{background-color:#e10602;border-bottom:1px solid #c30
602}100%{background-color:#3385ff;border-bottom:1px solid #2d78f4}}.sethf{padding:0;margin:0;font-size:14px}.set\_h{display:none;behavior:url(#default#homepage)}.set\_f{display:none}.shouji{margin-left
:19px}.shouji a{text-decoration:none}#head .bdsug{top:33px}#search form{position:relative}#search form .bdsug{bottom:33px}.bdsug{display:none;position:absolute;z-index:1;width:538px;background:#fff;bor
der:1px solid #ccc;\_overflow:hidden;box-shadow:1px 1px 3px #ededed;-webkit-box-shadow:1px 1px 3px #ededed;-moz-box-shadow:1px 1px 3px #ededed;-o-box-shadow:1px 1px 3px #ededed}.bdsug.bdsugbg ul{backgr
ound:url(https://pss.bdstatic.com/r/www/cache/static/protocol/https/home/img/sugbg\_1762fe7.png) 100% 100% no-repeat;background-size:100px 110px;background-image:url(https://pss.bdstatic.com/r/www/cach
e/static/protocol/https/home/img/sugbg\_90fc9cf.gif)\9}.bdsug li{width:522px;color:#000;font:14px arial;line-height:22px;padding:0 8px;position:relative;cursor:default}.bdsug li.bdsug-s{background:#f0f
0f0}.bdsug-store span,.bdsug-store b{color:#7A77C8}.bdsug-store-del{font-size:12px;color:#666;text-decoration:underline;position:absolute;right:8px;top:0;cursor:pointer;display:none}.bdsug-s .bdsug-sto
re-del{display:inline-block}.bdsug-ala{display:inline-block;border-bottom:1px solid #e6e6e6}.bdsug-ala h3{line-height:14px;background:url(//www.baidu.com/img/sug\_bd.png) no-repeat left center;margin:8
px 0 5px;font-size:12px;font-weight:400;color:#7B7B7B;padding-left:20px}.bdsug-ala p{font-size:14px;font-weight:700;padding-left:20px}.bdsug .bdsug-direct{width:auto;padding:0;border-bottom:1px solid #
f1f1f1}.bdsug .bdsug-direct p{color:#00c;font-weight:700;line-height:34px;padding:0 8px;cursor:pointer;white-space:nowrap;overflow:hidden}.bdsug .bdsug-direct p img{width:16px;height:16px;margin:7px 6p
x 9px 0;vertical-align:middle}.bdsug .bdsug-direct p span{margin-left:8px}.bdsug .bdsug-direct p i{font-size:12px;line-height:100%;font-style:normal;font-weight:400;color:#fff;background-color:#2b99ff;
display:inline;text-align:center;padding:1px 5px;\*padding:2px 5px 0;margin-left:8px;overflow:hidden}.bdsug .bdsug-pcDirect{color:#000;font-size:14px;line-height:30px;height:30px;background-color:#f8f8
f8}.bdsug .bdsug-pc-direct-tip{position:absolute;right:15px;top:8px;width:55px;height:15px;display:block;background:url(https://pss.bdstatic.com/r/www/cache/static/protocol/https/global/img/pc\_direct\
_42d6311.png) no-repeat 0 0}.bdsug li.bdsug-pcDirect-s{background-color:#f0f0f0}.bdsug .bdsug-pcDirect-is{color:#000;font-size:14px;line-height:22px;background-color:#f8f8f8}.bdsug .bdsug-pc-direct-tip
-is{position:absolute;right:15px;top:3px;width:55px;height:15px;display:block;background:url(https://pss.bdstatic.com/r/www/cache/static/protocol/https/global/img/pc\_direct\_42d6311.png) no-repeat 0 0
}.bdsug li.bdsug-pcDirect-is-s{background-color:#f0f0f0}.bdsug .bdsug-pcDirect-s .bdsug-pc-direct-tip,.bdsug .bdsug-pcDirect-is-s .bdsug-pc-direct-tip-is{background-position:0 -15px}.bdsug .bdsug-newic
on{color:#929292;opacity:.7;font-size:12px;display:inline-block;line-height:22px;letter-spacing:2px}.bdsug .bdsug-s .bdsug-newicon{opacity:1}.bdsug .bdsug-newicon i{letter-spacing:0;font-style:normal}.
bdsug .bdsug-feedback-wrap{text-align:right;background:#fafafa;color:#666;height:25px;line-height:27px}.bdsug .bdsug-feedback{margin-right:10px;text-decoration:underline;color:#666}.toggle-underline{te
xt-decoration:none}.toggle-underline:hover{text-decoration:underline}#tb\_mr{color:#00c;cursor:pointer;position:relative;z-index:298}#tb\_mr b{font-weight:400;text-decoration:underline}#tb\_mr small{fo
nt-size:11px}#rs{width:900px;background:#fff;padding:8px 0;margin:20px 0 0 15px}#rs td{width:5%}#rs th{font-size:14px;font-weight:400;line-height:19px;white-space:nowrap;text-align:left;vertical-align:
top}#rs .tt{font-weight:700;padding:0 10px 0 20px}#rs .tt\_normal{font-weight:400}#rs\_top{font-size:14px;margin-bottom:22px}#rs\_top a{margin-right:18px}#container .rs{margin:30px 0 20px;padding:5px 0
 15px;font-size:14px;width:540px;padding-left:121px;position:relative;background-color:#fafafa}#container .noback{background-color:#fff}#content\_left .rs{margin-left:-121px}#container .rs table{width:
540px}#container .rs td{width:5px}#container .rs th{font-size:14px;font-weight:400;white-space:nowrap;text-align:left;vertical-align:top;width:175px;line-height:22px}#container .rs .tt{font-weight:700;
padding:0 10px 0 20px;padding:0;line-height:30px;font-size:16px}#container .rs a{margin:0;height:24px;width:173px;display:inline-block;line-height:25px;border:1px solid #ebebeb;text-align:center;vertic
al-align:middle;overflow:hidden;outline:0;color:#333;background-color:#fff;text-decoration:none}#container .rs a:hover{border-color:#388bff}.c-tip-con .c-tip-menu-b ul{width:100px}.c-tip-con .c-tip-men
u-b ul{text-align:center}.c-tip-con .c-tip-menu-b li a{display:block;text-decoration:none;cursor:pointer;background-color:#fff;padding:3px 0;color:#666}.c-tip-con .c-tip-menu-b li a:hover{display:block
;background-color:#ebebeb}.c-tip-con.baozhang-r-tip{visibility:hidden}.aviation-new a{background:0 0;color:#91B9F7;font-size:16px;width:16px;height:auto;vertical-align:top}.c-tip-con.custom-wrap-tip .c
-tip-info{width:auto}.c-tip-con.aviation-wrap-tip{box-shadow:0 2px 10px 0 rgba(0,0,0,.1);border-radius:12px;border:0;padding:12px}.c-tip-con.aviation-wrap-tip .c-tip-info{margin:0;width:auto}.c-tip-con
.aviation-wrap-tip .c-tip-item-i{padding:0;line-height:1}.c-tip-con.aviation-wrap-tip .c-tip-item-i .c-tip-item-icon{margin-left:0}.c-tip-con.aviation-wrap-tip .aviation-title{line-height:1}#search{wid
th:900px;padding:35px 0 16px 35px}#search .s\_help{position:relative;top:10px}.site\_tip{font-size:12px;margin-bottom:20px}.site\_tip\_icon{width:56px;height:56px;background:url(//www.baidu.com/aladdin
/img/tools/tools-3.png) -288px 0 no-repeat}.to\_zhidao,.to\_tieba,.to\_zhidao\_bottom{font-size:16px;line-height:24px;margin:20px 0 0 35px}.to\_tieba .c-icon-tieba{float:left}.f{line-height:115%;\*line
-height:120%;font-size:100%;width:33.7em;word-break:break-all;word-wrap:break-word}.h{margin-left:8px;width:100%}.r{word-break:break-all;cursor:hand;width:238px}.t{font-weight:400;font-size:medium;marg
in-bottom:1px}.pl{padding-left:3px;height:8px;padding-right:2px;font-size:14px}.mo,a.mo:link,a.mo:visited{color:#666;font-size:100%;line-height:10px}.htb{margin-bottom:5px}.jc a{color:#c00}a font[size=
"3"] font,font[size="3"] a font{text-decoration:underline}div.blog,div.bbs{color:#707070;padding-top:2px;font-size:13px}.result{width:33.7em;table-layout:fixed}.result-op .f{word-wrap:normal}.nums{font
-size:12px;color:#999}.tools{position:absolute;top:10px;white-space:nowrap}#mHolder{width:62px;position:relative;z-index:296;top:-18px;margin-left:9px;margin-right:-12px;display:none}#mCon{height:18px;
position:absolute;top:3px;top:6px\9;cursor:pointer;line-height:18px}.wrapper\_l #mCon{right:7px}#mCon span{color:#00c;display:block}#mCon .hw{text-decoration:underline;cursor:pointer;display:inline-blo
ck}#mCon .pinyin{display:inline-block}#mCon .c-icon-chevron-unfold2{margin-left:5px}#mMenu{width:56px;border:1px solid #9b9b9b;position:absolute;right:7px;top:23px;display:none;background:#fff}#mMenu a
{width:100%;height:100%;color:#00c;display:block;line-height:22px;text-indent:6px;text-decoration:none;filter:none\9}#mMenu a:hover{background:#ebebeb}#mMenu .ln{height:1px;background:#ebebeb;overflow:
hidden;font-size:1px;line-height:1px;margin-top:-1px}.op\_LAMP{background:url(//www.baidu.com/cache/global/img/aladdinIcon-1.0.gif) no-repeat 0 2px;color:#77C;display:inline-block;font-size:13px;height
:12px;\*height:14px;width:16px;text-decoration:none;zoom:1}.EC\_mr15{margin-left:0}.pd15{padding-left:0}.map\_1{width:30em;font-size:80%;line-height:145%}.map\_2{width:25em;font-size:80%;line-height:14
5%}.favurl{background-repeat:no-repeat;background-position:0 1px;padding-left:20px}.dan\_tip{font-size:12px;margin-top:4px}.dan\_tip a{color:#b95b07}#more,#u ul,#mMenu,.msg\_holder{box-shadow:1px 1px 2
px #ccc;-moz-box-shadow:1px 1px 2px #ccc;-webkit-box-shadow:1px 1px 2px #ccc;filter:progid:DXImageTransform.Microsoft.Shadow(Strength=2, Direction=135, Color=#cccccc)\9}.hit\_top{line-height:18px;margi
n:0 15px 10px 0;width:516px}.hit\_top .c-icon-bear{height:18px;margin-right:4px}#rs\_top\_new,.hit\_top\_new{width:538px;font-size:13px;line-height:1.54;word-wrap:break-word;word-break:break-all;margin
:0 0 14px}.zhannei-si{margin:0 0 10px 121px}.zhannei-si-none{margin:10px 0 -10px 121px}.zhannei-search{margin:10px 0 0 121px;color:#999;font-size:14px}.f a font[size="3"] font,.f font[size="-1"] a font
{text-decoration:underline}h3 a font{text-decoration:underline}.c-title{font-weight:400;font-size:16px}.c-title-size{font-size:16px}.c-abstract{font-size:13px}.c-abstract-size{font-size:13px}.c-showurl
{color:green;font-size:13px}.c-showurl-color{color:green}.c-cache-color{color:#666}.c-lightblue{color:#77c}.c-highlight-color{color:#c00}.c-clearfix:after{content:".";display:block;height:0;clear:both;
visibility:hidden}.c-clearfix{zoom:1}.c-wrap{word-break:break-all;word-wrap:break-word}.c-icons-outer{overflow:hidden;display:inline-block;vertical-align:bottom;\*vertical-align:-1px;\_vertical-align:b
ottom}.c-icons-inner{margin-left:-4px;display:inline-block}.c-container table.result,.c-container table.result-op{width:100%}.c-container td.f{font-size:13px;line-height:1.54;width:auto}.c-container .vd\_newest\_main{width:auto}.INFO     [agent] 📍 Step 7
ERROR    [agent] ❌ Result failed 1/3 times:
 Error code: 400 - {'error': {'message': "This model's maximum context length is 65536 tokens. However, you requested 99540 tokens (99540 in the messages, 0 in the completion). Please reduce the length of the messages or completion.", 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}
INFO     [agent] 📍 Step 7
INFO     [agent] 👍 Eval: Success - Found the first search result for 'browser use' (index 17) and extracted its content.
INFO     [agent] 🧠 Memory: Task progress: 1. Opened https://www.baidu.com. 2. Input 'browser use' into the search bar. 3. Submitted the search. 4. Extracted the first search result (index 17). Currently at step 5/100.
INFO     [agent] 🎯 Next goal: Open the first search result (index 17) to proceed with the task.
INFO     [agent] 🛠️  Action 1/1: {"click_element_by_index":{"index":17}}
INFO     [controller] 🖱️  Clicked button with index 17: 
INFO     [agent] 📍 Step 8
WARNING  [browser] 👁️ Foregound tab changed by human from baidu.com/s?ie=utf-8&f… to blog.csdn.net/weixin_4… (navigation) but agent will stay on baidu.com/s?ie=utf-8&f…
INFO     [agent] 👍 Eval: Success - Successfully clicked the first search result (index 17) for 'browser use', which opened a new tab with the article about 'Browser Use'.
INFO     [agent] 🧠 Memory: Task progress: 1. Opened https://www.baidu.com. 2. Input 'browser use' into the search bar. 3. Submitted the search. 4. Clicked the first search result (index 17). 5. Now on the article page about 'Browser Use'. Currently at step 5/100.
INFO     [agent] 🎯 Next goal: Extract the content of the article to fulfill the task requirement of returning the result.
INFO     [agent] 🛠️  Action 1/2: {"switch_tab":{"page_id":1}}
INFO     [agent] 🛠️  Action 2/2: {"extract_content":{"goal":"Extract the content of the article about 'Browser Use'","should_strip_link_urls":true}}
INFO     [controller] 🔄  Switched to tab 1
INFO     [controller] 📄  Extracted from page
: ```json
{
  "title": "Browser Use:AI智能体自动化操作浏览器的开源工具",
  "author": "blues_C",
  "publish_date": "2024-12-27 14:20:08",
  "update_date": "2025-06-02 16:20:32",
  "read_count": "1.2w",
  "likes": 10,
  "favorites": 23,
  "tags": ["人工智能", "自动化", "AI", "python"],
  "categories": ["AI测试:从入门到进阶"],
  "license": "CC 4.0 BY-SA",
  "original_link": "https://blog.csdn.net/weixin_48321392/article/details/144763659",
  "content": {
    "introduction": "Browser Use 是一个Python库,它能够帮助我们将AI代理与浏览器自动化操作结合起来。通过这个库,我们可以定义AI代理的任务,允许其在浏览器中执行特定操作,如访问网页、点击按钮、填写表单、提网页信息等。Browser Use结合了浏览器自动化(Playwright)工具,能够提供稳定的跨平台支持,使得我们能够在不同操作系统上运行自动化任务。",
    "github_link": "https://github.com/browser-use/browser-use",
    "installation": {
      "description": "首先,我们需要安装browser-use和playwright。可以通过以下命令安装:",
      "command": "pip install browser-use playwright"
    },
    "steps": [
      {
        "step": "1. 安装所需依赖",
        "details": "安装browser-use和playwright。"
      },
      {
        "step": "2. 生成openai密钥",
        "details": "获取OpenAI API密钥以使用AI功能。"
      },
      {
        "step": "3. 编写代码",
        "details": "编写代码定义AI代理的任务。"
      },
      {
        "step": "4. 运行代码",
        "details": "执行代码以启动自动化任务。"
      },
      {
        "step": "5. 部署与优化",
        "substeps": [
          {
            "step": "5.1 部署AI代理",
            "details": "将AI代理部署到生产环境。"
          },
          {
            "step": "5.2 优化与扩展",
            "details": "优化性能并扩展功能。"
          }
        ]
      }
    ],
    "conclusion": "Browser Use 是一个强大的工具,能够将AI代理与浏览器自动化操作结合起来,适用于各种自动化任务。通过简单的安装和配置,开发者可以快速上手并利用其强大的功能。"
  },
  "comments": [
    {
      "user": "blues_C",
      "comment": "JWT 将所有必要的用户信息都加密存储在 Token 自身之中,并由客户端在每次请求时发回给服务器。服务器不需要在数据库或内存中保存任何用户的登录状态(Session)。它只需验证收到的 Token 是否有效可。由于服务器不保存状态,任何一台服务器都能验证同一个 Token。可以增加更多的服务器来分担流量,无需处理复杂的会话同步问题。"
    },
    {
      "user": "征途黯然.",
      "comment": "【问题】JWT认证如何确保无状态且易于水平扩展?"
    }
  ],
  "related_articles": [
    {
      "title": "AI智能体,AI computer use:浏览器使用(Browser Use)项目实际体验,deepseek r1,百度云,满血版",
      "link": "https://blog.csdn.net/xiezhipu/article/details/details/144763659"
    },
    {
      "title": "Browser Use:AI如何“操控”浏览器进行自动化测试?",
      "link": "https://blog.csdn.net/zhangkexin_z/article/details/details/144763659"
    }
  ]
}
```

INFO     [agent] 📍 Step 9
INFO     [agent] 👍 Eval: Success - Successfully extracted the content of the article about 'Browser Use' from the first search result.
INFO     [agent] 🧠 Memory: Task progress: 1. Opened https://www.baidu.com. 2. Input 'browser use' into the search bar. 3. Submitted the search. 4. Clicked the first search result (index 17). 5. Extracted the article content. Currently at step 6/100.
INFO     [agent] 🎯 Next goal: Complete the task by returning the extracted result.
INFO     [agent] 🛠️  Action 1/1: {"done":{"text":"The first search result for 'browser use' is an article titled 'Browser Use:AI智能体自动化操作浏览器的开源工具' by blues_C. It discusses a Python lir
ary called Browser Use that combines AI agents with browser automation (using Playwright) for tasks like visiting web pages, clicking buttons, filling forms, and extracting information. The article inc
ludes installation instructions, usage steps, and a conclusion highlighting its versatility for automation tasks. GitHub link: https://github.com/browser-use/browser-use. Original article link: https://blog.csdn.net/weixin_48321392/article/details/144763659.","success":true}}
INFO     [agent] 📄 Result: The first search result for 'browser use' is an article titled 'Browser Use:AI智能体自动化操作浏览器的开源工具' by blues_C. It discusses a Python library called Browser Use
 that combines AI agents with browser automation (using Playwright) for tasks like visiting web pages, clicking buttons, filling forms, and extracting information. The article includes installation ins
tructions, usage steps, and a conclusion highlighting its versatility for automation tasks. GitHub link: https://github.com/browser-use/browser-use. Original article link: https://blog.csdn.net/weixin_48321392/article/details/144763659.
INFO     [agent] ✅ Task completed
INFO     [agent] ✅ Successfully
INFO     [agent] 📝 Total input tokens used (approximate): 121166
INFO     [agent] Agent run telemetry logged.
View Code

 

转:https://zhuanlan.zhihu.com/p/1885651451088462924

posted @ 2025-06-10 15:49  rmticocean  阅读(625)  评论(2)    收藏  举报