MCPcopy Create free account
hub / github.com/zai-org/Open-AutoGLM / execute

Method execute

phone_agent/actions/handler_ios.py:53–96  ·  view source on GitHub ↗

Execute an action from the AI model. Args: action: The action dictionary from the model. screen_width: Current screen width in pixels. screen_height: Current screen height in pixels. Returns: ActionResult indicating success a

(
        self, action: dict[str, Any], screen_width: int, screen_height: int
    )

Source from the content-addressed store, hash-verified

51 self.takeover_callback = takeover_callback or self._default_takeover
52
53 def execute(
54 self, action: dict[str, Any], screen_width: int, screen_height: int
55 ) -> ActionResult:
56 """
57 Execute an action from the AI model.
58
59 Args:
60 action: The action dictionary from the model.
61 screen_width: Current screen width in pixels.
62 screen_height: Current screen height in pixels.
63
64 Returns:
65 ActionResult indicating success and whether to finish.
66 """
67 action_type = action.get("_metadata")
68
69 if action_type == "finish":
70 return ActionResult(
71 success=True, should_finish=True, message=action.get("message")
72 )
73
74 if action_type != "do":
75 return ActionResult(
76 success=False,
77 should_finish=True,
78 message=f"Unknown action type: {action_type}",
79 )
80
81 action_name = action.get("action")
82 handler_method = self._get_handler(action_name)
83
84 if handler_method is None:
85 return ActionResult(
86 success=False,
87 should_finish=False,
88 message=f"Unknown action: {action_name}",
89 )
90
91 try:
92 return handler_method(action, screen_width, screen_height)
93 except Exception as e:
94 return ActionResult(
95 success=False, should_finish=False, message=f"Action failed: {e}"
96 )
97
98 def _get_handler(self, action_name: str) -> Callable | None:
99 """Get the handler method for an action."""

Callers

nothing calls this directly

Calls 2

_get_handlerMethod · 0.95
ActionResultClass · 0.70

Tested by

no test coverage detected