Skip to main content
The ActionResult class represents the result of executing an action (tool). It provides structured output, error handling, and metadata for agent communication.

Constructor

from browser_use import ActionResult

result = ActionResult(
    extracted_content="Found 10 products",
    long_term_memory="Searched for laptops on Amazon",
)

Parameters

extracted_content
str | None
Main content to show to the agent. This is the primary output of the action.
long_term_memory
str | None
Compact memory for long-term context. Used to summarize the action for future reference.
error
str | None
Error message if something went wrong. When set, this indicates the action failed.
is_done
bool
default:"False"
Whether the task is complete. Only used for the done action.
success
bool | None
Whether the task completed successfully. Can only be set when is_done=True.
attachments
list[str] | None
List of file paths to display in the completion message.
images
list[dict[str, Any]] | None
List of images (base64 encoded). Format: [{"name": "file.jpg", "data": "base64_string"}]
metadata
dict | None
Additional metadata for observability (e.g., click coordinates, duration, API calls).
judgement
JudgementResult | None
Judge evaluation result (populated by judge system).
include_extracted_content_only_once
bool
default:"False"
If True, extracted content is only added to context once (for next step) and not stored in long-term memory.
include_in_memory
bool
default:"False"
Deprecated: Whether to include extracted content in long-term memory.

Return Formats

Tools can return ActionResult or simple strings:
@tools.action('Extract product info')
async def extract_product() -> ActionResult:
    return ActionResult(
        extracted_content="Product: Laptop, Price: $999",
        long_term_memory="Found laptop pricing",
        metadata={"product_id": "123"},
    )

Simple String Return

@tools.action('Simple action')
async def simple_action() -> str:
    return "Task completed"

Usage Examples

Success Result

result = ActionResult(
    extracted_content="Successfully uploaded 5 files",
    long_term_memory="Uploaded reports to server",
    attachments=[
        "/path/to/report1.pdf",
        "/path/to/report2.pdf",
    ],
)

Error Result

result = ActionResult(
    error="Failed to connect to API: Connection timeout",
)

Task Completion (Done)

result = ActionResult(
    is_done=True,
    success=True,
    extracted_content="Task completed: Found 25 articles and saved to research.txt",
    attachments=["research.txt"],
)

With Images

import base64

with open("screenshot.png", "rb") as f:
    image_data = base64.b64encode(f.read()).decode()

result = ActionResult(
    extracted_content="Screenshot captured",
    images=[
        {"name": "screenshot.png", "data": image_data}
    ],
)

With Metadata

result = ActionResult(
    extracted_content="Clicked button at (100, 200)",
    metadata={
        "click_x": 100,
        "click_y": 200,
        "element_type": "button",
        "duration_ms": 45,
    },
)

Extraction with Read-Once Content

# Large extracted content that should only be in context once
result = ActionResult(
    extracted_content=long_json_data,  # Sent to agent once
    long_term_memory="Extracted product catalog (500 items)",  # Compact memory
    include_extracted_content_only_once=True,  # Don't store full content
)

Best Practices

1. Always Provide Extracted Content

# ✅ Good
ActionResult(
    extracted_content="Found 5 results",
)

# ❌ Bad
ActionResult()  # No information for the agent

2. Use Long-Term Memory for Summaries

# ✅ Good - Compact memory
ActionResult(
    extracted_content="<100 lines of detailed data>",
    long_term_memory="Extracted customer data",
)

# ❌ Bad - Full data in memory
ActionResult(
    extracted_content="<100 lines of detailed data>",
    # No long_term_memory - full content stored
)

3. Clear Error Messages

# ✅ Good - Actionable error
ActionResult(
    error="File not found: /path/to/data.csv. Available files: [list.txt, report.pdf]",
)

# ❌ Bad - Generic error
ActionResult(
    error="Error occurred",
)

4. Success Flag Only With is_done

# ✅ Good
ActionResult(
    is_done=True,
    success=True,
    extracted_content="Task completed",
)

# ❌ Bad - Raises ValidationError
try:
    ActionResult(
        success=True,  # is_done not set
        extracted_content="Step completed",
    )
except ValueError as e:
    print(e)  # success=True requires is_done=True

5. Include Attachments for Files

# ✅ Good - Files visible to user
ActionResult(
    extracted_content="Report generated",
    attachments=["/path/to/report.pdf"],
)

# ❌ Bad - User doesn't know where file is
ActionResult(
    extracted_content="Report generated",
)

Properties

All ActionResult fields are accessible as properties:
result = ActionResult(
    extracted_content="Data found",
    long_term_memory="Searched database",
)

print(result.extracted_content)  # "Data found"
print(result.long_term_memory)   # "Searched database"
print(result.error)               # None
print(result.is_done)             # False

JudgementResult

Used for judge evaluation:
from browser_use.agent.views import JudgementResult

judgement = JudgementResult(
    reasoning="Task requirements met",
    verdict=True,
    failure_reason=None,
    impossible_task=False,
    reached_captcha=False,
)

result = ActionResult(
    is_done=True,
    success=True,
    extracted_content="Task completed",
    judgement=judgement,
)

See Also