Files
liqiang b119135836
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
2026-08-20 13:12:50 +00:00

44 lines
1.0 KiB
Python

"""
Simple example of using Browser-Use cloud browser service.
Prerequisites:
1. Set BROWSER_USE_API_KEY environment variable
2. Active subscription at https://cloud.browser-use.com
"""
import asyncio
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
from browser_use import Agent, Browser, ChatOpenAI
async def main():
"""Basic cloud browser example."""
print('🌤️ Using Browser-Use Cloud Browser')
# Create agent with cloud browser enabled
agent = Agent(
task='Go to https://github.com/browser-use/browser-use and find the number of stars',
llm=ChatOpenAI(model='gpt-4.1-mini'),
browser=Browser(use_cloud=True), # Enable cloud browser
)
try:
result = await agent.run()
print(f'✅ Result: {result}')
except Exception as e:
print(f'❌ Error: {e}')
if 'Authentication' in str(e):
print(
'💡 Set BROWSER_USE_API_KEY environment variable. You can also create an API key at https://cloud.browser-use.com'
)
if __name__ == '__main__':
asyncio.run(main())