Skip to content

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

Merge branch 'main' of https://github.com/gregpr07/agentweb

magmueller86cf02ab4a6e
diff --cc examples/simple_run.py
index 05e5fb887,fe30364f5..46ae51815
--- a/examples/simple_run.py
+++ b/examples/simple_run.py
@@@ -17,9 -16,11 +18,11 @@@ from langchain_openai import ChatOpenA
from src import Agent
+ logging.basicConfig(level=logging.INFO)
+
llm = ChatOpenAI(model='gpt-4o')
agent = Agent(
- task='Find cheapest flights on kayak.com from London to Kyrgyzstan and return the url.',
+ task='Opening new tabs to search for images of Albert Einstein, Oprah Winfrey, and Steve Jobs. Then ask user for further instructions.',
llm=llm,
)
diff --cc src/agent/service.py
index f09512afa,0b2b93b90..165f2821f
--- a/src/agent/service.py
+++ b/src/agent/service.py
@@@ -103,10 -112,41 +112,41 @@@ class AgentService
self.messages.append(
HumanMessage(content=f'Extracted content: {result.extracted_content}')
)
- return action, result
+
+ # Convert action to history and update click/input fields if present
+ history_item = self._make_history_item(action, state)
+ self.action_history.append(history_item)
+
+ return history_item, result
+
+ def _make_history_item(self, action: AgentOutput, state: ControllerPageState) -> AgentHistory:
+ return AgentHistory(
+ search_google=action.search_google,
+ go_to_url=action.go_to_url,
+ nothing=action.nothing,
+ go_back=action.go_back,
+ done=action.done,
+ click_element=ClickElementControllerHistoryItem(
+ id=action.click_element.id, xpath=state.selector_map.get(action.click_element.id)
+ )
+ if action.click_element and state.selector_map.get(action.click_element.id)
+ else None,
+ input_text=InputTextControllerHistoryItem(
+ id=action.input_text.id,
+ xpath=state.selector_map.get(action.input_text.id),
+ text=action.input_text.text,
+ )
+ if action.input_text and state.selector_map.get(action.input_text.id)
+ else None,
+ extract_page_content=action.extract_page_content,
+ switch_tab=action.switch_tab,
+ open_tab=action.open_tab,
+ ask_human=action.ask_human,
+ url=state.url,
+ )
async def _take_human_input(self, question: str) -> AgentOutput:
- human_input = input(f'Human input required: {question}\n\n')
+ human_input = input(f'\nHi, your input is required: {question}\n\n')
logger.info('-' * 50)
self.messages.append(HumanMessage(content=human_input))