Agent to do websearch, built with agent framework
This sample demonstrates how to build a web search agent using Bing Grounding, hosted using Azure AI AgentServer SDK and deploy it to Microsoft Foundry using the Azure Developer CLI ai agent extension.
The agent uses Bing Grounding to search the web for current information and provide accurate, well-sourced answers. This demonstrates:
- How to integrate Bing Grounding as a tool in an AI agent
- How to use the
HostedWebSearchToolfrom the Agent Framework
The agent is hosted using the Azure AI AgentServer SDK, which provisions a REST API endpoint compatible with the OpenAI Responses protocol. This allows interaction with the agent using OpenAI Responses compatible clients.
The hosted agent can be seamlessly deployed to Microsoft Foundry using the Azure Developer CLI ai agent extension. The extension builds a container image into Azure Container Registry (ACR), and creates a hosted agent version and deployment on Microsoft Foundry.
Before running this sample, ensure you have:
- An Azure AI Foundry project configured
- A deployment of a chat model (e.g.,
gpt-4.1-mini) - A Bing Grounding connection in your project
- Azure CLI installed and authenticated (
az login) - Python 3.10+ installed
Create a .env file with the following environment variables:
Note: The
.envfile is for local development only. When deploying to Azure AI Foundry, remove the.envfile and configure environment variables inagent.yamlinstead.
AZURE_AI_PROJECT_ENDPOINT=https://<your-foundry-account>.services.ai.azure.com/api/projects/<your-project>
AZURE_AI_MODEL_DEPLOYMENT_NAME=<your-model-deployment> # e.g., gpt-4.1-mini
BING_GROUNDING_CONNECTION_ID=/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.CognitiveServices/accounts/<foundry-account>/projects/<project>/connections/<bing-connection-name>Install the required Python dependencies using pip:
pip install -r requirements.txtTo run the agent, execute the following command in your terminal:
python main.pyThis will start the hosted agent locally on http://localhost:8088/.
curl -X POST http://localhost:8088/responses \
-H "Content-Type: application/json" \
-d '{"input": "What is the latest news in AI?"}' | jq .To deploy your agent to Microsoft Foundry, follow the comprehensive deployment guide at https://aka.ms/azdaiagent/docs
We recommend using azd cloud build, which always builds images with the correct architecture.
If you choose to build locally, and your machine is not linux/amd64 (for example, an Apple Silicon Mac), the image will not be compatible with our service, causing runtime failures.
Fix for local builds
Use this command to build the image locally:
docker build --platform=linux/amd64 -t image .This forces the image to be built for the required amd64 architecture.