Skip to main content

What is Shared State?

DroidAgentState is a Pydantic model that serves as the central coordination mechanism for DroidRun’s multi-agent workflow. It’s a shared data structure that all agents (Manager, Executor, FastAgent, Scripter) 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

class DroidAgentState(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.

    # Script execution (Scripter)
    scripter_history: List[Dict] = []          # Scripter results
    last_scripter_success: bool = True         # Last execution status

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