mirror of
https://github.com/browser-use/browser-use
synced 2026-05-06 17:52:15 +02:00
* Validator * Test mind2web * Cleaned up logger * Pytest logger * Cleaned up logger * Disable flag for human input * Multiple clicks per button * Multiple clicks per button * More structured system prompt * Fields with description * System prompt example * One logger * Cleaner logging * Log step in step function * Fix critical clicking error - wrong argument used * Improved thought process of agent * Improve system prompt * Remove human input message * Custome action registration * Pydantic model for custom actions * Pydantic model for custome output * Runs through, model outputs functions, but not called yet * Work in progress - description for custome actions * Description works, but schema not yet * Model can call the right action - but is not executed * Seperate is_controller_action and is_custom_action * Works! Model can call custom function * Use registry for action, but result is not feed back to model * Include result in messages * Works with custom function - but typing is not correct * Renamed registry * First test cases * Captcha tests * Pydantic for tests * Improve prompts for multy step * System prompt structure * Handle errors like validation error * Refactor error handling in agent * Refactor error handling in agent * Improved logging * Update view * Fix click parameter to index * Simplify dynamic actions * Use run instead of step * Rename history * Rename AgentService to Agent * Rename ControllerService to Controller * Pytest file * Rename get state * Rename BrowserService * reversed dom extraction recursion to while * Rename use_vision * Rename use_vision * reversed dom tree items and made browser less anoying * Renaming and fixing type errors * Renamed class names for agent * updated requirements * Update prompt * Action registration works for user and controller * Fix done call by returning ActionResult * Fix if result is none * Rename AgentOutput and ActionModel * Improved prompt Passes 6/8 tests from test_agent_actions * Calculate token cost * Improve display * Simplified logger * Test function calling * created super simple xpath extraction algo * Tests logging * tiny fixes to dom extraction * Remove test * Dont log number of clicks * Pytest file * merged per element js checks * Check if driver is still open * super fast processing * fixed agent planning and stuff * Fix example * Fix example * Improve error * Improved error correction * New line for step * small type error fixes * Test for pydantic * Fix line * Removed sample * fixed readme and examples --------- Co-authored-by: magmueller <mamagnus00@gmail.com>
61 lines
1.2 KiB
Python
61 lines
1.2 KiB
Python
"""
|
|
Simple try of the agent.
|
|
|
|
@dev You need to add ANTHROPIC_API_KEY to your environment variables.
|
|
"""
|
|
|
|
import logging
|
|
import os
|
|
import sys
|
|
|
|
from langchain_anthropic import ChatAnthropic
|
|
from langchain_openai import ChatOpenAI
|
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
import argparse
|
|
import asyncio
|
|
|
|
from browser_use import Agent
|
|
from browser_use.controller.service import Controller
|
|
|
|
|
|
def get_llm(provider: str):
|
|
if provider == 'anthropic':
|
|
return ChatAnthropic(
|
|
model_name='claude-3-5-sonnet-20240620', timeout=25, stop=None, temperature=0.3
|
|
)
|
|
elif provider == 'openai':
|
|
return ChatOpenAI(model='gpt-4o', temperature=0.3)
|
|
else:
|
|
raise ValueError(f'Unsupported provider: {provider}')
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('query', type=str, help='The query to process')
|
|
parser.add_argument(
|
|
'--provider',
|
|
type=str,
|
|
choices=['openai', 'anthropic'],
|
|
default='openai',
|
|
help='The model provider to use (default: openai)',
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
llm = get_llm(args.provider)
|
|
|
|
agent = Agent(
|
|
task=args.query,
|
|
llm=llm,
|
|
controller=Controller(keep_open=True),
|
|
# save_conversation_path='./tmp/try_flight/',
|
|
)
|
|
|
|
|
|
async def main():
|
|
await agent.run()
|
|
|
|
|
|
asyncio.run(main())
|