Skip to main content

Overview

Mobilerun uses Jinja2 templates for agent prompts. You can customize agent behavior by passing custom template strings to MobileAgent:
Important: The prompts parameter accepts Jinja2 template strings, not file paths.

How It Works

  1. MobileAgent creates a PromptResolver with your custom prompts
  2. Each agent checks if you provided a custom template for its key (e.g., “manager_system”)
  3. If found: uses your custom template
  4. If not found: loads the default template from Mobilerun’s built-in files
  5. Templates are rendered with context variables specific to each agent

Available Prompt Keys

Context Variables

Each agent has access to different variables in its templates:

Manager

  • instruction - User’s goal
  • device_date - Current device date/time
  • app_card - App-specific guidance (empty if none available)
  • error_history - List of recent failed actions with details
  • custom_tools_descriptions - Custom tool documentation
  • available_secrets - Available credential IDs
  • variables - Custom variables passed to MobileAgent
  • output_schema - Pydantic model schema (if provided)

Executor

  • instruction - User’s goal
  • device_state - Current UI tree
  • plan - Current plan from Manager
  • subgoal - Current subgoal from Manager
  • progress_status - Cumulative progress summary
  • atomic_actions - Available actions (includes custom tools)
  • action_history - Recent actions with outcomes
  • available_secrets - Available credential IDs
  • variables - Custom variables passed to MobileAgent

FastAgent

System prompt:
  • tool_descriptions - Available tool signatures
  • available_secrets - Credential IDs
  • variables - Custom variables
  • output_schema - Output model schema (if provided)
User prompt:
  • goal - Task description
  • variables - Custom variables

Example: Custom Manager Prompt

Example: Using Custom Variables

Custom variables let you inject dynamic context into prompts:

Jinja2 Syntax Reference

Variables

Conditionals

Loops

Filters

Best Practices

1. Use Clear Structure

2. Handle Missing Data with Conditionals

3. Document Expected Variables

4. Use Variables for Dynamic Behavior

Complete Example

Key Points

  • Pass Jinja2 template strings (not file paths) to MobileAgent(prompts={...})
  • Each agent has different available variables in its template
  • Use variables parameter to inject custom context
  • Templates are rendered at runtime with current state
  • If no custom prompt provided, default templates are used
  • Supports full Jinja2 syntax (conditionals, loops, filters)