agent-programming
Write and debug Browser Use Python agent workflows with legacy browser_use.Agent and Rust-backed browser_use.beta.Agent, including prompts, run loops, callbacks, initial_actions, planning, timeouts, flash mode, history, and API routing.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- agent-programming
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Write and debug Browser Use Python agent workflows with legacy browser_use.Agent and Rust-backed browser_use.beta.Agent, including prompts, run loops, callbacks, initial_actions, planning, timeouts, flash mode, history, and API routing.
- disable-model-invocation
- true
02 资源文件 3
- 参考文档references/agent-api.md11.3 KB
- 参考文档references/troubleshooting.md8.5 KB
- 参考文档references/workflows.md8.9 KB
03 SKILL.md 正文
Agent Programming
Use this sub-skill when the user is writing Python code around Browser Use agents: constructing an agent, designing the task prompt, running it in an async loop, inspecting history, adding callbacks, preloading initial actions, choosing legacy vs beta agent entrypoints, or debugging agent-loop behavior.
Route Here
- The user imports
Agentfrombrowser_useorbrowser_use.beta. - The task is about
Agent(...),await agent.run(...),agent.step(...),agent.take_step(...), callbacks, stop/pause hooks, history parsing, or prompt design. - The request mentions
initial_actions,max_steps,max_failures,llm_timeout,step_timeout,flash_mode,enable_planning,message_compaction,save_conversation_path, orgenerate_gif. - The user wants to compare legacy Python agent behavior with the beta Rust-backed agent.
- The user hit a workflow symptom such as empty history, repeated actions, planning not showing, initial navigation failing, final result missing, or
BetaAgentError.
Route Elsewhere
- Browser/profile/CDP/session launch settings, real Chrome profiles, downloads, proxies, screenshots, videos, HAR, domains, and low-level Actor APIs belong in
../browser-control/SKILL.md. - Custom actions, default tools, file tools, action schemas,
ActionResult, sensitive data guardrails, and domain/file security belong in../tools-and-actions/SKILL.md. - LLM provider selection, API keys,
ChatBrowserUse, structured output, extraction models, fallback models, and cost accounting belong in../llm-and-output/SKILL.md. - Terminal
browser-useorbuCLI sessions belong in../cli-and-sessions/SKILL.md. - Cloud sandbox, MCP, skill services, telemetry, hosted production, and integration workflows belong in
../production-integrations/SKILL.md.
Entry Point Choice
Prefer the legacy Python agent when the user needs maximum open-source Python extensibility:
from browser_use import Agent, ChatBrowserUse
Prefer the beta agent when the user asks for the Rust-backed/core runtime path or is following the 0.13 beta quickstart:
from browser_use.beta import Agent, BrowserProfile, ChatBrowserUse
The public package exposes both paths. Existing Python code can keep from browser_use import Agent; the beta path is explicitly from browser_use.beta import Agent and requires the Browser Use terminal/core runtime to be available.
Safe Default Agent Pattern
Use an explicit async main(), load environment variables outside the skill content, and set a small step limit during debugging:
import asyncio
from browser_use import Agent, ChatBrowserUse
async def main():
agent = Agent(
task="Go to https://example.com and report the page title.",
llm=ChatBrowserUse(),
)
history = await agent.run(max_steps=20)
print(history.final_result() or "No final result")
asyncio.run(main())
For new Browser Use automation tasks, recommend ChatBrowserUse() as the default model because Browser Use maintains it for browser automation. Do not replace user-specified model names in existing code.
Prompt Design Checklist
- Make browser tasks explicit: start URL, goal, fields to extract, output format, login assumptions, and fallback path.
- Name default actions when deterministic behavior matters:
navigate,click,input,scroll,extract,send_keys,done. - Add recovery instructions for flaky sites: try keyboard navigation, wait/refresh once, use search fallback, or stop with a clear reason.
- Keep credentials out of prompts; use approved sensitive-data or custom-tool patterns from sibling skills.
- For multi-step tasks, ask for intermediate validation and a final
doneresult rather than open-ended browsing.
See references/workflows.md for reusable recipes.
Core Constructor Knobs
Use references/agent-api.md for parameter details. The most common agent-programming knobs are:
task: natural-language browser objective; include a URL ifdirectly_open_url=Trueshould pre-navigate.llm: model object; when omitted, Browser Use resolves a configured default or createsChatBrowserUse().initial_actions: ordered list of action dictionaries executed before model-driven steps.max_failures,final_response_after_failure: controls failure stopping and final recovery call.llm_timeout,step_timeout: separate model-call and per-step/action watchdogs.max_actions_per_step: lets the model emit multiple actions in a single step.flash_mode: faster output shape; strips thinking and planning fields and disables planning.enable_planning,planning_replan_on_stall,planning_exploration_limit: plan/replan nudges for full-mode agents.register_new_step_callback,register_done_callback,on_step_start,on_step_end: observe or interrupt run progress.save_conversation_path,generate_gif,max_history_items,message_compaction: debugging and memory controls.
Initial Actions
Use initial_actions when setup is deterministic and should happen before the model reasons:
initial_actions = [
{"navigate": {"url": "https://example.com", "new_tab": False}},
]
agent = Agent(task="Summarize the landing page", llm=llm, initial_actions=initial_actions)
Notes:
- Legacy and beta agents convert action dictionaries through the current tool registry when possible.
- The beta agent preserves the original ordered payloads in task context and maps legacy aliases such as
click_element_by_indexto current action names when possible. - If
directly_open_url=Trueand the task contains a URL, Browser Use can add an initialnavigateaction automatically when no explicitinitial_actionsare supplied. - Initial actions can time out or fail before any model step; inspect history and
history.errors().
Running and Observing
- Use
history = await agent.run(max_steps=...)for normal execution. - Use
on_step_start(agent)andon_step_end(agent)when you need per-step hooks around the run loop. - Use constructor callbacks for external systems:
register_new_step_callback(state, model_output, step_number)can be sync or async.register_done_callback(history)can be sync or async.register_should_stop_callback()andregister_external_agent_status_raise_error_callback()can stop or fail externally.
- For beta follow-up tasks, call
await agent.follow_up("...", max_steps=...)only after a successfulrun()created an active Rust session.
Reading History
Agent.run() returns AgentHistoryList. Use its helper methods instead of parsing private fields:
history = await agent.run(max_steps=30)
print(history.final_result())
print(history.is_done(), history.is_successful())
print(history.urls())
print(history.action_names())
print(history.errors())
Useful helpers include final_result(), is_done(), is_successful(), has_errors(), urls(), screenshot_paths(), screenshots(), action_names(), model_actions(), model_outputs(), model_thoughts(), action_results(), action_history(), extracted_content(), number_of_steps(), total_duration_seconds(), and save_to_file(...).
For Pydantic structured output, prefer the sibling model/output guidance. At the agent-programming level, remember that history.structured_output only works when the history retains the output model schema; otherwise use history.get_structured_output(MyModel).
Planning and Flash Mode
- Full-mode output can include thinking, previous-goal evaluation, memory, next goal, current plan item, and plan updates.
enable_planning=Falsemakes plan rendering and plan updates no-ops.flash_mode=Trueremoves thinking and planning fields from the output schema and forcesenable_planning=False.- In the current implementation, a Browser Use provider model automatically enables flash mode; use a non-flash-compatible configuration if the user specifically needs plan fields.
- Replan nudges are soft context messages; they do not block repeated actions.
Beta/Core Routing
The beta agent is a Python wrapper around a Rust Browser Use terminal SDK server. Use it when the user explicitly asks for beta/core behavior or imports from browser_use.beta.
from browser_use.beta import Agent, ChatBrowserUse
agent = Agent(task="Open https://example.com and report the title", llm=ChatBrowserUse())
history = await agent.run(max_steps=20)
Beta-specific notes:
find_browser_use_terminal_binary()locates the required terminal binary.- Missing terminal/core runtime raises
BetaAgentErrorwith instructions to install Browser Use Terminal/core or setBROWSER_USE_TERMINAL_BINARY. run(max_steps=100)delegates the main loop to the SDK server after Python-side setup and initial actions.take_step(...)can execute initial actions and then run one SDK step.follow_up(...)requires an active Rust session from a priorrun().
Validation Commands
Use this portable check when validating agent code or reproducing issues:
python - <<'PY'
from browser_use import Agent, ChatBrowserUse
from browser_use.beta import Agent as BetaAgent
print(Agent, ChatBrowserUse, BetaAgent)
PY
For normal user projects, prefer import/signature smoke checks and small scripts with max_steps capped. Run source-checkout test suites only when the user is explicitly maintaining Browser Use itself.
Troubleshooting First Steps
See references/troubleshooting.md for symptoms and fixes. Start with:
- Confirm
browser-useimports and Chromium/Browser Use terminal dependencies are installed for the chosen agent path. - Confirm the relevant provider API key is present without printing it.
- Reduce to a minimal
Agent(task="Open https://example.com...", max_steps=5)script. - Lower complexity: remove custom tools, structured output, proxies, and persistent profiles until the run loop works.
- Inspect
history.errors(),history.action_names(), and saved conversation logs. - If initial actions fail, set
step_timeout, disable automatic URL pre-navigation withdirectly_open_url=False, or make the first navigation explicit.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).