agent-framework-azure-contentunderstanding 1.0.0a260429__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agent_framework_azure_contentunderstanding-1.0.0a260429/LICENSE +21 -0
- agent_framework_azure_contentunderstanding-1.0.0a260429/PKG-INFO +156 -0
- agent_framework_azure_contentunderstanding-1.0.0a260429/README.md +127 -0
- agent_framework_azure_contentunderstanding-1.0.0a260429/agent_framework_azure_contentunderstanding/__init__.py +28 -0
- agent_framework_azure_contentunderstanding-1.0.0a260429/agent_framework_azure_contentunderstanding/_context_provider.py +858 -0
- agent_framework_azure_contentunderstanding-1.0.0a260429/agent_framework_azure_contentunderstanding/_detection.py +234 -0
- agent_framework_azure_contentunderstanding-1.0.0a260429/agent_framework_azure_contentunderstanding/_extraction.py +297 -0
- agent_framework_azure_contentunderstanding-1.0.0a260429/agent_framework_azure_contentunderstanding/_file_search.py +101 -0
- agent_framework_azure_contentunderstanding-1.0.0a260429/agent_framework_azure_contentunderstanding/_models.py +115 -0
- agent_framework_azure_contentunderstanding-1.0.0a260429/pyproject.toml +101 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-framework-azure-contentunderstanding
|
|
3
|
+
Version: 1.0.0a260429
|
|
4
|
+
Summary: Azure Content Understanding integration for Microsoft Agent Framework.
|
|
5
|
+
Author-email: Microsoft <af-support@microsoft.com>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: agent-framework-core>=1.2.2,<2
|
|
20
|
+
Requires-Dist: agent-framework-foundry>=1.2.2,<2
|
|
21
|
+
Requires-Dist: azure-ai-contentunderstanding>=1.0.1,<1.1
|
|
22
|
+
Requires-Dist: aiohttp>=3.9,<4
|
|
23
|
+
Requires-Dist: filetype>=1.2,<2
|
|
24
|
+
Project-URL: homepage, https://aka.ms/agent-framework
|
|
25
|
+
Project-URL: issues, https://github.com/microsoft/agent-framework/issues
|
|
26
|
+
Project-URL: release_notes, https://github.com/microsoft/agent-framework/releases?q=tag%3Apython-1&expanded=true
|
|
27
|
+
Project-URL: source, https://github.com/microsoft/agent-framework/tree/main/python
|
|
28
|
+
|
|
29
|
+
# Get Started with Azure Content Understanding in Microsoft Agent Framework
|
|
30
|
+
|
|
31
|
+
Please install this package via pip:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install agent-framework-azure-contentunderstanding --pre
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Azure Content Understanding Integration
|
|
38
|
+
|
|
39
|
+
### Prerequisites
|
|
40
|
+
|
|
41
|
+
Before using this package, you need an Azure Content Understanding resource:
|
|
42
|
+
|
|
43
|
+
1. An active **Azure subscription** ([create one for free](https://azure.microsoft.com/pricing/purchase-options/azure-account))
|
|
44
|
+
2. A **Microsoft Foundry resource** created in a [supported region](https://learn.microsoft.com/azure/ai-services/content-understanding/language-region-support)
|
|
45
|
+
3. **Default model deployments** configured for your resource (GPT-4.1, GPT-4.1-mini, text-embedding-3-large)
|
|
46
|
+
|
|
47
|
+
Follow the [prerequisites section](https://learn.microsoft.com/azure/ai-services/content-understanding/quickstart/use-rest-api?tabs=portal%2Cdocument&pivots=programming-language-rest#prerequisites) in the Azure Content Understanding quickstart for setup instructions.
|
|
48
|
+
|
|
49
|
+
### Introduction
|
|
50
|
+
|
|
51
|
+
The Azure Content Understanding integration provides a context provider that automatically analyzes file attachments (documents, images, audio, video) using [Azure Content Understanding](https://learn.microsoft.com/azure/ai-services/content-understanding/) and injects structured results into the LLM context.
|
|
52
|
+
|
|
53
|
+
- **Document & image analysis**: State-of-the-art OCR with markdown extraction, table preservation, and structured field extraction — handles scanned PDFs, handwritten content, and complex layouts
|
|
54
|
+
- **Audio & video analysis**: Transcription, speaker diarization, and per-segment summaries
|
|
55
|
+
- **Background processing**: Configurable timeout with async background fallback for large files
|
|
56
|
+
- **file_search integration**: Optional vector store upload for token-efficient RAG on large documents
|
|
57
|
+
|
|
58
|
+
> Learn more about Azure Content Understanding capabilities at [https://learn.microsoft.com/azure/ai-services/content-understanding/](https://learn.microsoft.com/azure/ai-services/content-understanding/)
|
|
59
|
+
|
|
60
|
+
### Basic Usage Example
|
|
61
|
+
|
|
62
|
+
See the [samples directory](samples/) which demonstrates:
|
|
63
|
+
|
|
64
|
+
- Single PDF upload and Q&A ([01_document_qa](samples/01-get-started/01_document_qa.py))
|
|
65
|
+
- Multi-turn sessions with cached results ([02_multi_turn_session](samples/01-get-started/02_multi_turn_session.py))
|
|
66
|
+
- PDF + audio + video parallel analysis ([03_multimodal_chat](samples/01-get-started/03_multimodal_chat.py))
|
|
67
|
+
- Structured field extraction with prebuilt-invoice ([04_invoice_processing](samples/01-get-started/04_invoice_processing.py))
|
|
68
|
+
- CU extraction + OpenAI vector store RAG ([05_large_doc_file_search](samples/01-get-started/05_large_doc_file_search.py))
|
|
69
|
+
- Interactive web UI with DevUI ([02-devui](samples/02-devui/))
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
import asyncio
|
|
73
|
+
from agent_framework import Agent, AgentSession, Message, Content
|
|
74
|
+
from agent_framework.foundry import FoundryChatClient
|
|
75
|
+
from agent_framework.foundry import ContentUnderstandingContextProvider
|
|
76
|
+
from azure.identity import AzureCliCredential
|
|
77
|
+
|
|
78
|
+
credential = AzureCliCredential()
|
|
79
|
+
|
|
80
|
+
cu = ContentUnderstandingContextProvider(
|
|
81
|
+
endpoint="https://my-resource.cognitiveservices.azure.com/",
|
|
82
|
+
credential=credential,
|
|
83
|
+
max_wait=None, # block until CU extraction completes before sending to LLM
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
client = FoundryChatClient(
|
|
87
|
+
project_endpoint="https://your-project.services.ai.azure.com",
|
|
88
|
+
model="gpt-4.1",
|
|
89
|
+
credential=credential,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
async def main():
|
|
93
|
+
async with cu:
|
|
94
|
+
agent = Agent(
|
|
95
|
+
client=client,
|
|
96
|
+
name="DocumentQA",
|
|
97
|
+
instructions="You are a helpful document analyst.",
|
|
98
|
+
context_providers=[cu],
|
|
99
|
+
)
|
|
100
|
+
session = AgentSession()
|
|
101
|
+
|
|
102
|
+
response = await agent.run(
|
|
103
|
+
Message(role="user", contents=[
|
|
104
|
+
Content.from_text("What's on this invoice?"),
|
|
105
|
+
Content.from_uri(
|
|
106
|
+
"https://raw.githubusercontent.com/Azure-Samples/"
|
|
107
|
+
"azure-ai-content-understanding-assets/main/document/invoice.pdf",
|
|
108
|
+
media_type="application/pdf",
|
|
109
|
+
additional_properties={"filename": "invoice.pdf"},
|
|
110
|
+
),
|
|
111
|
+
]),
|
|
112
|
+
session=session,
|
|
113
|
+
)
|
|
114
|
+
print(response.text)
|
|
115
|
+
|
|
116
|
+
asyncio.run(main())
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Supported File Types
|
|
120
|
+
|
|
121
|
+
| Category | Types |
|
|
122
|
+
|----------|-------|
|
|
123
|
+
| Documents | PDF, DOCX, XLSX, PPTX, HTML, TXT, Markdown |
|
|
124
|
+
| Images | JPEG, PNG, TIFF, BMP |
|
|
125
|
+
| Audio | WAV, MP3, M4A, FLAC, OGG |
|
|
126
|
+
| Video | MP4, MOV, AVI, WebM |
|
|
127
|
+
|
|
128
|
+
For the complete list of supported file types and size limits, see [Azure Content Understanding service limits](https://learn.microsoft.com/azure/ai-services/content-understanding/service-limits#input-file-limits).
|
|
129
|
+
|
|
130
|
+
### Environment Variables
|
|
131
|
+
|
|
132
|
+
The provider supports automatic endpoint resolution from environment variables.
|
|
133
|
+
When ``endpoint`` is not passed to the constructor, it is loaded from
|
|
134
|
+
``AZURE_CONTENTUNDERSTANDING_ENDPOINT``:
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
# Endpoint auto-loaded from AZURE_CONTENTUNDERSTANDING_ENDPOINT env var
|
|
138
|
+
cu = ContentUnderstandingContextProvider(credential=credential)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Set these in your shell or in a `.env` file:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
AZURE_CONTENTUNDERSTANDING_ENDPOINT=https://your-cu-resource.cognitiveservices.azure.com/
|
|
145
|
+
AZURE_AI_PROJECT_ENDPOINT=https://your-project.services.ai.azure.com
|
|
146
|
+
AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4.1
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
You also need to be logged in with `az login` (for `AzureCliCredential`).
|
|
150
|
+
|
|
151
|
+
### Next steps
|
|
152
|
+
|
|
153
|
+
- Explore the [samples directory](samples/) for complete code examples
|
|
154
|
+
- Read the [Azure Content Understanding documentation](https://learn.microsoft.com/azure/ai-services/content-understanding/) for detailed service information
|
|
155
|
+
- Learn more about the [Microsoft Agent Framework](https://aka.ms/agent-framework)
|
|
156
|
+
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Get Started with Azure Content Understanding in Microsoft Agent Framework
|
|
2
|
+
|
|
3
|
+
Please install this package via pip:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install agent-framework-azure-contentunderstanding --pre
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Azure Content Understanding Integration
|
|
10
|
+
|
|
11
|
+
### Prerequisites
|
|
12
|
+
|
|
13
|
+
Before using this package, you need an Azure Content Understanding resource:
|
|
14
|
+
|
|
15
|
+
1. An active **Azure subscription** ([create one for free](https://azure.microsoft.com/pricing/purchase-options/azure-account))
|
|
16
|
+
2. A **Microsoft Foundry resource** created in a [supported region](https://learn.microsoft.com/azure/ai-services/content-understanding/language-region-support)
|
|
17
|
+
3. **Default model deployments** configured for your resource (GPT-4.1, GPT-4.1-mini, text-embedding-3-large)
|
|
18
|
+
|
|
19
|
+
Follow the [prerequisites section](https://learn.microsoft.com/azure/ai-services/content-understanding/quickstart/use-rest-api?tabs=portal%2Cdocument&pivots=programming-language-rest#prerequisites) in the Azure Content Understanding quickstart for setup instructions.
|
|
20
|
+
|
|
21
|
+
### Introduction
|
|
22
|
+
|
|
23
|
+
The Azure Content Understanding integration provides a context provider that automatically analyzes file attachments (documents, images, audio, video) using [Azure Content Understanding](https://learn.microsoft.com/azure/ai-services/content-understanding/) and injects structured results into the LLM context.
|
|
24
|
+
|
|
25
|
+
- **Document & image analysis**: State-of-the-art OCR with markdown extraction, table preservation, and structured field extraction — handles scanned PDFs, handwritten content, and complex layouts
|
|
26
|
+
- **Audio & video analysis**: Transcription, speaker diarization, and per-segment summaries
|
|
27
|
+
- **Background processing**: Configurable timeout with async background fallback for large files
|
|
28
|
+
- **file_search integration**: Optional vector store upload for token-efficient RAG on large documents
|
|
29
|
+
|
|
30
|
+
> Learn more about Azure Content Understanding capabilities at [https://learn.microsoft.com/azure/ai-services/content-understanding/](https://learn.microsoft.com/azure/ai-services/content-understanding/)
|
|
31
|
+
|
|
32
|
+
### Basic Usage Example
|
|
33
|
+
|
|
34
|
+
See the [samples directory](samples/) which demonstrates:
|
|
35
|
+
|
|
36
|
+
- Single PDF upload and Q&A ([01_document_qa](samples/01-get-started/01_document_qa.py))
|
|
37
|
+
- Multi-turn sessions with cached results ([02_multi_turn_session](samples/01-get-started/02_multi_turn_session.py))
|
|
38
|
+
- PDF + audio + video parallel analysis ([03_multimodal_chat](samples/01-get-started/03_multimodal_chat.py))
|
|
39
|
+
- Structured field extraction with prebuilt-invoice ([04_invoice_processing](samples/01-get-started/04_invoice_processing.py))
|
|
40
|
+
- CU extraction + OpenAI vector store RAG ([05_large_doc_file_search](samples/01-get-started/05_large_doc_file_search.py))
|
|
41
|
+
- Interactive web UI with DevUI ([02-devui](samples/02-devui/))
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
import asyncio
|
|
45
|
+
from agent_framework import Agent, AgentSession, Message, Content
|
|
46
|
+
from agent_framework.foundry import FoundryChatClient
|
|
47
|
+
from agent_framework.foundry import ContentUnderstandingContextProvider
|
|
48
|
+
from azure.identity import AzureCliCredential
|
|
49
|
+
|
|
50
|
+
credential = AzureCliCredential()
|
|
51
|
+
|
|
52
|
+
cu = ContentUnderstandingContextProvider(
|
|
53
|
+
endpoint="https://my-resource.cognitiveservices.azure.com/",
|
|
54
|
+
credential=credential,
|
|
55
|
+
max_wait=None, # block until CU extraction completes before sending to LLM
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
client = FoundryChatClient(
|
|
59
|
+
project_endpoint="https://your-project.services.ai.azure.com",
|
|
60
|
+
model="gpt-4.1",
|
|
61
|
+
credential=credential,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
async def main():
|
|
65
|
+
async with cu:
|
|
66
|
+
agent = Agent(
|
|
67
|
+
client=client,
|
|
68
|
+
name="DocumentQA",
|
|
69
|
+
instructions="You are a helpful document analyst.",
|
|
70
|
+
context_providers=[cu],
|
|
71
|
+
)
|
|
72
|
+
session = AgentSession()
|
|
73
|
+
|
|
74
|
+
response = await agent.run(
|
|
75
|
+
Message(role="user", contents=[
|
|
76
|
+
Content.from_text("What's on this invoice?"),
|
|
77
|
+
Content.from_uri(
|
|
78
|
+
"https://raw.githubusercontent.com/Azure-Samples/"
|
|
79
|
+
"azure-ai-content-understanding-assets/main/document/invoice.pdf",
|
|
80
|
+
media_type="application/pdf",
|
|
81
|
+
additional_properties={"filename": "invoice.pdf"},
|
|
82
|
+
),
|
|
83
|
+
]),
|
|
84
|
+
session=session,
|
|
85
|
+
)
|
|
86
|
+
print(response.text)
|
|
87
|
+
|
|
88
|
+
asyncio.run(main())
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Supported File Types
|
|
92
|
+
|
|
93
|
+
| Category | Types |
|
|
94
|
+
|----------|-------|
|
|
95
|
+
| Documents | PDF, DOCX, XLSX, PPTX, HTML, TXT, Markdown |
|
|
96
|
+
| Images | JPEG, PNG, TIFF, BMP |
|
|
97
|
+
| Audio | WAV, MP3, M4A, FLAC, OGG |
|
|
98
|
+
| Video | MP4, MOV, AVI, WebM |
|
|
99
|
+
|
|
100
|
+
For the complete list of supported file types and size limits, see [Azure Content Understanding service limits](https://learn.microsoft.com/azure/ai-services/content-understanding/service-limits#input-file-limits).
|
|
101
|
+
|
|
102
|
+
### Environment Variables
|
|
103
|
+
|
|
104
|
+
The provider supports automatic endpoint resolution from environment variables.
|
|
105
|
+
When ``endpoint`` is not passed to the constructor, it is loaded from
|
|
106
|
+
``AZURE_CONTENTUNDERSTANDING_ENDPOINT``:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
# Endpoint auto-loaded from AZURE_CONTENTUNDERSTANDING_ENDPOINT env var
|
|
110
|
+
cu = ContentUnderstandingContextProvider(credential=credential)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Set these in your shell or in a `.env` file:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
AZURE_CONTENTUNDERSTANDING_ENDPOINT=https://your-cu-resource.cognitiveservices.azure.com/
|
|
117
|
+
AZURE_AI_PROJECT_ENDPOINT=https://your-project.services.ai.azure.com
|
|
118
|
+
AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4.1
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
You also need to be logged in with `az login` (for `AzureCliCredential`).
|
|
122
|
+
|
|
123
|
+
### Next steps
|
|
124
|
+
|
|
125
|
+
- Explore the [samples directory](samples/) for complete code examples
|
|
126
|
+
- Read the [Azure Content Understanding documentation](https://learn.microsoft.com/azure/ai-services/content-understanding/) for detailed service information
|
|
127
|
+
- Learn more about the [Microsoft Agent Framework](https://aka.ms/agent-framework)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copyright (c) Microsoft. All rights reserved.
|
|
2
|
+
|
|
3
|
+
"""Azure Content Understanding integration for Microsoft Agent Framework.
|
|
4
|
+
|
|
5
|
+
Provides a context provider that analyzes file attachments (documents, images,
|
|
6
|
+
audio, video) using Azure Content Understanding and injects structured results
|
|
7
|
+
into the LLM context.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import importlib.metadata
|
|
11
|
+
|
|
12
|
+
from ._context_provider import ContentUnderstandingContextProvider
|
|
13
|
+
from ._file_search import FileSearchBackend
|
|
14
|
+
from ._models import AnalysisSection, DocumentStatus, FileSearchConfig
|
|
15
|
+
|
|
16
|
+
try:
|
|
17
|
+
__version__ = importlib.metadata.version(__name__)
|
|
18
|
+
except importlib.metadata.PackageNotFoundError:
|
|
19
|
+
__version__ = "0.0.0"
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"AnalysisSection",
|
|
23
|
+
"ContentUnderstandingContextProvider",
|
|
24
|
+
"DocumentStatus",
|
|
25
|
+
"FileSearchBackend",
|
|
26
|
+
"FileSearchConfig",
|
|
27
|
+
"__version__",
|
|
28
|
+
]
|