-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Python: Integrate azure-cosmos into core, lazy loading, and root samples #5044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,5 @@ | ||
| # Azure Cosmos DB Package Samples | ||
|
|
||
| This folder contains samples for `agent-framework-azure-cosmos`. | ||
| Samples for `agent-framework-azure-cosmos` have moved to the root samples directory: | ||
|
|
||
| | File | Description | | ||
| | --- | --- | | ||
| | [`cosmos_history_provider.py`](cosmos_history_provider.py) | Demonstrates an Agent using `CosmosHistoryProvider` with `FoundryChatClient` (configured against an Azure AI Foundry project endpoint), provider-configured container name, and `session_id` partitioning. | | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - `AZURE_COSMOS_ENDPOINT` | ||
| - `AZURE_COSMOS_DATABASE_NAME` | ||
| - `AZURE_COSMOS_CONTAINER_NAME` | ||
| - `AZURE_COSMOS_KEY` (or equivalent credential flow) | ||
|
|
||
| ## Run | ||
|
|
||
| ```bash | ||
| uv run --directory packages/azure-cosmos python samples/cosmos_history_provider.py | ||
| ``` | ||
| [`samples/02-agents/context_providers/azure_cosmos/`](../../../samples/02-agents/context_providers/azure_cosmos/) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| "AgentResponseCallbackProtocol": ("agent_framework_durabletask", "agent-framework-durabletask"), | ||
| "AzureAISearchContextProvider": ("agent_framework_azure_ai_search", "agent-framework-azure-ai-search"), | ||
| "AzureAISearchSettings": ("agent_framework_azure_ai_search", "agent-framework-azure-ai-search"), | ||
| "CosmosHistoryProvider": ("agent_framework_azure_cosmos", "agent-framework-azure-cosmos"), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is missing from the accompanying init.pyi |
||
| "AzureAISettings": ("agent_framework_azure_ai", "agent-framework-azure-ai"), | ||
|
giles17 marked this conversation as resolved.
|
||
| "AzureAIInferenceEmbeddingClient": ("agent_framework_azure_ai", "agent-framework-azure-ai"), | ||
| "AzureAIInferenceEmbeddingOptions": ("agent_framework_azure_ai", "agent-framework-azure-ai"), | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't exist |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| """Azure Cosmos DB integration namespace for optional Agent Framework connectors. | ||
|
|
||
| This module lazily re-exports objects from: | ||
| - ``agent-framework-azure-cosmos`` | ||
|
|
||
| Supported classes: | ||
| - CosmosHistoryProvider | ||
| """ | ||
|
|
||
| import importlib | ||
| from typing import Any | ||
|
|
||
| IMPORT_PATH = "agent_framework_azure_cosmos" | ||
| PACKAGE_NAME = "agent-framework-azure-cosmos" | ||
| _IMPORTS = ["CosmosHistoryProvider"] | ||
|
|
||
|
|
||
| def __getattr__(name: str) -> Any: | ||
| if name in _IMPORTS: | ||
| try: | ||
| return getattr(importlib.import_module(IMPORT_PATH), name) | ||
| except ModuleNotFoundError as exc: | ||
| raise ModuleNotFoundError( | ||
| f"The '{PACKAGE_NAME}' package is not installed, please do `pip install {PACKAGE_NAME}`" | ||
| ) from exc | ||
| raise AttributeError(f"Module {IMPORT_PATH} has no attribute {name}.") | ||
|
giles17 marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def __dir__() -> list[str]: | ||
| return _IMPORTS | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Azure Cosmos DB Context Provider Examples | ||
|
|
||
| The Azure Cosmos DB context provider enables persistent conversation history for your agents using Azure Cosmos DB. It uses `session_id` as the partition key for efficient multi-session support. | ||
|
|
||
| ## Examples | ||
|
|
||
| | File | Description | | ||
| |------|-------------| | ||
| | [`cosmos_history_provider.py`](cosmos_history_provider.py) | Demonstrates an Agent using `CosmosHistoryProvider` with `FoundryChatClient` (configured against an Azure AI Foundry project endpoint), provider-configured container name, and `session_id` partitioning. | | ||
|
|
||
|
giles17 marked this conversation as resolved.
|
||
| ## Prerequisites | ||
|
|
||
| ### Required resources | ||
|
|
||
| 1. An Azure Cosmos DB account with a database and container | ||
| 2. Python environment with Agent Framework Azure Cosmos extra installed | ||
| 3. Azure AI Foundry project endpoint and model deployment | ||
|
|
||
| ### Install the package | ||
|
|
||
| ```bash | ||
| pip install "agent-framework-azure-cosmos" | ||
|
giles17 marked this conversation as resolved.
|
||
| ``` | ||
|
|
||
| ### Environment variables | ||
|
|
||
| - `FOUNDRY_PROJECT_ENDPOINT` (required): Azure AI Foundry project endpoint | ||
| - `FOUNDRY_MODEL` (required): Foundry model deployment name | ||
| - `AZURE_COSMOS_ENDPOINT` (required): Azure Cosmos DB endpoint | ||
| - `AZURE_COSMOS_DATABASE_NAME` (required): Cosmos DB database name | ||
| - `AZURE_COSMOS_CONTAINER_NAME` (required): Cosmos DB container name | ||
| - `AZURE_COSMOS_KEY` (optional): Cosmos DB key (falls back to Azure CLI credential) | ||
|
|
||
| ## How to run | ||
|
|
||
| 1. Set the required environment variables: | ||
|
|
||
| ```bash | ||
| export FOUNDRY_PROJECT_ENDPOINT="https://<resource>.services.ai.azure.com/api/projects/<project>" | ||
| export FOUNDRY_MODEL="<deployment-name>" | ||
| export AZURE_COSMOS_ENDPOINT="https://<account>.documents.azure.com:443/" | ||
| export AZURE_COSMOS_DATABASE_NAME="<database>" | ||
| export AZURE_COSMOS_CONTAINER_NAME="<container>" | ||
| ``` | ||
|
|
||
| 2. Run the example: | ||
|
|
||
| ```bash | ||
| uv run python samples/02-agents/context_providers/azure_cosmos/cosmos_history_provider.py | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,11 @@ | |
| import asyncio | ||
| import os | ||
|
|
||
| from agent_framework.azure_cosmos import CosmosHistoryProvider | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be .azure |
||
| from agent_framework.foundry import FoundryChatClient | ||
| from azure.identity.aio import AzureCliCredential | ||
| from dotenv import load_dotenv | ||
|
|
||
| from agent_framework_azure_cosmos import CosmosHistoryProvider | ||
|
|
||
| # Load environment variables from .env file. | ||
| load_dotenv() | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in the azure namespace