22
33from dataclasses import dataclass , replace
44from textwrap import dedent
5- from typing import TYPE_CHECKING , Any , Optional
5+ from typing import TYPE_CHECKING , Any
66
77if TYPE_CHECKING :
88 from .agent import Agent
99 from .guardrail import InputGuardrailResult , OutputGuardrailResult
1010 from .items import ModelResponse , RunItem , TResponseInputItem
11- from .run_context import RunContextWrapper
12- from .run import RunConfig
1311 from .result import RunResult
12+ from .run import RunConfig
13+ from .run_context import RunContextWrapper
1414 from .tool_guardrails import (
1515 ToolGuardrailFunctionOutput ,
1616 ToolInputGuardrail ,
@@ -54,14 +54,15 @@ class MaxTurnsExceeded(AgentsException):
5454
5555 _DEFAULT_RESUME_PROMPT = """
5656 You reached the maximum number of turns.
57- Return a final answer to the query using ONLY the information already gathered in the conversation so far.
57+ Return a final answer to the query using ONLY the information already gathered \
58+ in the conversation so far.
5859 """
5960
6061 def __init__ (self , message : str ):
6162 self .message = message
6263 super ().__init__ (message )
6364
64- async def resume (self , prompt : Optional [ str ] = _DEFAULT_RESUME_PROMPT ) -> RunResult :
65+ async def resume (self , prompt : str | None = _DEFAULT_RESUME_PROMPT ) -> RunResult :
6566 """Resume the failed run asynchronously with a final, tool-free turn.
6667
6768 Note:
@@ -87,7 +88,7 @@ async def resume(self, prompt: Optional[str] = _DEFAULT_RESUME_PROMPT) -> RunRes
8788 run_config = run_config ,
8889 )
8990
90- def resume_sync (self , prompt : Optional [ str ] = _DEFAULT_RESUME_PROMPT ) -> RunResult :
91+ def resume_sync (self , prompt : str | None = _DEFAULT_RESUME_PROMPT ) -> RunResult :
9192 """Resume the failed run synchronously with a final, tool-free turn.
9293
9394 Note:
@@ -116,7 +117,7 @@ def resume_sync(self, prompt: Optional[str] = _DEFAULT_RESUME_PROMPT) -> RunResu
116117 def _prepare_resume_arguments (
117118 self ,
118119 run_data : RunErrorDetails ,
119- prompt : Optional [ str ] = None ,
120+ prompt : str | None = None ,
120121 ) -> tuple [list [TResponseInputItem ], RunConfig ]:
121122 from .items import ItemHelpers
122123 from .model_settings import ModelSettings
@@ -142,7 +143,7 @@ def _prepare_resume_arguments(
142143 run_config ,
143144 )
144145
145- def _normalize_resume_prompt (self , prompt : Optional [ str ] ) -> Optional [ str ] :
146+ def _normalize_resume_prompt (self , prompt : str | None ) -> str | None :
146147 if prompt is None :
147148 return None
148149 normalized = dedent (prompt ).strip ()
@@ -151,7 +152,8 @@ def _normalize_resume_prompt(self, prompt: Optional[str]) -> Optional[str]:
151152 def _require_run_data (self ) -> RunErrorDetails :
152153 if self .run_data is None :
153154 raise RuntimeError (
154- "Run data is not available; resume() can only be called on exceptions raised by Runner."
155+ "Run data is not available; resume() can only be called on\
156+ exceptions raised by Runner."
155157 )
156158 return self .run_data
157159
0 commit comments