Items
Item utilities for the run pipeline. Hosts input normalization helpers and lightweight builders for synthetic run items or IDs used during tool execution. Internal use only.
NestedHistoryOwnedItem
dataclass
A run item and the exact nested-input occurrence that represents it.
ソースコード位置: src/agents/run_internal/items.py
NestedHistoryOwnedItemRef
dataclass
Durable coordinates plus the live object for one owned session occurrence.
ソースコード位置: src/agents/run_internal/items.py
order_current_turn_tool_outputs
order_current_turn_tool_outputs(
items: Sequence[RunItem],
*,
start: int | None,
call_positions: dict[str, int],
published_items: Sequence[RunItem] = (),
) -> list[RunItem]
Order pending local outputs without moving the response or published history.
ソースコード位置: src/agents/run_internal/items.py
nested_history_run_item_occurrence_key
nested_history_run_item_occurrence_key(
run_item: RunItem | None,
) -> str | None
Return the private copy-lineage key for a run item, when one exists.
ソースコード位置: src/agents/run_internal/items.py
ensure_nested_history_run_item_occurrence_key
ensure_nested_history_run_item_occurrence_key(
run_item: RunItem,
) -> str
Bind an ephemeral key that survives object copies but never enters model payloads.
ソースコード位置: src/agents/run_internal/items.py
copy_input_items
copy_input_items(
value: str | list[TResponseInputItem],
) -> str | list[TResponseInputItem]
Return a shallow copy of input items so mutations do not leak between turns.
run_item_to_input_item
run_item_to_input_item(
run_item: RunItem,
reasoning_item_id_policy: ReasoningItemIdPolicy
| None = None,
) -> TResponseInputItem | None
Convert a run item to model input, optionally stripping reasoning IDs.
ソースコード位置: src/agents/run_internal/items.py
run_items_to_input_items
run_items_to_input_items(
run_items: Sequence[RunItem],
reasoning_item_id_policy: ReasoningItemIdPolicy
| None = None,
) -> list[TResponseInputItem]
Convert run items to model input items while skipping approvals.
ソースコード位置: src/agents/run_internal/items.py
drop_orphan_function_calls
drop_orphan_function_calls(
items: list[TResponseInputItem],
*,
pruning_indexes: set[int] | None = None,
output_pruning_indexes: set[int] | None = None,
) -> list[TResponseInputItem]
Remove tool and program call items that do not have corresponding outputs so resumptions or
retries do not replay stale calls. When output_pruning_indexes identifies unambiguous
stored history, also remove tool outputs whose corresponding calls are no longer present after
history pruning. Program-owned items are removed with an orphan program, while programs with
retained hosted calls or tool outputs remain available for continuation. Reasoning items that
immediately precede a call dropped by this pass are also removed, since the Responses API
rejects reasoning items that are not followed by their associated model-emitted item (Item
'rs_...' of type 'reasoning' was provided without its required following item).
ソースコード位置: src/agents/run_internal/items.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
ensure_input_item_format
ensure_input_item_format(
item: TResponseInputItem,
) -> TResponseInputItem
Ensure a single item is normalized for model input.
ソースコード位置: src/agents/run_internal/items.py
normalize_input_items_for_api
normalize_input_items_for_api(
items: list[TResponseInputItem],
) -> list[TResponseInputItem]
Normalize input items for API submission.
ソースコード位置: src/agents/run_internal/items.py
prepare_model_input_items
prepare_model_input_items(
caller_items: Sequence[TResponseInputItem],
generated_items: Sequence[TResponseInputItem] = (),
) -> list[TResponseInputItem]
Normalize model input while pruning orphans only from runner-generated history.
ソースコード位置: src/agents/run_internal/items.py
normalize_resumed_input
normalize_resumed_input(
raw_input: str | list[TResponseInputItem],
) -> str | list[TResponseInputItem]
Normalize resumed list inputs and drop orphan tool calls.
ソースコード位置: src/agents/run_internal/items.py
fingerprint_input_item
Hashable fingerprint used to dedupe or rewind input items across resumes.
ソースコード位置: src/agents/run_internal/items.py
digest_input_item
Return a fixed-size digest of an input item for durable occurrence tracking.
ソースコード位置: src/agents/run_internal/items.py
filter_nested_history_owned_item_refs_for_input
filter_nested_history_owned_item_refs_for_input(
input: str | Sequence[TResponseInputItem],
owned_item_refs: Sequence[NestedHistoryOwnedItemRef],
) -> list[NestedHistoryOwnedItemRef]
Keep ownership whose exact clean input occurrence is still present.
ソースコード位置: src/agents/run_internal/items.py
reconcile_nested_history_owned_input_after_rewrite
reconcile_nested_history_owned_input_after_rewrite(
previous_input: str | Sequence[TResponseInputItem],
rewritten_input: str | Sequence[TResponseInputItem],
owned_item_refs: Sequence[NestedHistoryOwnedItemRef],
) -> tuple[
str | list[TResponseInputItem],
list[NestedHistoryOwnedItemRef],
]
Rebind ownership after an unambiguous input rewrite.
ソースコード位置: src/agents/run_internal/items.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 | |
resolve_nested_history_owned_item_indexes
resolve_nested_history_owned_item_indexes(
run_items: Sequence[RunItem],
owned_item_refs: Sequence[NestedHistoryOwnedItemRef],
) -> set[int]
Resolve ownership references without dropping a different item after list mutation.
ソースコード位置: src/agents/run_internal/items.py
rebase_nested_history_owned_item_refs
rebase_nested_history_owned_item_refs(
input: str | Sequence[TResponseInputItem],
run_items: Sequence[RunItem],
owned_item_refs: Sequence[NestedHistoryOwnedItemRef],
) -> list[NestedHistoryOwnedItemRef]
Rebase surviving ownership onto exact live input and session occurrences.
ソースコード位置: src/agents/run_internal/items.py
strip_internal_input_item_metadata
strip_internal_input_item_metadata(
item: TResponseInputItem,
) -> TResponseInputItem
Remove session and output-only metadata before replaying items as input.
ソースコード位置: src/agents/run_internal/items.py
apply_reasoning_item_id_policy
apply_reasoning_item_id_policy(
items: list[TResponseInputItem],
reasoning_item_id_policy: ReasoningItemIdPolicy | None,
) -> list[TResponseInputItem]
Apply the reasoning item ID policy to already-converted input items.
ソースコード位置: src/agents/run_internal/items.py
deduplicate_input_items
deduplicate_input_items(
items: Sequence[TResponseInputItem],
) -> list[TResponseInputItem]
Remove duplicate items that share stable identifiers to avoid re-sending tool outputs.
ソースコード位置: src/agents/run_internal/items.py
deduplicate_input_items_preferring_latest
deduplicate_input_items_preferring_latest(
items: Sequence[TResponseInputItem],
) -> list[TResponseInputItem]
Deduplicate by stable identifiers while keeping the latest value.
Causal precursor items stay at their earliest position so they cannot move behind required followers. Other identified items stay at their latest position so replacing a stale value does not move the replacement earlier in the conversation.
ソースコード位置: src/agents/run_internal/items.py
function_tool_error_output
function_tool_error_output(
tool_call: Any,
output: Any,
*,
output_json_schema: dict[str, Any] | None,
) -> Any
Encode SDK-generated programmatic tool errors as provider-compatible JSON objects.
ソースコード位置: src/agents/run_internal/items.py
function_rejection_item
function_rejection_item(
agent: Any,
tool_call: Any,
*,
rejection_message: str = REJECTION_MESSAGE,
output_json_schema: dict[str, Any] | None = None,
scope_id: str | None = None,
tool_origin: Any = None,
) -> ToolCallOutputItem
Build a ToolCallOutputItem representing a rejected function tool call.
ソースコード位置: src/agents/run_internal/items.py
shell_rejection_item
shell_rejection_item(
agent: Any,
call_id: str,
*,
tool_call: Any | None = None,
rejection_message: str = REJECTION_MESSAGE,
) -> ToolCallOutputItem
Build a ToolCallOutputItem representing a rejected shell call.
ソースコード位置: src/agents/run_internal/items.py
apply_patch_rejection_item
apply_patch_rejection_item(
agent: Any,
call_id: str,
*,
tool_call: Any | None = None,
output_type: Literal[
"apply_patch_call_output", "custom_tool_call_output"
] = "apply_patch_call_output",
rejection_message: str = REJECTION_MESSAGE,
) -> ToolCallOutputItem
Build a ToolCallOutputItem representing a rejected apply_patch call.
ソースコード位置: src/agents/run_internal/items.py
extract_mcp_request_id
Pull the request id from hosted MCP approval payloads.
ソースコード位置: src/agents/run_internal/items.py
extract_mcp_request_id_from_run
Extract the hosted MCP request id from a streaming run item.