You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -21,44 +21,38 @@ Use this article to find step-by-step instructions and code samples for the Deep
21
21
> [!NOTE]
22
22
> Limitation: The Deep Research tool is currently recommended only in nonstreaming scenarios. Using it with streaming can work, but it might occasionally time out and is therefore not recommended.
23
23
24
-
## Create a function to get and print an agent response
24
+
## Create an agent the Deep Research tool
25
25
26
26
```python
27
-
import asyncio
28
-
import os
27
+
import os, time
29
28
from typing import Optional
30
-
31
-
from azure.ai.projects.aioimportAIProjectClient
32
-
from azure.ai.agents.aioimport AgentsClient
29
+
from azure.ai.projects import AIProjectClient
30
+
from azure.identityimportDefaultAzureCredential
31
+
from azure.ai.agents import AgentsClient
33
32
from azure.ai.agents.models import DeepResearchTool, MessageRole, ThreadMessage
34
-
from azure.identity.aio import DefaultAzureCredential
To make the Deep Research tool available to your agent, use the `tools` parameter to initialize it and attach it to the agent. You can find your connection in the connected resources section of your project in the Azure AI Foundry portal. You also need to specify the deployment name of your Deep Research model.
91
+
# Initialize a Deep Research tool with Bing Connection ID and Deep Research model deployment name
# Create Agent with the Deep Research tool and process Agent run
98
+
with project_client:
116
99
117
-
agents_client =project_client.agents
100
+
withproject_client.agentsas agents_client:
118
101
119
102
# Create a new agent that has the Deep Research tool attached.
120
103
#NOTE: To add Deep Research to an existing agent, fetch it with `get_agent(agent_id)` and then,
121
104
# update the agent with the Deep Research tool.
122
-
agent =awaitagents_client.create_agent(
105
+
agent = agents_client.create_agent(
123
106
model=os.environ["MODEL_DEPLOYMENT_NAME"],
124
107
name="my-agent",
125
108
instructions="You are a helpful Agent that assists in researching scientific topics.",
126
109
tools=deep_research_tool.definitions,
127
110
)
128
-
print(f"Created agent, ID: {agent.id}")
129
-
```
130
-
131
-
## Create a thread
132
-
133
-
Create a thread and attach a message to it
134
-
135
-
```python
136
-
# Create thread for communication
137
-
thread =await agents_client.threads.create()
138
-
print(f"Created thread, ID: {thread.id}")
139
-
140
-
# Create message to thread
141
-
message =await agents_client.messages.create(
142
-
thread_id=thread.id,
143
-
role="user",
144
-
content=(
145
-
"Research the current state of studies on orca intelligence and orca language, including what is currently known about orcas' cognitive capabilities and communication systems."
146
-
),
147
-
)
148
-
print(f"Created message, ID: {message.id}")
149
-
150
-
```
151
-
152
-
## Create a run and check the output
153
-
154
-
Create a run and observe the response to the question.
155
-
156
-
> [!NOTE]
157
-
> According to Grounding with Bing's [terms of use and use and display requirements](https://www.microsoft.com/bing/apis/grounding-legal#use-and-display-requirements), you need to display both website URLs and Bing search query URLs in your custom interface. See the [Grounding with Bing Search documentation](./bing-grounding.md#how-to-display-grounding-with-bing-search-results) for more information.
158
-
159
-
```python
160
-
print("Start processing the message... this may take a few minutes to finish. Be patient!")
161
-
# Poll the run as long as run status is queued or in progress
162
-
run =await agents_client.runs.create(thread_id=thread.id, agent_id=agent.id)
163
-
last_message_id: Optional[str] =None
164
-
while run.status in ("queued", "in_progress"):
165
-
await asyncio.sleep(1)
166
-
run =await agents_client.runs.get(thread_id=thread.id, run_id=run.id)
# Clean-up and delete the agent once the run is finished.
188
-
#NOTE: Comment out this line if you plan to reuse the agent later.
189
-
await agents_client.delete_agent(agent.id)
190
-
print("Deleted agent")
191
-
192
-
193
-
if__name__=="__main__":
194
-
asyncio.run(main())
195
-
```
196
-
197
-
## Delete the agent (optional)
112
+
# [END create_agent_with_deep_research_tool]
113
+
print(f"Created agent, ID: {agent.id}")
198
114
199
-
If you decide you don't need your agent, you can delete with:
115
+
# Create thread for communication
116
+
thread = agents_client.threads.create()
117
+
print(f"Created thread, ID: {thread.id}")
118
+
119
+
# Create message to thread
120
+
message = agents_client.messages.create(
121
+
thread_id=thread.id,
122
+
role="user",
123
+
content=(
124
+
"Research the current state of studies on orca intelligence and orca language, including what is currently known about orcas' cognitive capabilities and communication systems."
125
+
),
126
+
)
127
+
print(f"Created message, ID: {message.id}")
128
+
129
+
print(f"Start processing the message... this may take a few minutes to finish. Be patient!")
130
+
# Poll the run as long as run status is queued or in progress
131
+
run = agents_client.runs.create(thread_id=thread.id, agent_id=agent.id)
132
+
last_message_id =None
133
+
while run.status in ("queued", "in_progress"):
134
+
time.sleep(1)
135
+
run = agents_client.runs.get(thread_id=thread.id, run_id=run.id)
*[Sample on GitHub](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-agents/samples/agents_async/sample_agents_deep_research_async.py)
165
+
*[Asynchronous sample on GitHub](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-agents/samples/agents_async/sample_agents_deep_research_async.py)
0 commit comments