This function will get called at every step of the agent's 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)
| 6 | game_api_key="" |
| 7 | |
| 8 | def get_state_fn(function_result: FunctionResult, current_state: dict) -> dict: |
| 9 | """ |
| 10 | This function will get called at every step of the agent's execution to form the agent's state. |
| 11 | It will take as input the function result from the previous step. |
| 12 | """ |
| 13 | # dict containing info about the function result as implemented in the exectuable |
| 14 | info = function_result.info |
| 15 | |
| 16 | # example of fixed state (function result info is not used to change state) - the first state placed here is the initial state |
| 17 | init_state = { |
| 18 | "objects": [ |
| 19 | {"name": "apple", "description": "A red apple", "type": ["item", "food"]}, |
| 20 | {"name": "banana", "description": "A yellow banana", "type": ["item", "food"]}, |
| 21 | {"name": "orange", "description": "A juicy orange", "type": ["item", "food"]}, |
| 22 | {"name": "chair", "description": "A chair", "type": ["sittable"]}, |
| 23 | {"name": "table", "description": "A table", "type": ["sittable"]}, |
| 24 | ] |
| 25 | } |
| 26 | |
| 27 | if current_state is None: |
| 28 | # at the first step, initialise the state with just the init state |
| 29 | new_state = init_state |
| 30 | else: |
| 31 | # do something wiht the current state input and the function result info |
| 32 | new_state = init_state # this is just an example where the state is static |
| 33 | |
| 34 | return new_state |
| 35 | |
| 36 | def take_object(object: str, **kwargs) -> Tuple[FunctionResultStatus, str, dict]: |
| 37 | """ |