Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@

from azure.ai.projects.aio import AIProjectClient
from azure.ai.agents.aio import AgentsClient
from azure.ai.agents.models import DeepResearchTool, MessageRole, ThreadMessage
from azure.ai.agents.models import (
DeepResearchTool,
MessageRole,
SubmitToolApprovalAction,
ThreadMessage,
ToolApproval,
)
from azure.identity.aio import DefaultAzureCredential


Expand Down Expand Up @@ -255,10 +261,27 @@ async def main() -> None:
# Poll the run as long as run status is queued or in progress
run = await agents_client.runs.create(thread_id=thread.id, agent_id=agent.id)
last_message_id: Optional[str] = None
while run.status in ("queued", "in_progress"):
while run.status in ("queued", "in_progress", "requires_action"):
await asyncio.sleep(1)
run = await agents_client.runs.get(thread_id=thread.id, run_id=run.id)

if run.status == "requires_action" and isinstance(
run.required_action, SubmitToolApprovalAction
):
tool_calls = run.required_action.submit_tool_approval.tool_calls
if not tool_calls:
print("Run requested tool approval but no tool calls were provided; cancelling run.")
await agents_client.runs.cancel(thread_id=thread.id, run_id=run.id)
break

approvals = [ToolApproval(tool_call_id=tool_call.id, approve=True) for tool_call in tool_calls]
run = await agents_client.runs.submit_tool_outputs(
thread_id=thread.id,
run_id=run.id,
tool_approvals=approvals,
)
continue

last_message_id = await fetch_and_print_new_agent_response(
thread_id=thread.id,
agents_client=agents_client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential
from azure.ai.agents import AgentsClient
from azure.ai.agents.models import DeepResearchTool, MessageRole, ThreadMessage
from azure.ai.agents.models import (
DeepResearchTool,
MessageRole,
SubmitToolApprovalAction,
ThreadMessage,
ToolApproval,
)


def convert_citations_to_superscript(markdown_content):
Expand Down Expand Up @@ -254,10 +260,27 @@ def create_research_summary(message: ThreadMessage, filepath: str = "research_re
# Poll the run as long as run status is queued or in progress
run = agents_client.runs.create(thread_id=thread.id, agent_id=agent.id)
last_message_id = None
while run.status in ("queued", "in_progress"):
while run.status in ("queued", "in_progress", "requires_action"):
time.sleep(1)
run = agents_client.runs.get(thread_id=thread.id, run_id=run.id)

if run.status == "requires_action" and isinstance(
run.required_action, SubmitToolApprovalAction
):
tool_calls = run.required_action.submit_tool_approval.tool_calls
if not tool_calls:
print("Run requested tool approval but no tool calls were provided; cancelling run.")
agents_client.runs.cancel(thread_id=thread.id, run_id=run.id)
break

approvals = [ToolApproval(tool_call_id=tool_call.id, approve=True) for tool_call in tool_calls]
run = agents_client.runs.submit_tool_outputs(
thread_id=thread.id,
run_id=run.id,
tool_approvals=approvals,
)
continue

last_message_id = fetch_and_print_new_agent_response(
thread_id=thread.id,
agents_client=agents_client,
Expand Down