Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
removed langfuse and small code cleanup
Gregor Žunič1b3de7611784
diff --git a/src/agent/prompts.py b/src/agent/prompts.pyindex 94ee79735..642673ee3 100644--- a/src/agent/prompts.py+++ b/src/agent/prompts.py@@ -1,7 +1,6 @@from langchain_core.messages import HumanMessage, SystemMessagefrom src.controller.views import ControllerPageState-from src.utils import time_execution_syncclass AgentSystemPrompt:diff --git a/src/agent/service.py b/src/agent/service.pyindex b36930046..d4c220674 100644--- a/src/agent/service.py+++ b/src/agent/service.py@@ -8,7 +8,7 @@ from src.agent.prompts import AgentMessagePrompt, AgentSystemPromptfrom src.agent.views import AgentOutput, Outputfrom src.controller.service import ControllerServicefrom src.controller.views import ControllerActionResult, ControllerPageState-from src.utils import time_execution_async, time_execution_sync+from src.utils import time_execution_asyncload_dotenv()@@ -88,20 +88,11 @@ class AgentService:new_message = AgentMessagePrompt(state).get_user_message()print(f'current tabs: {state.tabs}')input_messages = self.messages + [new_message]- # if self.use_vision:- # print(f'model input content with image: {new_message.content[0]}')- # else:- # print(f'model input: {new_message}')structured_llm = self.llm.with_structured_output(Output, include_raw=False)- # print(f'state:\n{state}')#response: Output = await structured_llm.ainvoke(input_messages) # type: ignore- # raw_response, response = invoke_response- # if store_conversation:- # # save conversation- # save_conversation(input_messages, response.model_dump_json(), store_conversation)# Only append the output messagehistory_new_message = AgentMessagePrompt(state).get_message_for_history()@@ -111,41 +102,6 @@ class AgentService:print(f'action\n: {response.action.model_dump_json(indent=4)}')self._save_conversation(input_messages, response)- # try:- # # Calculate total cost for all messages-- # # check if multiple input-- # # can not handly list of content- # output = calculate_all_costs_and_tokens(- # [system_prompt] + self.messages + [new_message],- # response.model_dump_json(),- # self.model,- # )- # if images:- # # resolution 1512 x 767- # image_cost = 0.000213- # total_cost = (- # output['prompt_cost']- # + output['completion_cost']- # + decimal.Decimal(str(image_cost))- # )- # print(- # f'Text ${output["prompt_cost"]:,.4f} + Image ${image_cost:,.4f} = ${total_cost:,.4f} for {output["prompt_tokens"] + output["completion_tokens"]} tokens'- # )- # else:- # total_cost = output['prompt_cost'] + output['completion_cost']- # print(- # f'Total cost: ${total_cost:,.4f} for {output["prompt_tokens"] + output["completion_tokens"]} tokens'- # )-- # except Exception as e:- # print(f'Error calculating prompt cost: {e}')-- # # keep newest 20 messages- # if len(self.messages) > 20:- # self.messages = self.messages[-20:]-return response.actiondef _get_action_description(self) -> str:diff --git a/src/tests/test_mind2web.py b/src/tests/test_mind2web.pyindex eaacf3022..86e819ee0 100644--- a/src/tests/test_mind2web.py+++ b/src/tests/test_mind2web.py@@ -9,8 +9,6 @@ from langchain_openai import ChatOpenAIfrom src.agent.service import AgentServicefrom src.controller.service import ControllerService-#-def setup_run_folder(timestamp_prefix: str) -> str:timestamp = f'{timestamp_prefix}_{datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}'diff --git a/src/tests/test_search.py b/src/tests/test_search.pyindex 24ea348f4..1c3130e2b 100644--- a/src/tests/test_search.py+++ b/src/tests/test_search.py@@ -5,18 +5,10 @@ import pytestfrom langchain_anthropic import ChatAnthropicfrom langchain_fireworks import ChatFireworksfrom langchain_openai import ChatOpenAI-from langfuse import Langfuse-from langfuse.decorators import observefrom src.agent.service import AgentServicefrom src.controller.service import ControllerService-langfuse = Langfuse(- secret_key=os.getenv('LANGFUSE_SECRET_KEY'),- public_key=os.getenv('LANGFUSE_PUBLIC_KEY'),- host=os.getenv('LANGFUSE_HOST'),-)-def setup_run_folder(timestamp_prefix: str) -> str:timestamp = f'{timestamp_prefix}_{datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}'@@ -35,7 +27,6 @@ def setup_run_folder(timestamp_prefix: str) -> str:# clear && pytest src/tests/test_search.py -v -s# clear && pytest src/tests/test_search.py::test_wikipedia_tabs -v -s@pytest.mark.asyncio-@observe()async def test_kayak_flight_search():task = 'go to kayak.com andfind a flight from Bali to Kirgistan on 2024-11-25 for 2 people one way.'run_folder = setup_run_folder('kayak_com_flight_search2')@@ -86,7 +77,6 @@ async def test_kayak_flight_search():# clear && pytest src/tests/test_search.py::test_wikipedia_tabs -v -s@pytest.mark.asyncio-@observe()async def test_wikipedia_tabs():# task = 'open 3 wikipedia pages in different tabs and then go back to the first one and summarize me the content of the page.'task = 'open 3 wikipedia pages in different tabs and summarize me the content of all pages.'@@ -129,7 +119,6 @@ async def test_wikipedia_tabs():# clear && pytest src/tests/test_search.py::test_albert_image_search -v -s@pytest.mark.asyncio-@observe()async def test_albert_image_search():# task = 'open 3 wikipedia pages in different tabs and then go back to the first one and summarize me the content of the page.'task = 'find an image of albert einstein, elon musk, julius caesar and steve jobs in new tabs and ask me for further instructions.'