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
To make the Grounding with Bing search tool available to your agent, use a connection to initialize the tool 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](https://ai.azure.com/).
conn_id = os.environ["BING_CONNECTION_NAME"] # Ensure the BING_CONNECTION_NAME environment variable is set
81
79
82
-
print(conn_id)
83
-
84
-
# Initialize agent bing tool and add the connection id
80
+
# Initialize the Bing Grounding tool
85
81
bing = BingGroundingTool(connection_id=conn_id)
86
82
87
-
# Create agent with the bing tool and process assistant run
88
83
with project_client:
84
+
# Create an agent with the Bing Grounding tool
89
85
agent = project_client.agents.create_agent(
90
-
model="gpt-4o",
91
-
name="my-assistant",
92
-
instructions="You are a helpful assistant",
93
-
tools=bing.definitions,
94
-
headers={"x-ms-enable-preview": "true"}
86
+
model=os.environ["MODEL_DEPLOYMENT_NAME"], # Model deployment name
87
+
name="my-agent", # Name of the agent
88
+
instructions="You are a helpful agent", # Instructions for the agent
89
+
tools=bing.definitions, # Attach the Bing Grounding tool
95
90
)
96
91
print(f"Created agent, ID: {agent.id}")
97
92
```
98
93
99
94
## Create a thread
100
95
101
96
```python
102
-
# Create thread for communication
103
-
thread = project_client.agents.create_thread()
97
+
# Create a thread for communication
98
+
thread = project_client.agents.threads.create()
104
99
print(f"Created thread, ID: {thread.id}")
105
100
106
-
#Create message to thread
107
-
message = project_client.agents.create_message(
101
+
#Add a message to the thread
102
+
message = project_client.agents.messages.create(
108
103
thread_id=thread.id,
109
-
role="user",
110
-
content="What is the top news today",
104
+
role="user",# Role of the message sender
105
+
content="What is the weather in Seattle today?", # Message content
111
106
)
112
-
print(f"Created message, ID: {message.id}")
107
+
print(f"Created message, ID: {message['id']}")
113
108
```
114
109
115
110
## Create a run and check the output
@@ -118,26 +113,22 @@ Create a run and observe that the model uses the Grounding with Bing Search tool
118
113
119
114
120
115
```python
121
-
# Create and process agent run in thread with tools
122
-
run = project_client.agents.create_and_process_run(thread_id=thread.id, agent_id=agent.id)
116
+
# Create and process an agent run
117
+
run = project_client.agents.runs.create_and_process(thread_id=thread.id, agent_id=agent.id)
123
118
print(f"Run finished with status: {run.status}")
124
119
125
-
# Retrieve run step details to get Bing Search query link
126
-
# To render the webpage, we recommend you replace the endpoint of Bing search query URLs with `www.bing.com` and your Bing search query URL would look like "https://www.bing.com/search?q={search query}"
Copy file name to clipboardExpand all lines: articles/ai-services/agents/how-to/tools/overview.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,8 @@ There are various ways to influence how your AI agent invokes tools:
50
50
51
51
## Prerequisites
52
52
53
-
*[A created agent](../../quickstart.md)
53
+
*[A created agent](../../quickstart.md)
54
+
* Make sure your AI model has enough Tokens-Per-Minute (TPM) allocated. We recommend having a minimum of 30k TPM. You can change the TPM allocation by going to **models + endpoints** in the [AI Foundry portal](https://ai.azure.com) and edit your model.
0 commit comments