Web search tool (preview)
Items marked (preview) in this article are currently in public preview. This preview is provided without a service-level agreement, and we don’t recommend it for production workloads. Certain features might not be supported or might have constrained capabilities. For more information, see Supplemental Terms of Use for Microsoft Azure Previews.
- Web Search(preview) uses Grounding with Bing Search and Grounding with Bing Custom Search, which are First Party Consumption Services governed by these Grounding with Bing terms of use and the Microsoft Privacy Statement.
- The Microsoft Data Protection Addendum doesn’t apply to data sent to Grounding with Bing Search and Grounding with Bing Custom Search. When you use Grounding with Bing Search and Grounding with Bing Custom Search, data transfers occur outside compliance and geographic boundaries.
- Use of Grounding with Bing Search and Grounding with Bing Custom Search incurs costs. See pricing for details.
- See the management section for information about how Azure admins can manage access to use of web search.
Usage support
| Microsoft Foundry support | Python SDK | C# SDK | JavaScript SDK | Java SDK | REST API | Basic agent setup | Standard agent setup |
|---|---|---|---|---|---|---|---|
| ✔️ | ✔️ | ✔️ | ✔️ | - | ✔️ | ✔️ | ✔️ |
Prerequisites
- A basic or standard agent environment
- The latest prerelease package. See the quickstart for details.
- Azure credentials configured for authentication (such as
DefaultAzureCredential). - Environment variables configured:
AZURE_AI_PROJECT_ENDPOINT(orPROJECT_ENDPOINT): Your Foundry project endpoint URL.AZURE_AI_MODEL_DEPLOYMENT_NAME(orMODEL_DEPLOYMENT_NAME): Your model deployment name.
Code examples
- See best practices for information on optimizing tool usage.
- You need the latest prerelease package. See the quickstart for details.
General Web Search
The following example shows how to set up the AI Project client by using the Azure Identity library for authentication.General Web Search
In this example, you use the agent to perform the web search in the given location. The example in this section uses synchronous calls. For an asynchronous example, see the sample code in the Azure SDK for .NET repository on GitHub.General Web Search
The following example shows how to create a response by using an agent that has the web search tool enabled.Expected output
The following example shows the expected output when using the web search tool via the REST API:Use the web search tool with TypeScript
The following TypeScript example demonstrates how to create an agent with the web search tool. For an example that uses JavaScript, see the sample code example in the Azure SDK for JavaScript repository on GitHub.Expected output
The following example shows the expected output when running the TypeScript code:Configure the web search tool
You can configure web search behavior when you create your agent.Optional parameters for general web search
user_location: Helps web search return results relevant to a user’s geography. Use an approximate location when you want results localized to a country/region/city.search_context_size: Controls how much context window space to use for the search. Supported values arelow,medium, andhigh. The default ismedium.
Security and privacy considerations
- Treat web search results as untrusted input. Validate and sanitize data before you use it in downstream systems.
- Avoid sending secrets or sensitive personal data in prompts that might be forwarded to external services.
- Review the terms, privacy, and data boundary notes in the preview section of this article before enabling web search in production.
Troubleshooting
| Issue | Cause | Resolution |
|---|---|---|
| Web search isn’t used and no citations appear | Model didn’t determine web search was needed | Update your instructions to explicitly allow web search for up-to-date questions, and ask a query that requires current information. |
| Requests fail after enabling web search | Web search is disabled at the subscription level | Ask an admin to enable web search. See Administrator control for the web search tool. |
| REST requests return authentication errors | Bearer token is missing, expired, or has insufficient permissions | Refresh your token and confirm your access to the project and agent. |
| Search returns outdated information | Web content not recently indexed | Refine your query to explicitly request the most recent information. Results depend on Bing’s indexing schedule. |
| No results for specific topics | Query too narrow or content not indexed | Broaden your search query. Some niche topics might have limited web coverage. |
| Rate limiting errors (429) | Too many requests in a short time period | Implement exponential backoff and retry logic. Consider spacing out requests. |
| Inconsistent citation formatting | Response format varies by query type | Standardize citation handling in your application code. Parse both inline and reference-style citations. |
| Tool not available for deployment | Regional or model limitations | Confirm web search is available in your region and with your model deployment. Check tool best practices. |
Administrator control for the web search tool
You can enable or disable the web search tool in Foundry Agent Service at the subscription level by using Azure CLI. This setting applies to all accounts within the specified subscription.Prerequisites
Before running the following commands, make sure that you:- Have Azure CLI installed.
- Are signed in to Azure by using
az login. - Have Owner or Contributor access to the subscription.