Skip to content

Commit 192c2fc

Browse files
Merge pull request #779 from MicrosoftDocs/main
2 parents fd58ef5 + bed3e8b commit 192c2fc

11 files changed

Lines changed: 1098 additions & 8 deletions

File tree

agent-framework/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ items:
1616
href: user-guide/model-context-protocol/TOC.yml
1717
- name: Workflows
1818
href: user-guide/workflows/TOC.yml
19+
- name: Hosting
20+
href: user-guide/hosting/TOC.yml
1921
- name: Integrations
2022
items:
2123
- name: AG-UI

agent-framework/tutorials/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
href: overview.md
33
- name: Agents
44
href: agents/TOC.yml
5+
- name: Plugins
6+
href: plugins/TOC.yml
57
- name: Workflows
68
href: workflows/TOC.yml
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- name: Use Microsoft Purview SDK with Agent Framework
2+
href: use-purview-with-agent-framework-sdk.md
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
title: Use Microsoft Purview SDK with Agent Framework
3+
description: Learn how to integrate Microsoft Purview SDK for data security and governance in your Agent Framework project
4+
zone_pivot_groups: programming-languages
5+
author: reezaali149
6+
ms.topic: conceptual
7+
ms.author: v-reezaali
8+
ms.date: 10/28/2025
9+
ms.service: purview
10+
---
11+
12+
# Use Microsoft Purview SDK with Agent Framework
13+
14+
Microsoft Purview provides enterprise-grade data security, compliance, and governance capabilities for AI applications. By integrating Purview APIs within the Agent Framework SDK, developers can build intelligent agents that are secure by design, while ensuring sensitive data in prompts and responses are protected and compliant with organizational policies.
15+
16+
## Why integrate Purview with Agent Framework?
17+
18+
- **Prevent sensitive data leaks**: Inline blocking of sensitive content based on Data Loss Prevention (DLP) policies.
19+
- **Enable governance**: Log AI interactions in Purview for Audit, Communication Compliance, Insider Risk Management, eDiscovery, and Data Lifecycle Management.
20+
- **Accelerate adoption**: Enterprise customers require compliance for AI apps. Purview integration unblocks deployment.
21+
22+
## Prerequisites
23+
24+
Before you begin, ensure you have:
25+
26+
- Microsoft Azure subscription with Microsoft Purview configured.
27+
- Microsoft 365 subscription with an E5 license and pay-as-you-go billing setup.
28+
- For testing, you can use a Microsoft 365 Developer Program tenant. For more information, see [Join the Microsoft 365 Developer Program](https://developer.microsoft.com/en-us/microsoft-365/dev-program).
29+
- Agent Framework SDK: To install the Agent Framework SDK:
30+
- Python: Run `pip install agent-framework`.
31+
- .NET: Install from NuGet.
32+
33+
## How to integrate Microsoft Purview into your agent
34+
35+
In your agent's workflow middleware pipeline, you can add Microsoft Purview policy middleware to intercept prompts and responses to determine if they meet the policies set up in Microsoft Purview. The Agent Framework SDK is capable of intercepting agent-to-agent or end-user chat client prompts and responses.
36+
37+
The following code sample demonstrates how to add the Microsoft Purview policy middleware to your agent code. If you're new to Agent Framework, see [Create and run an agent with Agent Framework](/agent-framework/tutorials/agents/run-agent?pivots=programming-language-python).
38+
39+
::: zone pivot="programming-language-csharp"
40+
41+
```csharp
42+
43+
using Azure.AI.OpenAI;
44+
using Azure.Core;
45+
using Azure.Identity;
46+
using Microsoft.Agents.AI;
47+
using Microsoft.Agents.AI.Purview;
48+
using Microsoft.Extensions.AI;
49+
using OpenAI;
50+
51+
string endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
52+
string deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
53+
string purviewClientAppId = Environment.GetEnvironmentVariable("PURVIEW_CLIENT_APP_ID") ?? throw new InvalidOperationException("PURVIEW_CLIENT_APP_ID is not set.");
54+
55+
TokenCredential browserCredential = new InteractiveBrowserCredential(
56+
new InteractiveBrowserCredentialOptions
57+
{
58+
ClientId = purviewClientAppId
59+
});
60+
61+
AIAgent agent = new AzureOpenAIClient(
62+
new Uri(endpoint),
63+
new AzureCliCredential())
64+
.GetChatClient(deploymentName)
65+
.CreateAIAgent("You are a secure assistant.")
66+
.AsBuilder()
67+
.WithPurview(browserCredential, new PurviewSettings("My Secure Agent"))
68+
.Build();
69+
70+
AgentRunResponse response = await agent.RunAsync("Summarize zero trust in one sentence.").ConfigureAwait(false);
71+
Console.WriteLine(response);
72+
73+
```
74+
75+
::: zone-end
76+
::: zone pivot="programming-language-python"
77+
78+
```python
79+
import asyncio
80+
import os
81+
from agent_framework import ChatAgent, ChatMessage, Role
82+
from agent_framework.azure import AzureOpenAIChatClient
83+
from agent_framework.microsoft import PurviewPolicyMiddleware, PurviewSettings
84+
from azure.identity import AzureCliCredential, InteractiveBrowserCredential
85+
86+
# Set default environment variables if not already set
87+
os.environ.setdefault("AZURE_OPENAI_ENDPOINT", "<azureOpenAIEndpoint>")
88+
os.environ.setdefault("AZURE_OPENAI_CHAT_DEPLOYMENT_NAME", "<azureOpenAIChatDeploymentName>")
89+
90+
async def main():
91+
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
92+
purview_middleware = PurviewPolicyMiddleware(
93+
credential=InteractiveBrowserCredential(
94+
client_id="<clientId>",
95+
),
96+
settings=PurviewSettings(app_name="My Secure Agent")
97+
)
98+
agent = ChatAgent(
99+
chat_client=chat_client,
100+
instructions="You are a secure assistant.",
101+
middleware=[purview_middleware]
102+
)
103+
response = await agent.run(ChatMessage(role=Role.USER, text="Summarize zero trust in one sentence."))
104+
print(response)
105+
106+
if __name__ == "__main__":
107+
asyncio.run(main())
108+
```
109+
110+
::: zone-end
111+
112+
---
113+
114+
## Next steps
115+
116+
Now that you added the above code to your agent, perform the following steps to test the integration of Microsoft Purview into your code:
117+
118+
1. **Entra registration**: Register your agent and add the required Microsoft Graph permissions ([ProtectionScopes.Compute.All](/graph/api/userprotectionscopecontainer-compute), [ContentActivity.Write](/graph/api/activitiescontainer-post-contentactivities), [Content.Process.All](/graph/api/userdatasecurityandgovernance-processcontent)) to the Service Principal. For more information, see [Register an application in Microsoft Entra ID](/entra/identity-platform/quickstart-register-app) and [dataSecurityAndGovernance resource type](/graph/api/resources/datasecurityandgovernance). You'll need the Microsoft Entra app ID in the next step.
119+
1. **Purview policies**: Configure Purview policies using the Microsoft Entra app ID to enable agent communications data to flow into Purview. For more information, see [Configure Microsoft Purview](/purview/developer/configurepurview).
120+
121+
## Resources
122+
123+
::: zone pivot="programming-language-csharp"
124+
125+
- Nuget: [Microsoft.Agents.AI.Purview](https://www.nuget.org/packages/Microsoft.Agents.AI.Purview/)
126+
- Github: [Microsoft.Agents.AI.Purview](https://github.com/microsoft/agent-framework/tree/main/dotnet/src/Microsoft.Agents.AI.Purview)
127+
- Sample: [AgentWithPurview](https://github.com/microsoft/agent-framework/tree/main/dotnet/samples/Purview/AgentWithPurview)
128+
129+
::: zone-end
130+
::: zone pivot="programming-language-python"
131+
132+
- [PyPI Package: Microsoft Agent Framework - Purview Integration (Python)](https://pypi.org/project/agent-framework-purview/).
133+
- [GitHub: Microsoft Agent Framework – Purview Integration (Python) source code](https://github.com/microsoft/agent-framework/tree/main/python/packages/purview).
134+
- [Code Sample: Purview Policy Enforcement Sample (Python)](https://github.com/microsoft/agent-framework/tree/main/python/samples/getting_started/purview_agent).
135+
136+
::: zone-end

agent-framework/user-guide/agents/agent-observability.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,11 @@ See a full example of an agent with OpenTelemetry enabled in the [Agent Framewor
167167

168168
## Enable Observability
169169

170-
To enable observability in your python application, you do not need to install anything extra, by default the following package are installed:
170+
To enable observability in your python application, in most cases you do not need to install anything extra, by default the following package are installed:
171171

172172
```text
173173
"opentelemetry-api",
174174
"opentelemetry-sdk",
175-
"azure-monitor-opentelemetry",
176-
"azure-monitor-opentelemetry-exporter",
177175
"opentelemetry-exporter-otlp-proto-grpc",
178176
"opentelemetry-semantic-conventions-ai",
179177
```
@@ -220,7 +218,7 @@ The easiest way to enable observability for your application is to set the follo
220218
This can be used for any compliant OTLP endpoint, such as [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/), [Aspire Dashboard](/dotnet/aspire/fundamentals/dashboard/overview?tabs=bash) or any other OTLP compliant endpoint.
221219
- APPLICATIONINSIGHTS_CONNECTION_STRING
222220
Default is `None`, set to your Application Insights connection string to export to Azure Monitor.
223-
You can find the connection string in the Azure portal, in the "Overview" section of your Application Insights resource.
221+
You can find the connection string in the Azure portal, in the "Overview" section of your Application Insights resource. This will require the `azure-monitor-opentelemetry-exporter` package to be installed.
224222
- VS_CODE_EXTENSION_PORT
225223
Default is `4317`, set to the port the AI Toolkit or AzureAI Foundry VS Code extension is running on.
226224

@@ -260,6 +258,14 @@ Azure AI Foundry has built-in support for tracing, with a really great visualiza
260258

261259
When you have a Azure AI Foundry project setup with a Application Insights resource, you can do the following:
262260

261+
1) Install the `azure-monitor-opentelemetry-exporter` package:
262+
263+
```bash
264+
pip install azure-monitor-opentelemetry-exporter>=1.0.0b41
265+
```
266+
267+
2) Then you can setup observability for your Azure AI Foundry project as follows:
268+
263269
```python
264270
from agent_framework.azure import AzureAIAgentClient
265271
from azure.identity import AzureCliCredential
@@ -269,7 +275,22 @@ agent_client = AzureAIAgentClient(credential=AzureCliCredential(), project_endpo
269275
await agent_client.setup_azure_ai_observability()
270276
```
271277

272-
This is a convenience method, that will use the project client, to get the Application Insights connection string, and then call `setup_observability` with that connection string.
278+
This is a convenience method, that will use the project client, to get the Application Insights connection string, and then call `setup_observability` with that connection string, overriding any existing connection string set via environment variable.
279+
280+
### Zero-code instrumentation
281+
282+
Because we use the standard OpenTelemetry SDK, you can also use zero-code instrumentation to instrument your application, run you code like this:
283+
284+
```bash
285+
opentelemetry-instrument \
286+
--traces_exporter console,otlp \
287+
--metrics_exporter console \
288+
--service_name your-service-name \
289+
--exporter_otlp_endpoint 0.0.0.0:4317 \
290+
python agent_framework_app.py
291+
```
292+
293+
See the [OpenTelemetry Zero-code Python documentation](https://opentelemetry.io/docs/zero-code/python/) for more information and details of the environment variables used.
273294

274295
## Spans and metrics
275296

@@ -288,7 +309,7 @@ The metrics that are created are:
288309
- For function invocation during the `execute_tool` operations:
289310
- `agent_framework.function.invocation.duration` (histogram): This metric measures the duration of each function execution, in seconds.
290311

291-
## Example trace output
312+
### Example trace output
292313

293314
When you run an agent with observability enabled, you'll see trace data similar to the following console output:
294315

@@ -328,7 +349,7 @@ This trace shows:
328349
- **Model information**: The AI system used (OpenAI) and response ID
329350
- **Token usage**: Input and output token counts for cost tracking
330351

331-
## Getting started
352+
## Samples
332353

333354
We have a number of samples in our repository that demonstrate these capabilities, see the [observability samples folder](https://github.com/microsoft/agent-framework/tree/main/python/samples/getting_started/observability) on Github. That includes samples for using zero-code telemetry as well.
334355

agent-framework/user-guide/agents/agent-types/anthropic-agent.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,35 @@ async def explicit_config_example():
9494
print(result.text)
9595
```
9696

97+
### Using Anthropic on Foundry
98+
99+
After you've setup Anthropic on Foundry, ensure you have the following environment variables set:
100+
101+
```bash
102+
ANTHROPIC_FOUNDRY_API_KEY="your-foundry-api-key"
103+
ANTHROPIC_FOUNDRY_RESOURCE="your-foundry-resource-name"
104+
```
105+
Then create the agent as follows:
106+
107+
```python
108+
from agent_framework.anthropic import AnthropicClient
109+
from anthropic import AsyncAnthropicFoundry
110+
111+
async def foundry_example():
112+
agent = AnthropicClient(
113+
anthropic_client=AsyncAnthropicFoundry()
114+
).create_agent(
115+
name="FoundryAgent",
116+
instructions="You are a helpful assistant using Anthropic on Foundry.",
117+
)
118+
119+
result = await agent.run("How do I use Anthropic on Foundry?")
120+
print(result.text)
121+
```
122+
123+
> Note:
124+
> This requires `anthropic>=0.74.0` to be installed.
125+
97126
## Agent Features
98127

99128
### Function Tools

agent-framework/user-guide/agents/agent-types/azure-ai-foundry-agent.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Add the required NuGet packages to your project.
2121

2222
```powershell
2323
dotnet add package Azure.Identity
24-
dotnet add package Microsoft.Agents.AI.AzureAI --prerelease
24+
dotnet add package Microsoft.Agents.AI.AzureAI.Persistent --prerelease
2525
```
2626

2727
## Creating Azure AI Foundry Agents
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- name: Overview
2+
href: index.md
3+
- name: A2A Integration
4+
href: agent-to-agent-integration.md
5+
- name: OpenAI Integration
6+
href: openai-integration.md

0 commit comments

Comments
 (0)