Fetch and format recent interaction history for each environment instance. Args: history_length (int): Maximum number of past steps to retrieve per environment. obs_key (str, default="text_obs"): The key name used to access the
(
self,
history_length: int,
obs_key: str = "text_obs",
action_key: str = "action",
)
| 41 | self._data[env_idx].append({k: record[k][env_idx] for k in self.keys}) |
| 42 | |
| 43 | def fetch( |
| 44 | self, |
| 45 | history_length: int, |
| 46 | obs_key: str = "text_obs", |
| 47 | action_key: str = "action", |
| 48 | ) -> Tuple[List[str], List[int]]: |
| 49 | """ |
| 50 | Fetch and format recent interaction history for each environment instance. |
| 51 | Args: |
| 52 | history_length (int): |
| 53 | Maximum number of past steps to retrieve per environment. |
| 54 | obs_key (str, default="text_obs"): |
| 55 | The key name used to access the observation in stored records. |
| 56 | For example: "text_obs" or "Observation", depending on the environment. |
| 57 | action_key (str, default="action"): |
| 58 | The key name used to access the action in stored records. |
| 59 | For example: "action" or "Action". |
| 60 | Returns: |
| 61 | memory_contexts : List[str] |
| 62 | A list of formatted action history strings for each environment. |
| 63 | valid_lengths : List[int] |
| 64 | A list of the actual number of valid history steps per environment. |
| 65 | """ |
| 66 | memory_contexts, valid_lengths = [], [] |
| 67 | |
| 68 | for env_idx in range(self.batch_size): |
| 69 | recent = self._data[env_idx][-history_length:] |
| 70 | valid_len = len(recent) |
| 71 | start_idx = len(self._data[env_idx]) - valid_len |
| 72 | |
| 73 | lines = [] |
| 74 | for j, rec in enumerate(recent): |
| 75 | step_num = start_idx + j + 1 |
| 76 | act = rec[action_key] |
| 77 | obs = rec[obs_key] |
| 78 | lines.append( |
| 79 | f"[Observation {step_num}: '{obs}', Action {step_num}: '{act}']" |
| 80 | ) |
| 81 | |
| 82 | memory_contexts.append("\n".join(lines)) |
| 83 | valid_lengths.append(valid_len) |
| 84 | |
| 85 | return memory_contexts, valid_lengths |
nothing calls this directly
no outgoing calls
no test coverage detected