Skip to content

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

Fix include index in current element

magmuellerc60cf381a4ee
diff --git a/src/dom/views.py b/src/dom/views.py
index cebd77550..ae47318e2 100644
--- a/src/dom/views.py
+++ b/src/dom/views.py
@@ -12,4 +12,4 @@ class ProcessedDomContent(BaseModel):
def dom_items_to_string(self) -> str:
"""Convert the processed DOM content to HTML."""
- return '\n'.join([item.text for item in self.items])
+ return '\n'.join([f'{item.index}:{item.text}' for item in self.items])
diff --git a/src/planning/prompts.py b/src/planning/prompts.py
index 4b867d8da..ad12c8917 100644
--- a/src/planning/prompts.py
+++ b/src/planning/prompts.py
@@ -1,4 +1,4 @@
-from langchain_core.messages import SystemMessage, HumanMessage
+from langchain_core.messages import HumanMessage, SystemMessage
from src.agent.views import AgentPageState
@@ -57,7 +57,7 @@ class PlanningMessagePrompt:
def get_user_message(self) -> HumanMessage:
state_description = f"""
-Currently on url: {self.state.url}
+Current url: {self.state.url}
Interactive elements:
{self.state.dom_items_to_string()}
diff --git a/src/planning/service.py b/src/planning/service.py
index 822ea1f62..ad4b4a73f 100644
--- a/src/planning/service.py
+++ b/src/planning/service.py
@@ -61,7 +61,6 @@ class PlaningService:
# | self.model
# | PydanticOutputParser(pydantic_object=PlanningAgentAction)
# )
-
structured_llm = self.llm.with_structured_output(PlanningAgentAction)
action: PlanningAgentAction = await structured_llm.ainvoke(self.messages) # type: ignore
@@ -75,9 +74,10 @@ class PlaningService:
new_message = PlanningMessagePrompt(state).get_user_message()
input_messages = self.messages + [new_message]
+ print(f'model input: {input_messages}')
structured_llm = self.llm.with_structured_output(PlanningAgentAction)
- print(f'state:\n{state}')
+ # print(f'state:\n{state}')
input('continue? ...')