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
Change default of include_tool_call_examples to False for reduced tokens
Cursor Agent31718e982c1f
diff --git a/IMPLEMENTATION_SUMMARY.md b/IMPLEMENTATION_SUMMARY.mddeleted file mode 100644index 995ca6d69..000000000--- a/IMPLEMENTATION_SUMMARY.md+++ /dev/null@@ -1,76 +0,0 @@-# Implementation Summary: `include_tool_call_examples` Parameter--## ✅ Complete Implementation--This PR successfully adds the `include_tool_call_examples` parameter to the Agent class, allowing users to control whether tool call examples are included in the message history.--## 🔧 Files Modified--### 1. `browser_use/agent/service.py`-- ✅ Added `include_tool_call_examples: bool = True` parameter to `Agent.__init__()`-- ✅ Added parameter to `AgentSettings` initialization-- ✅ Passed parameter to `MessageManager` constructor--### 2. `browser_use/agent/views.py`-- ✅ Added `include_tool_call_examples: bool = True` field to `AgentSettings` model--### 3. `browser_use/agent/message_manager/service.py`-- ✅ Added `include_tool_call_examples: bool = True` parameter to `MessageManager.__init__()`-- ✅ Stored parameter as instance variable `self.include_tool_call_examples`-- ✅ Modified `_init_messages()` to conditionally include the 3 example messages--## 📋 Parameter Details--**Parameter**: `include_tool_call_examples`-**Type**: `bool`-**Default**: `True`-**Location**: Agent initialization--## 🎯 Behavior--### When `include_tool_call_examples=True` (default)-- System prompt + 3 example messages are added-- **Total messages**: 4 (1 system + 3 examples)-- **Backward compatible**: Existing behavior is preserved--### When `include_tool_call_examples=False`-- Only system prompt is added-- **Total messages**: 1 (system only)-- **Cleaner history**: No example clutter--## 🔍 The 3 Example Messages--1. **UserMessage**: `"<example_1>\nHere is an example output..."`-2. **AssistantMessage**: JSON example with thinking and actions-3. **UserMessage**: `"Data written to todo.md.\nData written to github.md..."`--## 📖 Usage Examples--```python-# Default behavior (with examples)-agent = Agent(- task="Your task",- llm=your_llm_model-)--# Without examples-agent = Agent(- task="Your task",- llm=your_llm_model,- include_tool_call_examples=False-)-```--## ✅ Validation--- [x] All modified files pass syntax validation-- [x] Parameter properly flows through: Agent → AgentSettings → MessageManager-- [x] Backward compatibility maintained (default=True)-- [x] Clean implementation with conditional logic in `_init_messages()`--## 🎉 Ready for Review--The implementation is complete and ready for PR submission. The feature allows users to:-- Reduce token usage by skipping examples-- Have cleaner message histories-- Maintain full backward compatibility\ No newline at end of filediff --git a/PR_CHANGES.md b/PR_CHANGES.mddeleted file mode 100644index ae28bf14d..000000000--- a/PR_CHANGES.md+++ /dev/null@@ -1,63 +0,0 @@-# PR: Add `include_tool_call_examples` Parameter to Agent--## Summary-Added a new optional parameter `include_tool_call_examples` to the Agent class initialization that controls whether the tool call examples (3 messages after the system prompt) are included in the message history.--## Changes Made--### 1. Added parameter to Agent class (`browser_use/agent/service.py`)-- Added `include_tool_call_examples: bool = True` parameter to the `Agent.__init__()` method-- Parameter defaults to `True` to maintain backward compatibility--### 2. Updated AgentSettings class (`browser_use/agent/views.py`)-- Added `include_tool_call_examples: bool = True` field to the `AgentSettings` model--### 3. Updated MessageManager class (`browser_use/agent/message_manager/service.py`)-- Added `include_tool_call_examples: bool = True` parameter to the `MessageManager.__init__()` method-- Stored the parameter as an instance variable `self.include_tool_call_examples`-- Modified `_init_messages()` method to conditionally include the 3 example messages based on this parameter--### 4. Updated Agent-MessageManager integration (`browser_use/agent/service.py`)-- Passed `include_tool_call_examples=self.settings.include_tool_call_examples` to the MessageManager constructor--## Usage--### Default behavior (backward compatible)-```python-# Tool call examples are included by default-agent = Agent(- task="Your task",- llm=your_llm_model-)-```--### Disable tool call examples-```python-# Tool call examples are excluded-agent = Agent(- task="Your task",- llm=your_llm_model,- include_tool_call_examples=False-)-```--## Technical Details--The tool call examples consist of 3 messages that are normally added after the system prompt:--1. **UserMessage**: Example introduction message-2. **AssistantMessage**: Example response with thinking and actions-3. **UserMessage**: Example result message--When `include_tool_call_examples=False`, these messages are skipped, resulting in:-- **With examples**: 4 messages (1 system + 3 example messages)-- **Without examples**: 1 message (system only)--This allows for:-- Cleaner message history for users who don't need examples-- Reduced token usage when examples are not needed-- More flexibility in prompt engineering--## Backward Compatibility-- Default value is `True`, so existing code continues to work unchanged-- No breaking changes to existing functionality\ No newline at end of filediff --git a/browser_use/agent/message_manager/service.py b/browser_use/agent/message_manager/service.pyindex ee92d1d2b..131a1390d 100644--- a/browser_use/agent/message_manager/service.py+++ b/browser_use/agent/message_manager/service.py@@ -103,7 +103,7 @@ class MessageManager:available_file_paths: list[str] | None = None,state: MessageManagerState = MessageManagerState(),use_thinking: bool = True,- include_tool_call_examples: bool = True,+ include_tool_call_examples: bool = False,include_attributes: list[str] | None = None,message_context: str | None = None,sensitive_data: dict[str, str | dict[str, str]] | None = None,diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex fe1d5f852..94800ce8f 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -171,7 +171,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):cloud_sync: CloudSync | None = None,calculate_cost: bool = False,display_files_in_done_text: bool = True,- include_tool_call_examples: bool = True,+ include_tool_call_examples: bool = False,**kwargs,):# Check for deprecated memory parametersdiff --git a/browser_use/agent/views.py b/browser_use/agent/views.pyindex c54a05c9c..379dc7486 100644--- a/browser_use/agent/views.py+++ b/browser_use/agent/views.py@@ -63,7 +63,7 @@ class AgentSettings(BaseModel):is_planner_reasoning: bool = False # type: ignoreextend_planner_system_message: str | None = Nonecalculate_cost: bool = False- include_tool_call_examples: bool = True+ include_tool_call_examples: bool = Falseclass AgentState(BaseModel):