Clean docs

This commit is contained in:
kalil0321
2025-11-01 23:42:45 +01:00
parent 5a8e78334c
commit 6f9ec79dcc

View File

@@ -98,96 +98,6 @@ errors = [cell.error for cell in session.cells if cell.error]
successful_cells = [cell for cell in session.cells if cell.status == 'success']
```
## History Property
For compatibility with evaluation systems, CodeAgent also provides a `history` property that mimics the Agent's history format:
```python
# Access history property (returns mock AgentHistoryList)
history = agent.history
# Access the history list
history.history # List of CodeAgentHistory objects (converted to dict-like objects)
history.usage # UsageSummary with token usage information
# Access individual history items
for step in history.history:
# Model output (code generated by LLM)
if step.model_output:
code = step.model_output.model_output
full_response = step.model_output.full_response
# Execution results
for result in step.result:
output = result.extracted_content
error = result.error
is_done = result.is_done
success = result.success
# Browser state
url = step.state.url
title = step.state.title
screenshot_path = step.state.screenshot_path
screenshot = step.state.get_screenshot() # Returns base64 string
# Metadata (timing and tokens)
if step.metadata:
duration = step.metadata.duration_seconds
input_tokens = step.metadata.input_tokens
output_tokens = step.metadata.output_tokens
```
## Screenshots
Access screenshot paths using the agent's `screenshot_paths()` method:
```python
# Get all screenshot paths
paths = agent.screenshot_paths()
# Get last N screenshots
last_3 = agent.screenshot_paths(n_last=3)
```
## Complete Example
```python
import asyncio
from browser_use import CodeAgent
async def main():
agent = CodeAgent(task="Extract products from example.com")
session = await agent.run()
# Check completion
if session.namespace.get('_task_done'):
print("✅ Task completed!")
print(f"Result: {session.namespace.get('_task_result')}")
else:
print("⚠️ Task incomplete")
# Review all code execution
print(f"\nExecuted {len(session.cells)} cells:")
for i, cell in enumerate(session.cells, 1):
print(f"\nCell {i}:")
print(f" Status: {cell.status}")
if cell.error:
print(f" ❌ Error: {cell.error}")
elif cell.output:
print(f" ✓ Output: {cell.output[:100]}...")
# Access extracted data
if 'products' in session.namespace:
products = session.namespace['products']
print(f"\n📦 Extracted {len(products)} products")
# Get screenshots
screenshots = agent.screenshot_paths()
print(f"\n📸 Captured {len([p for p in screenshots if p])} screenshots")
asyncio.run(main())
```
## Data Models
See the complete data model definitions in the [CodeAgent views source code](https://github.com/browser-use/browser-use/blob/main/browser_use/code_use/views.py).