> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mobilerun.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Shared State

> MobileAgentState - the coordination mechanism for multi-agent workflow communication.

## What is Shared State?

**MobileAgentState** is a Pydantic model that serves as the **central coordination mechanism** for Mobilerun's multi-agent workflow. It's a shared data structure that all agents (Manager, Executor, FastAgent) can read from and write to.

Shared state enables:

* **Cross-agent communication**: Agents share information about actions, results, and errors
* **Progress tracking**: Step counts, action history, visited apps/screens
* **Memory management**: Agent memory, custom variables, user session data
* **Error coordination**: Error flags, escalation thresholds, error descriptions

**Key insight**: Shared state replaces complex message passing. Instead of sending data back and forth, agents update a single shared object.

## Core State Fields

```python theme={null}
class MobileAgentState(BaseModel):
    # Task context
    instruction: str = ""           # Original task
    step_number: int = 0            # Current step

    # Device state
    formatted_device_state: str = ""           # Human-readable state
    current_package_name: str = ""             # Current app
    current_activity_name: str = ""            # Current screen

    # Action tracking
    action_history: List[Dict] = []            # All actions taken
    action_outcomes: List[bool] = []           # Success/failure
    summary_history: List[str] = []            # Action summaries

    # Memory
    manager_memory: str = ""                   # Manager's planning notes (append-only)
    fast_memory: List[str] = []                # FastAgent remember() items (max 10)

    # Planning (Manager)
    plan: str = ""                             # Current plan
    current_subgoal: str = ""                  # Current subgoal
    answer: str = ""                           # Final answer (manager completion or complete() tool)

    # Completion (set by complete() tool)
    finished: bool = False                     # Whether task is done
    success: Optional[bool] = None             # Whether task succeeded

    # Error handling
    error_flag_plan: bool = False              # Signal error to Manager
    error_descriptions: List[str] = []         # Error messages
    err_to_manager_thresh: int = 2             # Consecutive errors before escalation

    # Message history (for stateful agents)
    message_history: List[ChatMessage] = []    # Preserves ThinkingBlock, ImageBlock, etc.

    # External user messages (mid-run injection queue)
    pending_user_messages: List[QueuedUserMessage] = []  # Queued external messages
    workflow_completed: bool = False                      # Set True at finalization

    # Custom variables
    custom_variables: Dict = {}                # User-defined data
```
