get_planner_state
Retrieve browser state and planning context to analyze previous actions, track memory, and determine next goals. Required before executing actions in MCP Browser Agent.
Instructions
Get the current browser state and planning context. This tool must be executed before execute_actions tool.
Must return a JSON string in the format:
{
"current_state": {
"evaluation_previous_goal": "Success|Failed|Unknown - Analysis of previous actions",
"memory": "Description of what has been done and what to remember",
"next_goal": "What needs to be done with the next immediate action"
},
"action": [
{"action_name": {"param1": "value1", ...}},
...
]
}
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- browser-use.py:143-208 (handler)The main handler function for the 'get_planner_state' tool, decorated with @mcp.tool() for registration. It retrieves the browser context state, available actions, and formats a JSON response with current state and browser information.@mcp.tool() async def get_planner_state(ctx: Context) -> str: """Get the current browser state and planning context. This tool must be executed before execute_actions tool. Must return a JSON string in the format: { "current_state": { "evaluation_previous_goal": "Success|Failed|Unknown - Analysis of previous actions", "memory": "Description of what has been done and what to remember", "next_goal": "What needs to be done with the next immediate action" }, "action": [ {"action_name": {"param1": "value1", ...}}, ... ] } """ try: browser_context = await browser_initialized_check() controller = ctx.request_context.lifespan_context.get("controller") if controller is None: controller = Controller() ctx.request_context.lifespan_context["controller"] = controller state = await browser_context.get_state() elements_text = state.element_tree.clickable_elements_to_string() # dom to html step -- basically gets elements on the page and returns for text representation input to llm # Get available actions from the controller's registry available_actions = controller.registry.get_prompt_description() # gets the action descriptions from the controller # Format the response according to system prompt response = { "current_state": { "evaluation_previous_goal": "Unknown - No previous actions to evaluate", "memory": "Starting new browser session", "next_goal": "Ready to execute browser actions" }, "action": [] # Empty action list - actions will be specified by the caller } # Add browser state information state_info = f""" Current URL: {state.url} Title: {state.title} Available tabs: {[tab.model_dump() for tab in state.tabs]} Interactive elements: {elements_text} Available Actions: {available_actions} Note: Actions should be executed using the execute_actions tool with the following format: {{ "name": "action_name", "params": {{ "param1": "value1", ... }} }} """ return json.dumps(response, indent=2) + "\n\nBrowser State:\n" + state_info except Exception as e: logger.error(f"Error getting planner state: {str(e)}") return f"Error getting planner state: {str(e)}"