Main agent loop: Perceive -> Reason -> Act Args: goal: The task to accomplish max_steps: Maximum steps before stopping (default from config)
(goal: str, max_steps: int = None)
| 39 | |
| 40 | |
| 41 | def run_agent(goal: str, max_steps: int = None) -> None: |
| 42 | """ |
| 43 | Main agent loop: Perceive -> Reason -> Act |
| 44 | |
| 45 | Args: |
| 46 | goal: The task to accomplish |
| 47 | max_steps: Maximum steps before stopping (default from config) |
| 48 | """ |
| 49 | if max_steps is None: |
| 50 | max_steps = Config.MAX_STEPS |
| 51 | |
| 52 | print(f"🚀 Android Action Kernel Started") |
| 53 | print(f"📋 Goal: {goal}") |
| 54 | print(f"🤖 Provider: {Config.LLM_PROVIDER} ({Config.get_model()})") |
| 55 | |
| 56 | # Initialize LLM provider |
| 57 | llm = get_llm_provider() |
| 58 | action_history: List[Dict[str, Any]] = [] |
| 59 | |
| 60 | for step in range(max_steps): |
| 61 | print(f"\n--- Step {step + 1}/{max_steps} ---") |
| 62 | |
| 63 | # 1. Perception: Capture screen state |
| 64 | print("👀 Scanning Screen...") |
| 65 | screen_context = get_screen_state() |
| 66 | |
| 67 | # 2. Reasoning: Get LLM decision |
| 68 | print("🧠 Thinking...") |
| 69 | decision = llm.get_decision(goal, screen_context, action_history) |
| 70 | print(f"💡 Decision: {decision.get('reason', 'No reason provided')}") |
| 71 | |
| 72 | # 3. Action: Execute the decision |
| 73 | execute_action(decision) |
| 74 | |
| 75 | # Track action history for context |
| 76 | action_history.append(decision) |
| 77 | |
| 78 | # Wait for UI to update |
| 79 | time.sleep(Config.STEP_DELAY) |
| 80 | |
| 81 | print("\n⚠️ Max steps reached. Task may be incomplete.") |
| 82 | |
| 83 | |
| 84 | def main(): |
no test coverage detected