MCPcopy Create free account
hub / github.com/Action-State-Labs/android-action-kernel / run_agent

Function run_agent

kernel.py:41–81  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

39
40
41def 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
84def main():

Callers 1

mainFunction · 0.85

Calls 5

get_llm_providerFunction · 0.90
execute_actionFunction · 0.90
get_screen_stateFunction · 0.85
get_modelMethod · 0.80
get_decisionMethod · 0.45

Tested by

no test coverage detected