MCPcopy Create free account
hub / github.com/Virtual-Protocol/virtuals-python / _get_action

Method _get_action

src/virtuals_sdk/game/worker.py:85–121  ·  view source on GitHub ↗

Gets the agent action from the GAME API

(
        self,
        # results of the previous action (if any)
        function_result: Optional[FunctionResult] = None
    )

Source from the content-addressed store, hash-verified

83 return self._submission_id
84
85 def _get_action(
86 self,
87 # results of the previous action (if any)
88 function_result: Optional[FunctionResult] = None
89 ) -> ActionResponse:
90 """
91 Gets the agent action from the GAME API
92 """
93 # dummy function result if None is provided - for get_state_fn to take the same input all the time
94 if function_result is None:
95 function_result = FunctionResult(
96 action_id="",
97 action_status=FunctionResultStatus.DONE,
98 feedback_message="",
99 info={},
100 )
101 # set up data payload
102 data = {
103 "environment": self.state, # state (updated state)
104 "functions": [
105 f.get_function_def() for f in self.action_space.values() # functions available
106 ],
107 "action_result": (
108 function_result.model_dump(
109 exclude={'info'}) if function_result else None
110 ),
111 }
112
113 # make API call
114 response = post(
115 base_url=self._base_url,
116 api_key=self._api_key,
117 endpoint=f"/v2/agents/{self._agent_id}/tasks/{self._submission_id}/next",
118 data=data,
119 )
120
121 return ActionResponse.model_validate(response)
122
123 def step(self):
124 """

Callers 1

stepMethod · 0.95

Calls 3

FunctionResultClass · 0.90
postFunction · 0.90
get_function_defMethod · 0.80

Tested by

no test coverage detected