Skip to content

Commit c62ba7e

Browse files
committed
run black
1 parent 13358f1 commit c62ba7e

File tree

4 files changed

+37
-25
lines changed

4 files changed

+37
-25
lines changed

sdk/ai/azure-ai-agents/azure/ai/agents/models/_patch.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@
4040
)
4141

4242
from azure.ai.agents.models import RunStatus
43+
4344
# NOTE: Avoid importing RunsOperations here to prevent circular import with operations package.
4445
from typing import TYPE_CHECKING
46+
4547
if 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

17321736
class AsyncToolSet(BaseToolSet):
@@ -1777,6 +1781,7 @@ async def execute_tool_calls(self, tool_calls: List[Any]) -> Any:
17771781
BaseAsyncAgentEventHandlerT = TypeVar("BaseAsyncAgentEventHandlerT", bound="BaseAsyncAgentEventHandler")
17781782
# BaseAgentEventHandlerT is defined after BaseAgentEventHandler class to avoid forward reference during parsing.
17791783

1784+
17801785
async 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

19871990
class 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.
20482052
BaseAgentEventHandlerT = TypeVar("BaseAgentEventHandlerT", bound="BaseAgentEventHandler")
20492053

sdk/ai/azure-ai-agents/azure/ai/agents/operations/_patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ def create_and_process(
555555
# Monitor and process the run status
556556
if not run_handler:
557557
run_handler = _models.RunHandler()
558-
558+
559559
return run_handler._start(self, run, polling_interval)
560560

561561
@overload

sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_functions_in_create_and_process.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,15 @@
4949
# Initialize function tool with user functions
5050
functions = FunctionTool(functions=user_functions)
5151

52+
5253
class MyRunHandler(RunHandler):
53-
def submit_function_call_output(self, run: ThreadRun, tool_call: RequiredFunctionToolCall, tool_call_details: RequiredFunctionToolCallDetails) -> Optional[Any]:
54+
def submit_function_call_output(
55+
self, run: ThreadRun, tool_call: RequiredFunctionToolCall, tool_call_details: RequiredFunctionToolCallDetails
56+
) -> Optional[Any]:
5457
print(f"Call function: {tool_call_details.name}")
5558
return functions.execute(tool_call)
5659

60+
5761
with project_client:
5862
agents_client = project_client.agents
5963

sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_mcp_in_create_and_process.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,18 @@
6565
mcp_tool.allow_tool(search_api_code)
6666
print(f"Allowed tools: {mcp_tool.allowed_tools}")
6767

68+
6869
class MyRunHandler(RunHandler):
69-
def submit_mcp_tool_approval(self, run: ThreadRun, tool_call: RequiredMcpToolCall, **kwargs) -> Optional[ToolApproval]:
70+
def submit_mcp_tool_approval(
71+
self, run: ThreadRun, tool_call: RequiredMcpToolCall, **kwargs
72+
) -> Optional[ToolApproval]:
7073
return ToolApproval(
7174
tool_call_id=tool_call.id,
7275
approve=True,
7376
headers=mcp_tool.headers,
7477
)
7578

79+
7680
# Create agent with MCP tool and process agent run
7781
with project_client:
7882
agents_client = project_client.agents
@@ -83,7 +87,7 @@ def submit_mcp_tool_approval(self, run: ThreadRun, tool_call: RequiredMcpToolCal
8387
model=os.environ["MODEL_DEPLOYMENT_NAME"],
8488
name="my-mcp-agent",
8589
instructions="You are a helpful agent that can use MCP tools to assist users. Use the available MCP tools to answer questions and perform tasks.",
86-
toolset=toolset
90+
toolset=toolset,
8791
)
8892
# [END create_agent_with_mcp_tool]
8993

@@ -105,7 +109,7 @@ def submit_mcp_tool_approval(self, run: ThreadRun, tool_call: RequiredMcpToolCal
105109
# [START handle_tool_approvals]
106110
# Create and process agent run in thread with MCP tools
107111
mcp_tool.update_headers("SuperSecret", "123456")
108-
112+
109113
run_handler = MyRunHandler()
110114
# mcp_tool.set_approval_mode("never") # Uncomment to disable approval requirement
111115
run = agents_client.runs.create_and_process(thread_id=thread.id, agent_id=agent.id, run_handler=run_handler)

0 commit comments

Comments
 (0)