Overview

You can customize the system prompt by extending the SystemPrompt class. Internally, this adds extra instructions to the default system prompt.

Custom system prompts allow you to modify the agent’s behavior at a fundamental level. Use this feature carefully as it can significantly impact the agent’s performance and reliability.

Basic Customization

Create a custom system prompt by inheriting from the base class.

from browser_use import SystemPrompt
from langchain_core.messages import SystemMessage
from overrides import overrides
class MySystemPrompt(SystemPrompt):
    @overrides
    def get_system_message(self) -> SystemMessage:
        
        # Get existing rules from parent class
        existing_prompt = self.prompt_template.format(max_actions=self.max_actions_per_step)

        # Add your custom rules
        new_prompt = """
            10. MOST IMPORTANT RULE:
            - You must response, think, reason Only Korean
            - You must find "ReactModal__Overlay" attribute when you search sections
            - You must search another apporach, another section, another actions even you faced retry the situations over twice times
        """

        # Make sure to use this pattern otherwise the exiting rules will be lost
        return SystemMessage(content=f'{existing_prompt}\n{new_prompt}')

Using Custom System Prompt

Apply your custom system prompt when creating an agent:

from langchain_openai import ChatOpenAI

# Initialize the model
model = ChatOpenAI(model='gpt-4o')

# Create agent with custom system prompt
agent = Agent(
    task="Your task here",
    llm=model,
    system_prompt_class=MySystemPrompt
)