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
add output format
magmuellerdea435029fd1
diff --git a/docs/customize/agent-settings.mdx b/docs/customize/agent-settings.mdxindex 94963a581..c2a1ef0ff 100644--- a/docs/customize/agent-settings.mdx+++ b/docs/customize/agent-settings.mdx@@ -131,7 +131,7 @@ The agent is executed using the async `run()` method:- `max_steps` (default: `100`)Maximum number of steps the agent can take during execution. This prevents infinite loops and helps control execution time.-### Agent History+## Agent HistoryThe method returns an `AgentHistoryList` object containing the complete execution history. This history is invaluable for debugging, analysis, and creating reproducible scripts.@@ -161,3 +161,8 @@ The `AgentHistoryList` provides many helper methods to analyze the execution:capabilities, refer to the [AgentHistoryList sourcecode](https://github.com/browser-use/browser-use/blob/main/browser_use/agent/views.py#L111).</Note>+++## Rerunning the Agent without LLM++## Initial Actions without LLMdiff --git a/docs/customize/custom-functions.mdx b/docs/customize/custom-functions.mdxindex 82ea12e95..119fb2a6c 100644--- a/docs/customize/custom-functions.mdx+++ b/docs/customize/custom-functions.mdx@@ -118,5 +118,12 @@ await agent2.run()+## Exclude functions+If you want less actions to be used by the agent, you can exclude them from the controller.+```python+controller = Controller(exclude_actions=['open_tab', 'google_search'])+```++For more examples like file upload or notifications, visit [examples/custom-functions](https://github.com/browser-use/browser-use/tree/main/examples/custom-functions).diff --git a/docs/customize/output-format.mdx b/docs/customize/output-format.mdxnew file mode 100644index 000000000..d893a7513--- /dev/null+++ b/docs/customize/output-format.mdx@@ -0,0 +1,50 @@+---+title: "Output Format"+description: "The default is text. But you can define a structured output format to make post-processing easier."+icon: "code"+---++## Custom output format+With [this example](https://github.com/browser-use/browser-use/blob/main/examples/features/custom_output.py) you can define what output format the agent should return to you.++```python+from pydantic import BaseModel+# Define the output format as a Pydantic model+class Post(BaseModel):+ post_title: str+ post_url: str+ num_comments: int+ hours_since_post: int+++class Posts(BaseModel):+ posts: List[Post]+++controller = Controller(output_model=Posts)+++async def main():+ task = 'Go to hackernews show hn and give me the first 5 posts'+ model = ChatOpenAI(model='gpt-4o')+ agent = Agent(task=task, llm=model, controller=controller)++ history = await agent.run()++ result = history.final_result()+ if result:+ parsed: Posts = Posts.model_validate_json(result)++ for post in parsed.posts:+ print('\n--------------------------------')+ print(f'Title: {post.post_title}')+ print(f'URL: {post.post_url}')+ print(f'Comments: {post.num_comments}')+ print(f'Hours since post: {post.hours_since_post}')+ else:+ print('No result')+++if __name__ == '__main__':+ asyncio.run(main())+```\ No newline at end of filediff --git a/docs/mint.json b/docs/mint.jsonindex cbaa403e1..e8015fd92 100644--- a/docs/mint.json+++ b/docs/mint.json@@ -49,6 +49,7 @@"customize/langchain-models","customize/agent-settings","customize/browser-settings",+ "customize/output-format","customize/system-prompt","customize/real-browser","customize/custom-functions"