This sample demonstrates how to build a streaming enterprise agent using Azure AI Agent Service. The agent can answer questions in real time using local HR and company policy documents, integrate external context via Bing, using gpt-4o-2024-05-13.
This demo teaches developers how to:
-
Create or Reuse Agents Programmatically
Demonstrates how to connect to an Azure AI Foundry hub, either create a new agent with customized instructions (using GPT-4o or any supported model), or reuse an existing agent. -
Incorporate Vector Stores for Enterprise Data
Shows how to automatically create or reuse a vector store containing local policy files (HR, PTO, etc.), enabling retrieval-augmented generation (RAG). -
Integrate Server-Side Tools
Illustrates adding tools—like Bing search, file search, and custom Python functions—into a singleToolSet
, and how to intercept and log each tool call. -
Stream Real-Time Agent Responses
Demonstrates a streaming approach for partial message updates from the agent, seamlessly handling partial tool invocation and chunked text output. -
Build an Interactive Gradio UI
Provides a Gradio-based chat interface that prompts the agent with user questions, displays partial tool calls and final results, and makes it easy to extend or adapt the UI.
Use this demo as a reference for creating, deploying, and managing enterprise-scale AI agents with strong integration, data security, and real-time conversation capabilities.
- Python 3.9+
- Visual Studio Code with the Python and Jupyter extensions
- An Azure AI Foundry resource set up (see Azure AI Agent Service docs)
-
Clone this repository:
git clone https://github.com/Azure-Samples/azure-ai-agent-service-enterprise-demo.git
-
Create a virtual environment (using venv as an example):
python -m venv .venv
-
Activate your virtual environment:
- Windows:
.venv\Scripts\activate
- macOS/Linux:
source .venv/bin/activate
- Windows:
-
Install the required dependencies:
pip install -r requirements.txt
-
Create a
.env
file at the root of this folder to store secret keys and settings (e.g., the connection string and optional model name). You can copy the provided.env.example
file:-
Windows (PowerShell):
Copy-Item -Path .env.example -Destination .env
-
macOS/Linux:
cp .env.example .env
Then, open the
.env
file and update it with your configuration details.-
Add your Azure AI Foundry connection string:
PROJECT_CONNECTION_STRING="<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<ProjectName>"
-
Specify the compatible model you want to use (e.g. GPT-4o):
MODEL_NAME="YOUR_MODEL_NAME"
-
(Optional) Grounding with Bing
You can add real-time web data to your agent via Grounding with Bing Search. For details on how to create a Bing search resource, link it with your Azure AI Agent, and meet display requirements, see Grounding with Bing Search.
BING_CONNECTION_NAME="YOUR_CONNECTION_NAME"
In this sample, the code automatically tries to discover an .env variable named
BING_CONNECTION_NAME
. If available, you’ll see a console message likebing > connected
. Otherwise, it gracefully proceeds without Bing. -
(Optional) OpenWeather API keys to enable
fetch_weather
tool:OPENWEATHER_GEO_API_KEY="YOUR_OPENWEATHER_GEOCODING_API_KEY" OPENWEATHER_ONE_API_KEY="YOUR_OPENWEATHER_ONE_CALL_API_KEY"
If you leave these blank, the weather function will simply return an error or remain disabled.
Tip: If you don’t plan to use Bing grounding or OpenWeather, you can skip setting up those resources. The demo will still work with your local documents and core agent features.
Make sure that .env is listed in your .gitignore. Never commit your credentials to source control!
-
-
Open the project folder in Visual Studio Code:
- Select your Python interpreter:
- Press Ctrl+Shift+P (or Cmd+Shift+P on Mac)
- Choose Python: Select Interpreter and select the
venv
environment.
- Select your Python interpreter:
-
Run Jupyter Notebook:
- Open the
enterprise-streaming-agent.ipynb
, in VS Code. - Step through the cells to:
- Connect to Azure AI Foundry and create or reuse an agent.
- Optionally upload local HR/policy files to a vector store.
- Add Bing integration, local file search, and custom Python functions (weather, stock lookup, etc.) to the agent’s ToolSet.
- See real-time streaming queries and partial responses via your console logs and Gradio chat UI.
- Open the
-
Try the Demo Chat:
- When you run the notebook, a local Gradio instance should launch in your cell output. You can click the localhost link to open the chat UI.
- Ask the agent questions like:
- “What’s my company’s remote work policy?”
- “Fetch the weather forecast for Seattle tomorrow.” (Requires valid OpenWeather keys)
- “How is MSFT stock price trending today?”
- “Send an email summary of the HR policy.”
- Gradio
This project uses Gradio under the Apache License 2.0. No modifications to Gradio’s source code are distributed in this repository.