Return input items for the requested result view. ``preserve_all`` keeps the full converted history from ``new_items``. ``normalized`` returns the canonical continuation input when handoff filtering rewrote model history, otherwise it falls back to the same converted history.
(
result: RunResultBase,
*,
mode: ToInputListMode,
reasoning_item_id_policy: Literal["preserve", "omit"] | None,
)
| 128 | |
| 129 | |
| 130 | def _input_items_for_result( |
| 131 | result: RunResultBase, |
| 132 | *, |
| 133 | mode: ToInputListMode, |
| 134 | reasoning_item_id_policy: Literal["preserve", "omit"] | None, |
| 135 | ) -> list[TResponseInputItem]: |
| 136 | """Return input items for the requested result view. |
| 137 | |
| 138 | ``preserve_all`` keeps the full converted history from ``new_items``. ``normalized`` returns |
| 139 | the canonical continuation input when handoff filtering rewrote model history, otherwise it |
| 140 | falls back to the same converted history. |
| 141 | """ |
| 142 | session_items = run_items_to_input_items(result.new_items, reasoning_item_id_policy) |
| 143 | if mode == "preserve_all": |
| 144 | return session_items |
| 145 | if mode != "normalized": |
| 146 | raise ValueError(f"Unsupported to_input_list mode: {mode}") |
| 147 | if not getattr(result, "_replay_from_model_input_items", False): |
| 148 | # Most runs never rewrite continuation history, so normalized stays identical to the |
| 149 | # historical preserve-all view unless the runner explicitly marked a divergence. |
| 150 | return session_items |
| 151 | |
| 152 | model_input_items = getattr(result, "_model_input_items", None) |
| 153 | if not isinstance(model_input_items, list): |
| 154 | return session_items |
| 155 | |
| 156 | # When the runner marks a divergence, generated_items already reflect the continuation input |
| 157 | # chosen for the next local run after applying handoff/input filtering. |
| 158 | return run_items_to_input_items(model_input_items, reasoning_item_id_policy) |
| 159 | |
| 160 | |
| 161 | def _starting_agent_for_state(result: RunResultBase) -> Agent[Any]: |
no test coverage detected