4040)
4141
4242from azure .ai .agents .models import RunStatus
43+
4344# NOTE: Avoid importing RunsOperations here to prevent circular import with operations package.
4445from typing import TYPE_CHECKING
46+
4547if TYPE_CHECKING : # pragma: no cover - type checking only
4648 from ..operations import RunsOperations # noqa: F401
4749
@@ -1704,7 +1706,9 @@ def execute_tool_calls(self, tool_calls: List[Any]) -> Any:
17041706 """
17051707 return self ._execute_tool_calls (tool_calls )
17061708
1707- def _execute_tool_calls (self , tool_calls : List [Any ], run : Optional [ThreadRun ] = None , run_handler : Optional ['RunHandler' ] = None ) -> Any :
1709+ def _execute_tool_calls (
1710+ self , tool_calls : List [Any ], run : Optional [ThreadRun ] = None , run_handler : Optional ["RunHandler" ] = None
1711+ ) -> Any :
17081712 tool_outputs = []
17091713
17101714 for tool_call in tool_calls :
@@ -1726,7 +1730,7 @@ def _execute_tool_calls(self, tool_calls: List[Any], run: Optional[ThreadRun] =
17261730 tool_output = {"tool_call_id" : tool_call .id , "output" : str (e )}
17271731 tool_outputs .append (tool_output )
17281732
1729- return tool_outputs
1733+ return tool_outputs
17301734
17311735
17321736class AsyncToolSet (BaseToolSet ):
@@ -1777,6 +1781,7 @@ async def execute_tool_calls(self, tool_calls: List[Any]) -> Any:
17771781BaseAsyncAgentEventHandlerT = TypeVar ("BaseAsyncAgentEventHandlerT" , bound = "BaseAsyncAgentEventHandler" )
17781782# BaseAgentEventHandlerT is defined after BaseAgentEventHandler class to avoid forward reference during parsing.
17791783
1784+
17801785async def async_chain (* iterators : AsyncIterator [T ]) -> AsyncIterator [T ]:
17811786 for iterator in iterators :
17821787 async for item in iterator :
@@ -1878,9 +1883,7 @@ def _start(self, runs_operations: "RunsOperations", run: ThreadRun, polling_inte
18781883 time .sleep (polling_interval )
18791884 run = runs_operations .get (thread_id = run .thread_id , run_id = run .id )
18801885
1881- if run .status == RunStatus .REQUIRES_ACTION and isinstance (
1882- run .required_action , SubmitToolOutputsAction
1883- ):
1886+ if run .status == RunStatus .REQUIRES_ACTION and isinstance (run .required_action , SubmitToolOutputsAction ):
18841887 tool_calls = run .required_action .submit_tool_outputs .tool_calls
18851888 if not tool_calls :
18861889 logger .warning ("No tool calls provided - cancelling run" )
@@ -1896,7 +1899,8 @@ def _start(self, runs_operations: "RunsOperations", run: ThreadRun, polling_inte
18961899 if _has_errors_in_toolcalls_output (tool_outputs ):
18971900 if current_retry >= runs_operations ._function_tool_max_retry : # pylint:disable=no-else-return
18981901 logger .warning (
1899- "Tool outputs contain errors - reaching max retry %s" , runs_operations ._function_tool_max_retry
1902+ "Tool outputs contain errors - reaching max retry %s" ,
1903+ runs_operations ._function_tool_max_retry ,
19001904 )
19011905 run = runs_operations .cancel (thread_id = run .thread_id , run_id = run .id )
19021906 else :
@@ -1966,22 +1970,21 @@ def submit_mcp_tool_approval(
19661970 tool_call : RequiredMcpToolCall ,
19671971 ** kwargs ,
19681972 ) -> Optional [ToolApproval ]:
1969- # NOTE: Implementation intentionally returns None; override in subclasses for real approval logic.
1970- """Return a ``ToolApproval`` for an MCP tool call or ``None`` to indicate rejection/cancellation.
1971-
1972- Override this to implement approval policies (interactive prompt, RBAC, heuristic checks, etc.).
1973- Returning ``None`` triggers cancellation logic in ``_start``.
1973+ # NOTE: Implementation intentionally returns None; override in subclasses for real approval logic.
1974+ """Return a ``ToolApproval`` for an MCP tool call or ``None`` to indicate rejection/cancellation.
19741975
1975- :param run: Current run containing the MCP approval request.
1976- :type run: ThreadRun
1977- :param tool_call: The MCP tool call requiring approval.
1978- :type tool_call: RequiredMcpToolCall
1979- :keyword kwargs: Additional keyword arguments for extensibility.
1980- :return: A populated ``ToolApproval`` instance on approval, or ``None`` to decline.
1981- :rtype: Optional[ToolApproval]
1982- """
1983- return None
1976+ Override this to implement approval policies (interactive prompt, RBAC, heuristic checks, etc.).
1977+ Returning ``None`` triggers cancellation logic in ``_start``.
19841978
1979+ :param run: Current run containing the MCP approval request.
1980+ :type run: ThreadRun
1981+ :param tool_call: The MCP tool call requiring approval.
1982+ :type tool_call: RequiredMcpToolCall
1983+ :keyword kwargs: Additional keyword arguments for extensibility.
1984+ :return: A populated ``ToolApproval`` instance on approval, or ``None`` to decline.
1985+ :rtype: Optional[ToolApproval]
1986+ """
1987+ return None
19851988
19861989
19871990class BaseAgentEventHandler (Iterator [T ]):
@@ -2044,6 +2047,7 @@ def until_done(self) -> None:
20442047 except StopIteration :
20452048 pass
20462049
2050+
20472051# Now that BaseAgentEventHandler is defined, we can bind the TypeVar.
20482052BaseAgentEventHandlerT = TypeVar ("BaseAgentEventHandlerT" , bound = "BaseAgentEventHandler" )
20492053
0 commit comments