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

Function get_worker_state_fn

examples/game/test_agent.py:12–38  ·  view source on GitHub ↗

This function will get called at every step of the workers execution to form the agent's state. It will take as input the function result from the previous step.

(function_result: FunctionResult, current_state: dict)

Source from the content-addressed store, hash-verified

10# or they can share the same get_worker_state_fn and maintain the same state
11
12def get_worker_state_fn(function_result: FunctionResult, current_state: dict) -> dict:
13 """
14 This function will get called at every step of the workers execution to form the agent's state.
15 It will take as input the function result from the previous step.
16 """
17 # dict containing info about the function result as implemented in the exectuable
18 info = function_result.info
19
20 # example of fixed state (function result info is not used to change state) - the first state placed here is the initial state
21 init_state = {
22 "objects": [
23 {"name": "apple", "description": "A red apple", "type": ["item", "food"]},
24 {"name": "banana", "description": "A yellow banana", "type": ["item", "food"]},
25 {"name": "orange", "description": "A juicy orange", "type": ["item", "food"]},
26 {"name": "chair", "description": "A chair", "type": ["sittable"]},
27 {"name": "table", "description": "A table", "type": ["sittable"]},
28 ]
29 }
30
31 if current_state is None:
32 # at the first step, initialise the state with just the init state
33 new_state = init_state
34 else:
35 # do something wiht the current state input and the function result info
36 new_state = init_state # this is just an example where the state is static
37
38 return new_state
39
40def get_agent_state_fn(function_result: FunctionResult, current_state: dict) -> dict:
41 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected