Skip to content

Commit d4075b6

Browse files
authored
fix: Fix compaction run item typing and lifecycle handling (#2287)
1 parent 4095250 commit d4075b6

2 files changed

Lines changed: 3 additions & 9 deletions

File tree

src/agents/_run_impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ def process_model_response(
542542
shell_calls.append(ToolRunShellCall(tool_call=output, shell_tool=shell_tool))
543543
continue
544544
if output_type == "compaction":
545-
items.append(CompactionItem(raw_item=cast(dict[str, Any], output), agent=agent))
545+
items.append(CompactionItem(raw_item=cast(TResponseInputItem, output), agent=agent))
546546
continue
547547
if output_type == "apply_patch_call":
548548
items.append(ToolCallItem(raw_item=cast(Any, output), agent=agent))

src/agents/items.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,20 +328,14 @@ class MCPApprovalResponseItem(RunItemBase[McpApprovalResponse]):
328328

329329

330330
@dataclass
331-
class CompactionItem:
331+
class CompactionItem(RunItemBase[TResponseInputItem]):
332332
"""Represents a compaction item from responses.compact."""
333333

334-
agent: Agent[Any]
335-
"""The agent whose run caused this item to be generated."""
336-
337-
raw_item: dict[str, Any]
338-
"""The raw compaction item containing encrypted_content."""
339-
340334
type: Literal["compaction_item"] = "compaction_item"
341335

342336
def to_input_item(self) -> TResponseInputItem:
343337
"""Converts this item into an input item suitable for passing to the model."""
344-
return cast(TResponseInputItem, self.raw_item)
338+
return self.raw_item
345339

346340

347341
RunItem: TypeAlias = Union[

0 commit comments

Comments
 (0)