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

Method execute

phone_agent/actions/handler.py:45–88  ·  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

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

Callers 2

_execute_stepMethod · 0.45
_execute_stepMethod · 0.45

Calls 2

_get_handlerMethod · 0.95
ActionResultClass · 0.70

Tested by

no test coverage detected