88
99from typing_extensions import TypeVar
1010
11+ from ._run_impl import NextStepInterruption
1112from .exceptions import UserError
13+ from .items import ToolApprovalItem
1214from .logger import logger
1315from .run_context import RunContextWrapper
1416from .usage import Usage
1517
1618if TYPE_CHECKING :
17- from ._run_impl import NextStepInterruption
1819 from .agent import Agent
1920 from .guardrail import InputGuardrailResult , OutputGuardrailResult
20- from .items import ModelResponse , RunItem , ToolApprovalItem
21+ from .items import ModelResponse , RunItem
2122
2223TContext = TypeVar ("TContext" , default = Any )
2324TAgent = TypeVar ("TAgent" , bound = "Agent[Any]" , default = "Agent[Any]" )
@@ -105,8 +106,6 @@ def get_interruptions(self) -> list[RunItem]:
105106 Returns:
106107 List of tool approval items awaiting approval, or empty list if no interruptions.
107108 """
108- from ._run_impl import NextStepInterruption
109-
110109 if self ._current_step is None or not isinstance (self ._current_step , NextStepInterruption ):
111110 return []
112111 return self ._current_step .interruptions
@@ -235,8 +234,6 @@ def to_json(self) -> dict[str, Any]:
235234
236235 def _serialize_current_step (self ) -> dict [str , Any ] | None :
237236 """Serialize the current step if it's an interruption."""
238- from ._run_impl import NextStepInterruption
239-
240237 if self ._current_step is None or not isinstance (self ._current_step , NextStepInterruption ):
241238 return None
242239
@@ -245,10 +242,15 @@ def _serialize_current_step(self) -> dict[str, Any] | None:
245242 "interruptions" : [
246243 {
247244 "type" : "tool_approval_item" ,
248- "rawItem" : item .raw_item .model_dump (exclude_unset = True ),
245+ "rawItem" : (
246+ item .raw_item .model_dump (exclude_unset = True )
247+ if hasattr (item .raw_item , "model_dump" )
248+ else item .raw_item
249+ ),
249250 "agent" : {"name" : item .agent .name },
250251 }
251252 for item in self ._current_step .interruptions
253+ if isinstance (item , ToolApprovalItem )
252254 ],
253255 }
254256
@@ -366,10 +368,7 @@ def from_string(initial_agent: Agent[Any], state_string: str) -> RunState[Any, A
366368 if current_step_data and current_step_data .get ("type" ) == "next_step_interruption" :
367369 from openai .types .responses import ResponseFunctionToolCall
368370
369- from ._run_impl import NextStepInterruption
370- from .items import ToolApprovalItem
371-
372- interruptions = []
371+ interruptions : list [RunItem ] = []
373372 for item_data in current_step_data .get ("interruptions" , []):
374373 agent_name = item_data ["agent" ]["name" ]
375374 agent = agent_map .get (agent_name )
@@ -458,10 +457,7 @@ def from_json(
458457 if current_step_data and current_step_data .get ("type" ) == "next_step_interruption" :
459458 from openai .types .responses import ResponseFunctionToolCall
460459
461- from ._run_impl import NextStepInterruption
462- from .items import ToolApprovalItem
463-
464- interruptions = []
460+ interruptions : list [RunItem ] = []
465461 for item_data in current_step_data .get ("interruptions" , []):
466462 agent_name = item_data ["agent" ]["name" ]
467463 agent = agent_map .get (agent_name )
0 commit comments