Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

renamed planning to agent service

Gregor Žuničd5dba508e624
diff --git a/instruction.md b/instruction.md
index b93ee65df..f1da7d7e4 100644
--- a/instruction.md
+++ b/instruction.md
@@ -4,7 +4,6 @@
## **1. Project Overview**
-**Project Name**: Web-use
+**Project Name**: Web-use
**Objective**: Develop a foundational layer that enables agents (specifically Large Language Models - LLMs) to interact with the web via a set of predefined browser actions. This layer allows developers to build higher-level planning agents capable of automating complex tasks, such as applying for jobs, data scraping, form filling, etc.
-
diff --git a/src/__init__.py b/src/__init__.py
index 6a9e10885..e26f17145 100644
--- a/src/__init__.py
+++ b/src/__init__.py
@@ -1,4 +1,4 @@
-from src.planning.service import PlaningService as PlanningAgent
from src.agent.service import AgentService as WebAgent
+from src.controller.service import ControllerService as WebController
-__all__ = ['PlanningAgent', 'WebAgent']
+__all__ = ['WebAgent', 'WebController']
diff --git a/src/planning/prompts.py b/src/agent/prompts.py
similarity index 98%
rename from src/planning/prompts.py
rename to src/agent/prompts.py
index 902f62646..43b2232e2 100644
--- a/src/planning/prompts.py
+++ b/src/agent/prompts.py
@@ -3,7 +3,7 @@ from langchain_core.messages import HumanMessage, SystemMessage
from src.controller.views import ControllerPageState
-class PlanningSystemPrompt:
+class AgentSystemPrompt:
def __init__(self, task: str, default_action_description: str):
self.task = task
self.default_action_description = default_action_description
@@ -51,7 +51,7 @@ class PlanningSystemPrompt:
return SystemMessage(content=AGENT_PROMPT)
-class PlanningMessagePrompt:
+class AgentMessagePrompt:
def __init__(self, state: ControllerPageState):
self.state = state
diff --git a/src/planning/service.py b/src/agent/service.py
similarity index 71%
rename from src/planning/service.py
rename to src/agent/service.py
index 83c3cbaaa..9d5ad4ddf 100644
--- a/src/planning/service.py
+++ b/src/agent/service.py
@@ -4,13 +4,13 @@ from langchain_core.messages import AIMessage, BaseMessage, HumanMessage
from src.controller.service import ControllerService
from src.controller.views import ControllerActionResult, ControllerPageState
-from src.planning.prompts import PlanningMessagePrompt, PlanningSystemPrompt
-from src.planning.views import PlanningControllerAction
+from src.agent.prompts import AgentMessagePrompt, AgentSystemPrompt
+from src.agent.views import AgentAction
load_dotenv()
-class PlaningService:
+class AgentService:
def __init__(
self,
task: str,
@@ -19,27 +19,25 @@ class PlaningService:
use_vision: bool = False,
):
"""
- Planning service.
+ Agent service.
Args:
task (str): Task to be performed.
llm (AvailableModel): Model to be used.
- browser (BrowserService | None): You can reuse an existing browser service or (automatically) create a new one.
+ controller (ControllerService | None): You can reuse an existing or (automatically) create a new one.
"""
self.controller = controller or ControllerService()
self.use_vision = use_vision
self.llm = llm
- system_prompt = PlanningSystemPrompt(
- task, self._get_action_description()
- ).get_system_message()
+ system_prompt = AgentSystemPrompt(task, self._get_action_description()).get_system_message()
first_message = HumanMessage(content=f'Your task is: {task}')
# self.messages_all: list[BaseMessage] = []
self.messages: list[BaseMessage] = [system_prompt, first_message]
- async def step(self) -> tuple[PlanningControllerAction, ControllerActionResult]:
+ async def step(self) -> tuple[AgentAction, ControllerActionResult]:
state = self.controller.get_current_state(screenshot=self.use_vision)
action = await self.get_next_action(state)
@@ -51,26 +49,22 @@ class PlaningService:
return action, result
- async def _take_human_input(self, question: str) -> PlanningControllerAction:
+ async def _take_human_input(self, question: str) -> AgentAction:
human_input = input(f'Human input required: {question}')
self.messages.append(HumanMessage(content=human_input))
- # chain = (
- # ChatPromptTemplate.from_messages(self.messages)
- # | self.model
- # | PydanticOutputParser(pydantic_object=PlanningAgentAction)
- # )
- structured_llm = self.llm.with_structured_output(PlanningControllerAction)
- action: PlanningControllerAction = await structured_llm.ainvoke(self.messages) # type: ignore
+
+ structured_llm = self.llm.with_structured_output(AgentAction)
+ action: AgentAction = await structured_llm.ainvoke(self.messages) # type: ignore
self.messages.append(AIMessage(content=action.model_dump_json()))
return action
- async def get_next_action(self, state: ControllerPageState) -> PlanningControllerAction:
+ async def get_next_action(self, state: ControllerPageState) -> AgentAction:
# TODO: include state, actions, etc.
- new_message = PlanningMessagePrompt(state).get_user_message()
+ new_message = AgentMessagePrompt(state).get_user_message()
input_messages = self.messages + [new_message]
if self.use_vision:
@@ -78,11 +72,11 @@ class PlaningService:
else:
print(f'model input: {new_message}')
- structured_llm = self.llm.with_structured_output(PlanningControllerAction)
+ structured_llm = self.llm.with_structured_output(AgentAction)
# print(f'state:\n{state}')
- response: PlanningControllerAction = await structured_llm.ainvoke(input_messages) # type: ignore
+ response: AgentAction = await structured_llm.ainvoke(input_messages) # type: ignore
# print('response', response)
@@ -91,7 +85,7 @@ class PlaningService:
# save_conversation(input_messages, response.model_dump_json(), store_conversation)
# Only append the output message
- history_new_message = PlanningMessagePrompt(state).get_message_for_history()
+ history_new_message = AgentMessagePrompt(state).get_message_for_history()
self.messages.append(history_new_message)
self.messages.append(AIMessage(content=response.model_dump_json()))
@@ -133,4 +127,4 @@ class PlaningService:
return response
def _get_action_description(self) -> str:
- return PlanningControllerAction.description()
+ return AgentAction.description()
diff --git a/src/planning/views.py b/src/agent/views.py
similarity index 69%
rename from src/planning/views.py
rename to src/agent/views.py
index cff76a0ba..3098b0a77 100644
--- a/src/planning/views.py
+++ b/src/agent/views.py
@@ -5,15 +5,15 @@ from pydantic import BaseModel
from src.controller.views import ControllerActions
-class AskHumanPlanningAgentAction(BaseModel):
+class AskHumanAgentAction(BaseModel):
question: str
-class PlanningControllerAction(ControllerActions):
+class AgentAction(ControllerActions):
valuation_previous_goal: str
goal: str
- ask_human: Optional[AskHumanPlanningAgentAction] = None
+ ask_human: Optional[AskHumanAgentAction] = None
@staticmethod
def description() -> str:
diff --git a/src/tests/test_kayak_search.py b/src/tests/test_kayak_search.py
index 9898cce23..1377f8d78 100644
--- a/src/tests/test_kayak_search.py
+++ b/src/tests/test_kayak_search.py
@@ -5,7 +5,7 @@ import pytest
from langchain_openai import ChatOpenAI
from src.controller.service import ControllerService
-from src.planning.service import PlaningService
+from src.agent.service import AgentService
def setup_run_folder(timestamp_prefix: str) -> str:
@@ -31,7 +31,7 @@ async def test_kayak_flight_search():
controller = ControllerService()
model = ChatOpenAI(model='gpt-4o')
- planning_service = PlaningService(task, model, controller, use_vision=True)
+ agent = AgentService(task, model, controller, use_vision=True)
print('\n' + '=' * 50)
print('🚀 Starting flight search task')
@@ -41,7 +41,7 @@ async def test_kayak_flight_search():
max_steps = 50
for i in range(max_steps):
print(f'\n📍 Step {i+1}')
- action, result = await planning_service.step()
+ action, result = await agent.step()
print('action:\n', action)
print('result:\n', result)