diff --git a/libraries/microsoft-agents-activity/pyproject.toml b/libraries/microsoft-agents-activity/pyproject.toml index 049566d4..e97bea23 100644 --- a/libraries/microsoft-agents-activity/pyproject.toml +++ b/libraries/microsoft-agents-activity/pyproject.toml @@ -6,6 +6,7 @@ build-backend = "setuptools.build_meta" name = "microsoft-agents-activity" dynamic = ["version"] description = "A protocol library for Microsoft Agents" +readme = {file = "readme.md", content-type = "text/markdown"} authors = [{name = "Microsoft Corporation"}] license = "MIT" license-files = ["LICENSE"] diff --git a/libraries/microsoft-agents-activity/readme.md b/libraries/microsoft-agents-activity/readme.md new file mode 100644 index 00000000..393c582c --- /dev/null +++ b/libraries/microsoft-agents-activity/readme.md @@ -0,0 +1,135 @@ +# Microsoft Agents Activity + +[![PyPI version](https://img.shields.io/pypi/v/microsoft-agents-activity)](https://pypi.org/project/microsoft-agents-activity/) + +Core types and schemas for building conversational AI agents that work across Microsoft 365 platforms like Teams, Copilot Studio, and Webchat. + +# What is this? + +This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehensive framework for building enterprise-grade conversational AI agents. The SDK enables developers to create intelligent agents that work across multiple platforms including Microsoft Teams, M365 Copilot, Copilot Studio, and web chat, with support for third-party integrations like Slack, Facebook Messenger, and Twilio. + +## Packages Overview + +We offer the following PyPI packages to create conversational experiences based on Agents: + +| Package Name | PyPI Version | Description | +|--------------|-------------|-------------| +| `microsoft-agents-activity` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-activity)](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. | +| `microsoft-agents-hosting-core` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-core)](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. | +| `microsoft-agents-hosting-aiohttp` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-aiohttp)](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. | +| `microsoft-agents-hosting-teams` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-teams)](https://pypi.org/project/microsoft-agents-hosting-teams/) | Provides classes to host an Agent for Teams. | +| `microsoft-agents-storage-blob` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-blob)](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. | +| `microsoft-agents-storage-cosmos` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-cosmos)](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. | +| `microsoft-agents-authentication-msal` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-authentication-msal)](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. | + +Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio: + +| Package Name | PyPI Version | Description | +|--------------|-------------|-------------| +| `microsoft-agents-copilotstudio-client` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-copilotstudio-client)](https://pypi.org/project/microsoft-agents-copilotstudio-client/) | Direct to Engine client to interact with Agents created in CopilotStudio | + +## Architecture + +The SDK follows a modular architecture: +- **Activity Layer**: Protocol definitions for cross-platform messaging +- **Hosting Layer**: Core agent lifecycle, middleware, and web hosting +- **Storage Layer**: Persistent state management with Azure backends +- **Authentication Layer**: Secure identity and token management +- **Integration Layer**: Platform-specific adapters (Teams, Copilot Studio) + +## Installation + +```bash +pip install microsoft-agents-activity +``` + +## Quick Start +Code below taken from the [Quick Start](https://github.com/microsoft/Agents/tree/main/samples/python/quickstart) sample. +```python +@AGENT_APP.conversation_update("membersAdded") +async def on_members_added(context: TurnContext, _state: TurnState): + await context.send_activity( + "Welcome to the empty agent! " + "This agent is designed to be a starting point for your own agent development." + ) + return True + + +@AGENT_APP.message(re.compile(r"^hello$")) +async def on_hello(context: TurnContext, _state: TurnState): + await context.send_activity("Hello!") + + +@AGENT_APP.activity("message") +async def on_message(context: TurnContext, _state: TurnState): + await context.send_activity(f"you said: {context.activity.text}") +``` + +## Common Use Cases + +### Rich Messages with Cards +Code below taken from the [Cards](https://github.com/microsoft/Agents/tree/main/samples/python/cards) sample. + + +```python + @staticmethod + async def send_animation_card(context: TurnContext): + card = CardFactory.animation_card( + AnimationCard( + title="Microsoft Agents Framework", + image=ThumbnailUrl( + url="https://i.giphy.com/Ki55RUbOV5njy.gif", alt="Cute Robot" + ), + media=[MediaUrl(url="https://i.giphy.com/Ki55RUbOV5njy.gif")], + subtitle="Animation Card", + text="This is an example of an animation card using a gif.", + aspect="16:9", + duration="PT2M", + ) + ) + await CardMessages.send_activity(context, card) + + @staticmethod + async def send_activity(context: TurnContext, card: Attachment): + activity = Activity(type=ActivityTypes.message, attachments=[card]) + await context.send_activity(activity) +``` + +## Activity Types + +The library supports different types of communication: + +- **Message** - Regular chat messages with text, cards, attachments +- **Typing** - Show typing indicators +- **ConversationUpdate** - People joining/leaving chats +- **Event** - Custom events and notifications +- **Invoke** - Direct function calls +- **EndOfConversation** - End chat sessions + +## Key Features + +✅ **Type-safe** - Built with Pydantic for automatic validation +✅ **Rich content** - Support for cards, images, videos, and interactive elements +✅ **Teams ready** - Full Microsoft Teams integration +✅ **Cross-platform** - Works across all Microsoft 365 chat platforms +✅ **Migration friendly** - Easy upgrade from Bot Framework + +# Quick Links + +- 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents) +- 📖 [Complete Documentation](https://aka.ms/agents) +- 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python) +- 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues) + +# Sample Applications +Explore working examples in the [Python samples repository](https://github.com/microsoft/Agents/tree/main/samples/python): + +|Name|Description|README| +|----|----|----| +|Quickstart|Simplest agent|[Quickstart](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/README.md)| +|Auto Sign In|Simple OAuth agent using Graph and GitHub|[auto-signin](https://github.com/microsoft/Agents/blob/main/samples/python/auto-signin/README.md)| +|OBO Authorization|OBO flow to access a Copilot Studio Agent|[obo-authorization](https://github.com/microsoft/Agents/blob/main/samples/python/obo-authorization/README.md)| +|Semantic Kernel Integration|A weather agent built with Semantic Kernel|[semantic-kernel-multiturn](https://github.com/microsoft/Agents/blob/main/samples/python/semantic-kernel-multiturn/README.md)| +|Streaming Agent|Streams OpenAI responses|[azure-ai-streaming](https://github.com/microsoft/Agents/blob/main/samples/python/azureai-streaming/README.md)| +|Copilot Studio Client|Console app to consume a Copilot Studio Agent|[copilotstudio-client](https://github.com/microsoft/Agents/blob/main/samples/python/copilotstudio-client/README.md)| +|Cards Agent|Agent that uses rich cards to enhance conversation design |[cards](https://github.com/microsoft/Agents/blob/main/samples/python/cards/README.md)| \ No newline at end of file diff --git a/libraries/microsoft-agents-authentication-msal/pyproject.toml b/libraries/microsoft-agents-authentication-msal/pyproject.toml index 33104f43..dd0ab327 100644 --- a/libraries/microsoft-agents-authentication-msal/pyproject.toml +++ b/libraries/microsoft-agents-authentication-msal/pyproject.toml @@ -6,6 +6,7 @@ build-backend = "setuptools.build_meta" name = "microsoft-agents-authentication-msal" dynamic = ["version", "dependencies"] description = "A msal-based authentication library for Microsoft Agents" +readme = {file = "readme.md", content-type = "text/markdown"} authors = [{name = "Microsoft Corporation"}] license = "MIT" license-files = ["LICENSE"] diff --git a/libraries/microsoft-agents-authentication-msal/readme.md b/libraries/microsoft-agents-authentication-msal/readme.md new file mode 100644 index 00000000..6fce36ab --- /dev/null +++ b/libraries/microsoft-agents-authentication-msal/readme.md @@ -0,0 +1,115 @@ +# Microsoft Agents MSAL Authentication + +[![PyPI version](https://img.shields.io/pypi/v/microsoft-agents-authentication-msal)](https://pypi.org/project/microsoft-agents-authentication-msal/) + +Provides secure authentication for your agents using Microsoft Authentication Library (MSAL). It handles getting tokens from Azure AD so your agent can securely communicate with Microsoft services like Teams, Graph API, and other Azure resources. + +# What is this? + +This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehensive framework for building enterprise-grade conversational AI agents. The SDK enables developers to create intelligent agents that work across multiple platforms including Microsoft Teams, M365 Copilot, Copilot Studio, and web chat, with support for third-party integrations like Slack, Facebook Messenger, and Twilio. + +## Packages Overview + +We offer the following PyPI packages to create conversational experiences based on Agents: + +| Package Name | PyPI Version | Description | +|--------------|-------------|-------------| +| `microsoft-agents-activity` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-activity)](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. | +| `microsoft-agents-hosting-core` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-core)](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. | +| `microsoft-agents-hosting-aiohttp` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-aiohttp)](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. | +| `microsoft-agents-hosting-teams` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-teams)](https://pypi.org/project/microsoft-agents-hosting-teams/) | Provides classes to host an Agent for Teams. | +| `microsoft-agents-storage-blob` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-blob)](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. | +| `microsoft-agents-storage-cosmos` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-cosmos)](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. | +| `microsoft-agents-authentication-msal` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-authentication-msal)](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. | + +Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio: + +| Package Name | PyPI Version | Description | +|--------------|-------------|-------------| +| `microsoft-agents-copilotstudio-client` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-copilotstudio-client)](https://pypi.org/project/microsoft-agents-copilotstudio-client/) | Direct to Engine client to interact with Agents created in CopilotStudio | + +## Installation + +```bash +pip install microsoft-agents-authentication-msal +``` + +## Quick Start + +### Basic Setup with Client Secret + +Define your client secrets in the ENV file +```python +CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTID=client-id +CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTSECRET=client-secret +CONNECTIONS__SERVICE_CONNECTION__SETTINGS__TENANTID=tenant-id +``` + +Load the Configuration (Code from [main.py Quickstart Sample](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/src/main.py)) + +```python +from .start_server import start_server + +start_server( + agent_application=AGENT_APP, + auth_configuration=CONNECTION_MANAGER.get_default_connection_configuration(), +) +``` +Then start the Agent (code snipped from (start_server.py Quickstart Sample](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/src/start_server.py)): + +```python +def start_server( + agent_application: AgentApplication, auth_configuration: AgentAuthConfiguration +): + async def entry_point(req: Request) -> Response: + agent: AgentApplication = req.app["agent_app"] + adapter: CloudAdapter = req.app["adapter"] + return await start_agent_process( + req, + agent, + adapter, + ) +[...] +``` + +## Authentication Types +The M365 Agents SDK in Python supports the following Auth types: +```python +class AuthTypes(str, Enum): + certificate = "certificate" + certificate_subject_name = "CertificateSubjectName" + client_secret = "ClientSecret" + user_managed_identity = "UserManagedIdentity" + system_managed_identity = "SystemManagedIdentity" +``` + +## Key Classes + +- **`MsalAuth`** - Core authentication provider using MSAL +- **`MsalConnectionManager`** - Manages multiple authentication connections + +## Features + +✅ **Multiple auth types** - Client secret, certificate, managed identity +✅ **Token caching** - Automatic token refresh and caching +✅ **Multi-tenant** - Support for different Azure AD tenants +✅ **Agent-to-agent** - Secure communication between agents +✅ **On-behalf-of** - Act on behalf of users + +# Security Best Practices + +- Store secrets in Azure Key Vault or environment variables +- Use managed identities when possible (no secrets to manage) +- Regularly rotate client secrets and certificates +- Use least-privilege principle for scopes and permissions + +# Quick Links + +- 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents) +- 📖 [Complete Documentation](https://aka.ms/agents) +- 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python) +- 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues) + +# Sample Applications + +w \ No newline at end of file diff --git a/libraries/microsoft-agents-copilotstudio-client/pyproject.toml b/libraries/microsoft-agents-copilotstudio-client/pyproject.toml index 79b03268..1509b964 100644 --- a/libraries/microsoft-agents-copilotstudio-client/pyproject.toml +++ b/libraries/microsoft-agents-copilotstudio-client/pyproject.toml @@ -6,6 +6,7 @@ build-backend = "setuptools.build_meta" name = "microsoft-agents-copilotstudio-client" dynamic = ["version", "dependencies"] description = "A client library for Microsoft Agents" +readme = {file = "readme.md", content-type = "text/markdown"} authors = [{name = "Microsoft Corporation"}] license = "MIT" license-files = ["LICENSE"] diff --git a/libraries/microsoft-agents-copilotstudio-client/readme.md b/libraries/microsoft-agents-copilotstudio-client/readme.md new file mode 100644 index 00000000..1ce21edf --- /dev/null +++ b/libraries/microsoft-agents-copilotstudio-client/readme.md @@ -0,0 +1,145 @@ +# Microsoft Agents Copilot Studio Client + +[![PyPI version](https://img.shields.io/pypi/v/microsoft-agents-copilotstudio-client)](https://pypi.org/project/microsoft-agents-copilotstudio-client/) + +The Copilot Studio Client is for connecting to and interacting with agents created in Microsoft Copilot Studio. This library allows you to integrate Copilot Studio agents into your Python applications. + +This client library provides a direct connection to Copilot Studio agents, bypassing traditional chat channels. It's perfect for integrating AI conversations into your applications, building custom UIs, or creating agent-to-agent communication flows. + +# What is this? +This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehensive framework for building enterprise-grade conversational AI agents. The SDK enables developers to create intelligent agents that work across multiple platforms including Microsoft Teams, M365 Copilot, Copilot Studio, and web chat, with support for third-party integrations like Slack, Facebook Messenger, and Twilio. + +## Packages Overview + +We offer the following PyPI packages to create conversational experiences based on Agents: + +| Package Name | PyPI Version | Description | +|--------------|-------------|-------------| +| `microsoft-agents-activity` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-activity)](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. | +| `microsoft-agents-hosting-core` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-core)](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. | +| `microsoft-agents-hosting-aiohttp` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-aiohttp)](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. | +| `microsoft-agents-hosting-teams` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-teams)](https://pypi.org/project/microsoft-agents-hosting-teams/) | Provides classes to host an Agent for Teams. | +| `microsoft-agents-storage-blob` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-blob)](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. | +| `microsoft-agents-storage-cosmos` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-cosmos)](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. | +| `microsoft-agents-authentication-msal` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-authentication-msal)](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. | + +Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio: + +| Package Name | PyPI Version | Description | +|--------------|-------------|-------------| +| `microsoft-agents-copilotstudio-client` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-copilotstudio-client)](https://pypi.org/project/microsoft-agents-copilotstudio-client/) | Direct to Engine client to interact with Agents created in CopilotStudio | + + +## Installation + +```bash +pip install microsoft-agents-copilotstudio-client +``` + +## Quick Start + +### Basic Setup + +Code below from the [main.py in the Copilot Studio Client](https://github.com/microsoft/Agents/blob/main/samples/python/copilotstudio-client/src/main.py) +```python +def create_client(): + settings = ConnectionSettings( + environment_id=environ.get("COPILOTSTUDIOAGENT__ENVIRONMENTID"), + agent_identifier=environ.get("COPILOTSTUDIOAGENT__SCHEMANAME"), + cloud=None, + copilot_agent_type=None, + custom_power_platform_cloud=None, + ) + token = acquire_token( + settings, + app_client_id=environ.get("COPILOTSTUDIOAGENT__AGENTAPPID"), + tenant_id=environ.get("COPILOTSTUDIOAGENT__TENANTID"), + ) + copilot_client = CopilotClient(settings, token) + return copilot_client +``` + +### Start a Conversation +The code below is summarized from the [main.py in the Copilot Studio Client](https://github.com/microsoft/Agents/blob/main/samples/python/copilotstudio-client/src/main.py). See that sample for complete & working code. + +```python + copilot_client = create_client() + act = copilot_client.start_conversation(True) + + ... + + replies = copilot_client.ask_question("Who are you?", conversation_id) + async for reply in replies: + if reply.type == ActivityTypes.message: + print(f"\n{reply.text}") +``` + +### Environment Variables +Set up your `.env` file: + +```bash +# Required +ENVIRONMENT_ID=your-power-platform-environment-id +AGENT_IDENTIFIER=your-copilot-studio-agent-id +APP_CLIENT_ID=your-azure-app-client-id +TENANT_ID=your-azure-tenant-id + +# Optional +CLOUD=PROD +COPILOT_AGENT_TYPE=PUBLISHED +CUSTOM_POWER_PLATFORM_CLOUD=your-custom-cloud.com +``` + +## Features + +✅ **Real-time streaming** - Server-sent events for live responses +✅ **Multi-cloud support** - Works across all Power Platform clouds +✅ **Rich content** - Support for cards, actions, and attachments +✅ **Conversation management** - Maintain context across interactions +✅ **Custom activities** - Send structured data to agents +✅ **Async/await** - Modern Python async support + +## Troubleshooting + +### Common Issues + +**Authentication failed** +- Verify your app is registered in Azure AD +- Check that token has `https://api.powerplatform.com/.default` scope +- Ensure your app has permissions to the Power Platform environment + +**Agent not found** +- Verify the environment ID and agent identifier +- Check that the agent is published and accessible +- Confirm you're using the correct cloud setting + +**Connection timeout** +- Check network connectivity to Power Platform +- Verify firewall settings allow HTTPS traffic +- Try a different cloud region if available + +## Requirements + +- Python 3.9+ +- Valid Azure AD app registration +- Access to Microsoft Power Platform environment +- Published Copilot Studio agent + +# Quick Links + +- 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents) +- 📖 [Complete Documentation](https://aka.ms/agents) +- 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python) +- 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues) + +# Sample Applications + +|Name|Description|README| +|----|----|----| +|Quickstart|Simplest agent|[Quickstart](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/README.md)| +|Auto Sign In|Simple OAuth agent using Graph and GitHub|[auto-signin](https://github.com/microsoft/Agents/blob/main/samples/python/auto-signin/README.md)| +|OBO Authorization|OBO flow to access a Copilot Studio Agent|[obo-authorization](https://github.com/microsoft/Agents/blob/main/samples/python/obo-authorization/README.md)| +|Semantic Kernel Integration|A weather agent built with Semantic Kernel|[semantic-kernel-multiturn](https://github.com/microsoft/Agents/blob/main/samples/python/semantic-kernel-multiturn/README.md)| +|Streaming Agent|Streams OpenAI responses|[azure-ai-streaming](https://github.com/microsoft/Agents/blob/main/samples/python/azureai-streaming/README.md)| +|Copilot Studio Client|Console app to consume a Copilot Studio Agent|[copilotstudio-client](https://github.com/microsoft/Agents/blob/main/samples/python/copilotstudio-client/README.md)| +|Cards Agent|Agent that uses rich cards to enhance conversation design |[cards](https://github.com/microsoft/Agents/blob/main/samples/python/cards/README.md)| \ No newline at end of file diff --git a/libraries/microsoft-agents-hosting-aiohttp/pyproject.toml b/libraries/microsoft-agents-hosting-aiohttp/pyproject.toml index a6943058..22013a7f 100644 --- a/libraries/microsoft-agents-hosting-aiohttp/pyproject.toml +++ b/libraries/microsoft-agents-hosting-aiohttp/pyproject.toml @@ -6,6 +6,7 @@ build-backend = "setuptools.build_meta" name = "microsoft-agents-hosting-aiohttp" dynamic = ["version", "dependencies"] description = "Integration library for Microsoft Agents with aiohttp" +readme = {file = "readme.md", content-type = "text/markdown"} authors = [{name = "Microsoft Corporation"}] license = "MIT" license-files = ["LICENSE"] diff --git a/libraries/microsoft-agents-hosting-aiohttp/readme.md b/libraries/microsoft-agents-hosting-aiohttp/readme.md new file mode 100644 index 00000000..2d397e4c --- /dev/null +++ b/libraries/microsoft-agents-hosting-aiohttp/readme.md @@ -0,0 +1,122 @@ +# Microsoft Agents Hosting - aiohttp + +[![PyPI version](https://img.shields.io/pypi/v/microsoft-agents-hosting-aiohttp)](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) + +Integration library for hosting Microsoft 365 Agents using aiohttp. This library provides HTTP adapters, middleware, and utilities for building web-based agent applications with the popular aiohttp framework. + +This library bridges the Microsoft 365 Agents SDK with aiohttp, allowing you to create HTTP endpoints that handle agent conversations. It provides everything you need to host agents as web services, including request processing, authentication, and routing. + +# What is this? + +This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehensive framework for building enterprise-grade conversational AI agents. The SDK enables developers to create intelligent agents that work across multiple platforms including Microsoft Teams, M365 Copilot, Copilot Studio, and web chat, with support for third-party integrations like Slack, Facebook Messenger, and Twilio. + +## Packages Overview + +We offer the following PyPI packages to create conversational experiences based on Agents: + +| Package Name | PyPI Version | Description | +|--------------|-------------|-------------| +| `microsoft-agents-activity` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-activity)](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. | +| `microsoft-agents-hosting-core` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-core)](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. | +| `microsoft-agents-hosting-aiohttp` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-aiohttp)](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. | +| `microsoft-agents-hosting-teams` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-teams)](https://pypi.org/project/microsoft-agents-hosting-teams/) | Provides classes to host an Agent for Teams. | +| `microsoft-agents-storage-blob` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-blob)](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. | +| `microsoft-agents-storage-cosmos` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-cosmos)](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. | +| `microsoft-agents-authentication-msal` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-authentication-msal)](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. | + +Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio: + +| Package Name | PyPI Version | Description | +|--------------|-------------|-------------| +| `microsoft-agents-copilotstudio-client` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-copilotstudio-client)](https://pypi.org/project/microsoft-agents-copilotstudio-client/) | Direct to Engine client to interact with Agents created in CopilotStudio | + +## Installation + +```bash +pip install microsoft-agents-hosting-aiohttp +``` + +## Simple Echo Agent +See the [Quickstart sample](https://github.com/microsoft/Agents/tree/main/samples/python/quickstart) for full working code. + +```python +agents_sdk_config = load_configuration_from_env(environ) + +STORAGE = MemoryStorage() +CONNECTION_MANAGER = MsalConnectionManager(**agents_sdk_config) +ADAPTER = CloudAdapter(connection_manager=CONNECTION_MANAGER) +AUTHORIZATION = Authorization(STORAGE, CONNECTION_MANAGER, **agents_sdk_config) + +AGENT_APP = AgentApplication[TurnState]( + storage=STORAGE, adapter=ADAPTER, authorization=AUTHORIZATION, **agents_sdk_config +) + +@AGENT_APP.activity("message") +async def on_message(context: TurnContext, state: TurnState): + await context.send_activity(f"You said: {context.activity.text}") + +... + +start_server( + agent_application=AGENT_APP, + auth_configuration=CONNECTION_MANAGER.get_default_connection_configuration(), +) +``` + + +### Error Handling + +Customize error responses. Code take from the [Quickstart sample](https://github.com/microsoft/Agents/tree/main/samples/python/quickstart). + +```python +@AGENT_APP.error +async def on_error(context: TurnContext, error: Exception): + # This check writes out errors to console log + # NOTE: In production environment, you should consider logging this to Azure + # application insights. + print(f"\n [on_turn_error] unhandled error: {error}", file=sys.stderr) + traceback.print_exc() + + # Send a message to the user + await context.send_activity("The bot encountered an error or bug.") +``` + +## Features + +✅ **HTTP hosting** - Full aiohttp integration for web hosting +✅ **JWT authentication** - Built-in security with middleware +✅ **Agent-to-agent** - Support for multi-agent communication +✅ **Streaming** - Real-time response streaming +✅ **Error handling** - Comprehensive error management +✅ **Development friendly** - Hot reload and debugging support + +## Requirements + +- Python 3.9+ +- aiohttp 3.11.11+ +- Microsoft Agents hosting core library + +## Best Practices + +1. **Use middleware** for cross-cutting concerns like auth and logging +2. **Handle errors gracefully** with custom error handlers +3. **Secure your endpoints** with JWT middleware in production +4. **Structure routes** logically for agent communication + +# Quick Links + +- 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents) +- 📖 [Complete Documentation](https://aka.ms/agents) +- 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python) +- 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues) + +# Sample Applications +|Name|Description|README| +|----|----|----| +|Quickstart|Simplest agent|[Quickstart](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/README.md)| +|Auto Sign In|Simple OAuth agent using Graph and GitHub|[auto-signin](https://github.com/microsoft/Agents/blob/main/samples/python/auto-signin/README.md)| +|OBO Authorization|OBO flow to access a Copilot Studio Agent|[obo-authorization](https://github.com/microsoft/Agents/blob/main/samples/python/obo-authorization/README.md)| +|Semantic Kernel Integration|A weather agent built with Semantic Kernel|[semantic-kernel-multiturn](https://github.com/microsoft/Agents/blob/main/samples/python/semantic-kernel-multiturn/README.md)| +|Streaming Agent|Streams OpenAI responses|[azure-ai-streaming](https://github.com/microsoft/Agents/blob/main/samples/python/azureai-streaming/README.md)| +|Copilot Studio Client|Console app to consume a Copilot Studio Agent|[copilotstudio-client](https://github.com/microsoft/Agents/blob/main/samples/python/copilotstudio-client/README.md)| +|Cards Agent|Agent that uses rich cards to enhance conversation design |[cards](https://github.com/microsoft/Agents/blob/main/samples/python/cards/README.md)| \ No newline at end of file diff --git a/libraries/microsoft-agents-hosting-core/pyproject.toml b/libraries/microsoft-agents-hosting-core/pyproject.toml index 011dfc0d..20bb2202 100644 --- a/libraries/microsoft-agents-hosting-core/pyproject.toml +++ b/libraries/microsoft-agents-hosting-core/pyproject.toml @@ -6,6 +6,7 @@ build-backend = "setuptools.build_meta" name = "microsoft-agents-hosting-core" dynamic = ["version", "dependencies"] description = "Core library for Microsoft Agents" +readme = {file = "readme.md", content-type = "text/markdown"} authors = [{name = "Microsoft Corporation"}] license = "MIT" license-files = ["LICENSE"] diff --git a/libraries/microsoft-agents-hosting-core/readme.md b/libraries/microsoft-agents-hosting-core/readme.md new file mode 100644 index 00000000..86730baa --- /dev/null +++ b/libraries/microsoft-agents-hosting-core/readme.md @@ -0,0 +1,148 @@ +# Microsoft Agents Hosting Core + +[![PyPI version](https://img.shields.io/pypi/v/microsoft-agents-hosting-core)](https://pypi.org/project/microsoft-agents-hosting-core/) + +The core hosting library for Microsoft 365 Agents SDK. This library provides the fundamental building blocks for creating conversational AI agents, including activity processing, state management, authentication, and channel communication. + +This is the heart of the Microsoft 365 Agents SDK - think of it as the engine that powers your conversational agents. It handles the complex orchestration of conversations, manages state across turns, and provides the infrastructure needed to build production-ready agents that work across Microsoft 365 platforms. + +# What is this? +This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehensive framework for building enterprise-grade conversational AI agents. The SDK enables developers to create intelligent agents that work across multiple platforms including Microsoft Teams, M365 Copilot, Copilot Studio, and web chat, with support for third-party integrations like Slack, Facebook Messenger, and Twilio. + +## Packages Overview + +We offer the following PyPI packages to create conversational experiences based on Agents: + +| Package Name | PyPI Version | Description | +|--------------|-------------|-------------| +| `microsoft-agents-activity` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-activity)](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. | +| `microsoft-agents-hosting-core` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-core)](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. | +| `microsoft-agents-hosting-aiohttp` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-aiohttp)](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. | +| `microsoft-agents-hosting-teams` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-teams)](https://pypi.org/project/microsoft-agents-hosting-teams/) | Provides classes to host an Agent for Teams. | +| `microsoft-agents-storage-blob` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-blob)](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. | +| `microsoft-agents-storage-cosmos` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-cosmos)](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. | +| `microsoft-agents-authentication-msal` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-authentication-msal)](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. | + +Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio: + +| Package Name | PyPI Version | Description | +|--------------|-------------|-------------| +| `microsoft-agents-copilotstudio-client` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-copilotstudio-client)](https://pypi.org/project/microsoft-agents-copilotstudio-client/) | Direct to Engine client to interact with Agents created in CopilotStudio | + + +## Installation + +```bash +pip install microsoft-agents-hosting-core +``` +## Simple Echo Agent +See the [Quickstart sample](https://github.com/microsoft/Agents/tree/main/samples/python/quickstart) for full working code. + +```python +agents_sdk_config = load_configuration_from_env(environ) + +STORAGE = MemoryStorage() +CONNECTION_MANAGER = MsalConnectionManager(**agents_sdk_config) +ADAPTER = CloudAdapter(connection_manager=CONNECTION_MANAGER) +AUTHORIZATION = Authorization(STORAGE, CONNECTION_MANAGER, **agents_sdk_config) + +AGENT_APP = AgentApplication[TurnState]( + storage=STORAGE, adapter=ADAPTER, authorization=AUTHORIZATION, **agents_sdk_config +) + +@AGENT_APP.activity("message") +async def on_message(context: TurnContext, state: TurnState): + await context.send_activity(f"You said: {context.activity.text}") + +... + +start_server( + agent_application=AGENT_APP, + auth_configuration=CONNECTION_MANAGER.get_default_connection_configuration(), +) +``` + +## Core Concepts + +### AgentApplication vs ActivityHandler + +**AgentApplication** - Modern, fluent API for building agents: +- Decorator-based routing (`@agent_app.activity("message")`) +- Built-in state management and middleware +- AI-ready with authorization support +- Type-safe with generics + +**ActivityHandler** - Traditional inheritance-based approach: +- Override methods for different activity types +- More familiar to Bot Framework developers +- Lower-level control over activity processing + +### Route-based Message Handling + +```python +@AGENT_APP.message(re.compile(r"^hello$")) +async def on_hello(context: TurnContext, _state: TurnState): + await context.send_activity("Hello!") + + +@AGENT_APP.activity("message") +async def on_message(context: TurnContext, _state: TurnState): + await context.send_activity(f"you said: {context.activity.text}") +``` + +### Error Handling + +```python +@AGENT_APP.error +async def on_error(context: TurnContext, error: Exception): + # NOTE: In production environment, you should consider logging this to Azure + # application insights. + print(f"\n [on_turn_error] unhandled error: {error}", file=sys.stderr) + traceback.print_exc() + + # Send a message to the user + await context.send_activity("The bot encountered an error or bug.") +``` + + +## Key Classes Reference + +### Core Classes +- **`AgentApplication`** - Main application class with fluent API +- **`ActivityHandler`** - Base class for inheritance-based agents +- **`TurnContext`** - Context for each conversation turn +- **`TurnState`** - State management across conversation turns + +### State Management +- **`ConversationState`** - Conversation-scoped state +- **`UserState`** - User-scoped state across conversations +- **`TempState`** - Temporary state for current turn +- **`MemoryStorage`** - In-memory storage (development) + +### Messaging +- **`MessageFactory`** - Create different types of messages +- **`CardFactory`** - Create rich card attachments +- **`InputFile`** - Handle file attachments + +### Authorization +- **`Authorization`** - Authentication and authorization manager +- **`ClaimsIdentity`** - User identity and claims + +# Quick Links + +- 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents) +- 📖 [Complete Documentation](https://aka.ms/agents) +- 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python) +- 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues) + +# Sample Applications + +|Name|Description|README| +|----|----|----| +|Quickstart|Simplest agent|[Quickstart](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/README.md)| +|Auto Sign In|Simple OAuth agent using Graph and GitHub|[auto-signin](https://github.com/microsoft/Agents/blob/main/samples/python/auto-signin/README.md)| +|OBO Authorization|OBO flow to access a Copilot Studio Agent|[obo-authorization](https://github.com/microsoft/Agents/blob/main/samples/python/obo-authorization/README.md)| +|Semantic Kernel Integration|A weather agent built with Semantic Kernel|[semantic-kernel-multiturn](https://github.com/microsoft/Agents/blob/main/samples/python/semantic-kernel-multiturn/README.md)| +|Streaming Agent|Streams OpenAI responses|[azure-ai-streaming](https://github.com/microsoft/Agents/blob/main/samples/python/azureai-streaming/README.md)| +|Copilot Studio Client|Console app to consume a Copilot Studio Agent|[copilotstudio-client](https://github.com/microsoft/Agents/blob/main/samples/python/copilotstudio-client/README.md)| +|Cards Agent|Agent that uses rich cards to enhance conversation design |[cards](https://github.com/microsoft/Agents/blob/main/samples/python/cards/README.md)| \ No newline at end of file diff --git a/libraries/microsoft-agents-hosting-teams/pyproject.toml b/libraries/microsoft-agents-hosting-teams/pyproject.toml index b3dcc534..401b15ee 100644 --- a/libraries/microsoft-agents-hosting-teams/pyproject.toml +++ b/libraries/microsoft-agents-hosting-teams/pyproject.toml @@ -6,6 +6,7 @@ build-backend = "setuptools.build_meta" name = "microsoft-agents-hosting-teams" dynamic = ["version", "dependencies"] description = "Integration library for Microsoft Agents with Teams" +readme = {file = "readme.md", content-type = "text/markdown"} authors = [{name = "Microsoft Corporation"}] license = "MIT" license-files = ["LICENSE"] diff --git a/libraries/microsoft-agents-hosting-teams/readme.md b/libraries/microsoft-agents-hosting-teams/readme.md new file mode 100644 index 00000000..9ff2e5ab --- /dev/null +++ b/libraries/microsoft-agents-hosting-teams/readme.md @@ -0,0 +1,87 @@ +# Microsoft Agents Hosting - Teams + +[![PyPI version](https://img.shields.io/pypi/v/microsoft-agents-hosting-teams)](https://pypi.org/project/microsoft-agents-hosting-teams/) + +Integration library for building Microsoft Teams agents using the Microsoft 365 Agents SDK. This library provides specialized handlers and utilities for Teams-specific functionality like messaging extensions, task modules, adaptive cards, and meeting events. + +This library extends the core hosting capabilities with Teams-specific features. It handles Teams' unique interaction patterns like messaging extensions, tab applications, task modules, and meeting integrations. Think of it as the bridge that makes your agent "Teams-native" rather than just a generic chatbot. + +This library is still in flux, as the interfaces to Teams continue to evolve. + +# What is this? +This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehensive framework for building enterprise-grade conversational AI agents. The SDK enables developers to create intelligent agents that work across multiple platforms including Microsoft Teams, M365 Copilot, Copilot Studio, and web chat, with support for third-party integrations like Slack, Facebook Messenger, and Twilio. + +## Packages Overview + +We offer the following PyPI packages to create conversational experiences based on Agents: + +| Package Name | PyPI Version | Description | +|--------------|-------------|-------------| +| `microsoft-agents-activity` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-activity)](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. | +| `microsoft-agents-hosting-core` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-core)](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. | +| `microsoft-agents-hosting-aiohttp` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-aiohttp)](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. | +| `microsoft-agents-hosting-teams` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-teams)](https://pypi.org/project/microsoft-agents-hosting-teams/) | Provides classes to host an Agent for Teams. | +| `microsoft-agents-storage-blob` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-blob)](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. | +| `microsoft-agents-storage-cosmos` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-cosmos)](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. | +| `microsoft-agents-authentication-msal` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-authentication-msal)](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. | + +Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio: + +| Package Name | PyPI Version | Description | +|--------------|-------------|-------------| +| `microsoft-agents-copilotstudio-client` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-copilotstudio-client)](https://pypi.org/project/microsoft-agents-copilotstudio-client/) | Direct to Engine client to interact with Agents created in CopilotStudio | + + +## Installation + +```bash +pip install microsoft-agents-hosting-teams +``` + +## Key Classes Reference + +- **`TeamsActivityHandler`** - Main handler class with Teams-specific event methods +- **`TeamsInfo`** - Utility class for Teams operations (members, meetings, channels) +- **`MessagingExtensionQuery/Response`** - Handle search and messaging extensions +- **`TaskModuleRequest/Response`** - Interactive dialogs and forms +- **`TabRequest/Response`** - Tab application interactions + +## Features Supported + +✅ **Messaging Extensions** - Search and action-based extensions +✅ **Task Modules** - Interactive dialogs and forms +✅ **Adaptive Cards** - Rich card interactions +✅ **Meeting Events** - Start, end, participant changes +✅ **Team Management** - Member operations, channel messaging +✅ **File Handling** - Upload/download with consent flow +✅ **Tab Apps** - Personal and team tab interactions +✅ **Proactive Messaging** - Send messages to channels/users + +## Migration from Bot Framework + +| Bot Framework Teams | Microsoft Agents Teams | +|-------------------|------------------------| +| `TeamsActivityHandler` | `TeamsActivityHandler` | +| `TeamsInfo` | `TeamsInfo` | +| `on_teams_members_added` | `on_teams_members_added_activity` | +| `MessagingExtensionQuery` | `MessagingExtensionQuery` | +| `TaskModuleRequest` | `TaskModuleRequest` | + +# Quick Links + +- 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents) +- 📖 [Complete Documentation](https://aka.ms/agents) +- 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python) +- 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues) + +# Sample Applications + +|Name|Description|README| +|----|----|----| +|Quickstart|Simplest agent|[Quickstart](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/README.md)| +|Auto Sign In|Simple OAuth agent using Graph and GitHub|[auto-signin](https://github.com/microsoft/Agents/blob/main/samples/python/auto-signin/README.md)| +|OBO Authorization|OBO flow to access a Copilot Studio Agent|[obo-authorization](https://github.com/microsoft/Agents/blob/main/samples/python/obo-authorization/README.md)| +|Semantic Kernel Integration|A weather agent built with Semantic Kernel|[semantic-kernel-multiturn](https://github.com/microsoft/Agents/blob/main/samples/python/semantic-kernel-multiturn/README.md)| +|Streaming Agent|Streams OpenAI responses|[azure-ai-streaming](https://github.com/microsoft/Agents/blob/main/samples/python/azureai-streaming/README.md)| +|Copilot Studio Client|Console app to consume a Copilot Studio Agent|[copilotstudio-client](https://github.com/microsoft/Agents/blob/main/samples/python/copilotstudio-client/README.md)| +|Cards Agent|Agent that uses rich cards to enhance conversation design |[cards](https://github.com/microsoft/Agents/blob/main/samples/python/cards/README.md)| \ No newline at end of file diff --git a/libraries/microsoft-agents-storage-blob/pyproject.toml b/libraries/microsoft-agents-storage-blob/pyproject.toml index 09f2fa4f..1b1be7d7 100644 --- a/libraries/microsoft-agents-storage-blob/pyproject.toml +++ b/libraries/microsoft-agents-storage-blob/pyproject.toml @@ -6,6 +6,7 @@ build-backend = "setuptools.build_meta" name = "microsoft-agents-storage-blob" dynamic = ["version", "dependencies"] description = "A blob storage library for Microsoft Agents" +readme = {file = "readme.md", content-type = "text/markdown"} authors = [{name = "Microsoft Corporation"}] license = "MIT" license-files = ["LICENSE"] diff --git a/libraries/microsoft-agents-storage-blob/readme.md b/libraries/microsoft-agents-storage-blob/readme.md new file mode 100644 index 00000000..4e9e1ceb --- /dev/null +++ b/libraries/microsoft-agents-storage-blob/readme.md @@ -0,0 +1,115 @@ +# Microsoft Agents Storage - Blob + +[![PyPI version](https://img.shields.io/pypi/v/microsoft-agents-storage-blob)](https://pypi.org/project/microsoft-agents-storage-blob/) + +Azure Blob Storage integration for Microsoft 365 Agents SDK. This library provides persistent storage for conversation state, user data, and custom agent information using Azure Blob Storage. + +This library implements the storage interface for the Microsoft 365 Agents SDK using Azure Blob Storage as the backend. It enables your agents to persist conversation state, user preferences, and custom data across sessions. Perfect for production deployments where you need reliable, scalable cloud storage. + +# What is this? +This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehensive framework for building enterprise-grade conversational AI agents. The SDK enables developers to create intelligent agents that work across multiple platforms including Microsoft Teams, M365 Copilot, Copilot Studio, and web chat, with support for third-party integrations like Slack, Facebook Messenger, and Twilio. + +## Packages Overview + +We offer the following PyPI packages to create conversational experiences based on Agents: + +| Package Name | PyPI Version | Description | +|--------------|-------------|-------------| +| `microsoft-agents-activity` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-activity)](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. | +| `microsoft-agents-hosting-core` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-core)](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. | +| `microsoft-agents-hosting-aiohttp` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-aiohttp)](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. | +| `microsoft-agents-hosting-teams` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-teams)](https://pypi.org/project/microsoft-agents-hosting-teams/) | Provides classes to host an Agent for Teams. | +| `microsoft-agents-storage-blob` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-blob)](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. | +| `microsoft-agents-storage-cosmos` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-cosmos)](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. | +| `microsoft-agents-authentication-msal` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-authentication-msal)](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. | + +Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio: + +| Package Name | PyPI Version | Description | +|--------------|-------------|-------------| +| `microsoft-agents-copilotstudio-client` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-copilotstudio-client)](https://pypi.org/project/microsoft-agents-copilotstudio-client/) | Direct to Engine client to interact with Agents created in CopilotStudio | + +## Installation + +```bash +pip install microsoft-agents-storage-blob +``` + +**Benefits:** +- ✅ No secrets in code +- ✅ Managed Identity support +- ✅ Automatic token renewal +- ✅ Fine-grained access control via Azure RBAC + +### Configuration Parameters + +| Parameter | Type | Required | Description | +|-----------|------|----------|-------------| +| `container_name` | `str` | Yes | Name of the blob container to use | +| `connection_string` | `str` | No* | Storage account connection string | +| `url` | `str` | No* | Blob service URL (e.g., `https://account.blob.core.windows.net`) | +| `credential` | `TokenCredential` | No** | Azure credential for authentication | + +*Either `connection_string` OR (`url` + `credential`) must be provided +**Required when using `url` + + +### Azure Managed Identity + +When running in Azure (App Service, Functions, Container Apps), use Managed Identity: + +```python +from azure.identity import ManagedIdentityCredential + +config = BlobStorageConfig( + container_name="agent-storage", + url="https://myaccount.blob.core.windows.net", + credential=ManagedIdentityCredential() +) +``` + +**Azure RBAC Roles Required:** +- `Storage Blob Data Contributor` - For read/write access +- `Storage Blob Data Reader` - For read-only access + +**Benefits of switching to BlobStorage:** +- ✅ Data persists across restarts +- ✅ Scalable to millions of items +- ✅ Multi-instance support (load balancing) +- ✅ Automatic backups and geo-replication +- ✅ Built-in monitoring and diagnostics + +## Best Practices + +1. **Use Token Authentication in Production** - Avoid storing connection strings; use Managed Identity or DefaultAzureCredential +2. **Initialize Once** - Call `storage.initialize()` during app startup, not on every request +3. **Implement Retry Logic** - Handle transient failures with exponential backoff +4. **Monitor Performance** - Use Azure Monitor to track storage operations +5. **Set Lifecycle Policies** - Configure automatic cleanup of old data in Azure Portal +6. **Use Consistent Naming** - Establish key naming conventions (e.g., `user:{id}`, `conversation:{id}`) +7. **Batch Operations** - Read/write multiple items together when possible + +## Key Classes Reference + +- **`BlobStorage`** - Main storage implementation using Azure Blob Storage +- **`BlobStorageConfig`** - Configuration settings for connection and authentication +- **`StoreItem`** - Base class for data models (inherit to create custom types) + +# Quick Links + +- 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents) +- 📖 [Complete Documentation](https://aka.ms/agents) +- 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python) +- 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues) + +# Sample Applications + +|Name|Description|README| +|----|----|----| +|Quickstart|Simplest agent|[Quickstart](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/README.md)| +|Auto Sign In|Simple OAuth agent using Graph and GitHub|[auto-signin](https://github.com/microsoft/Agents/blob/main/samples/python/auto-signin/README.md)| +|OBO Authorization|OBO flow to access a Copilot Studio Agent|[obo-authorization](https://github.com/microsoft/Agents/blob/main/samples/python/obo-authorization/README.md)| +|Semantic Kernel Integration|A weather agent built with Semantic Kernel|[semantic-kernel-multiturn](https://github.com/microsoft/Agents/blob/main/samples/python/semantic-kernel-multiturn/README.md)| +|Streaming Agent|Streams OpenAI responses|[azure-ai-streaming](https://github.com/microsoft/Agents/blob/main/samples/python/azureai-streaming/README.md)| +|Copilot Studio Client|Console app to consume a Copilot Studio Agent|[copilotstudio-client](https://github.com/microsoft/Agents/blob/main/samples/python/copilotstudio-client/README.md)| +|Cards Agent|Agent that uses rich cards to enhance conversation design |[cards](https://github.com/microsoft/Agents/blob/main/samples/python/cards/README.md)| \ No newline at end of file diff --git a/libraries/microsoft-agents-storage-cosmos/pyproject.toml b/libraries/microsoft-agents-storage-cosmos/pyproject.toml index 5e743e18..a2318f8a 100644 --- a/libraries/microsoft-agents-storage-cosmos/pyproject.toml +++ b/libraries/microsoft-agents-storage-cosmos/pyproject.toml @@ -6,6 +6,7 @@ build-backend = "setuptools.build_meta" name = "microsoft-agents-storage-cosmos" dynamic = ["version", "dependencies"] description = "A Cosmos DB storage library for Microsoft Agents" +readme = {file = "readme.md", content-type = "text/markdown"} authors = [{name = "Microsoft Corporation"}] license = "MIT" license-files = ["LICENSE"] diff --git a/libraries/microsoft-agents-storage-cosmos/readme.md b/libraries/microsoft-agents-storage-cosmos/readme.md new file mode 100644 index 00000000..847761fc --- /dev/null +++ b/libraries/microsoft-agents-storage-cosmos/readme.md @@ -0,0 +1,91 @@ +# Microsoft Agents Storage - Cosmos DB + +[![PyPI version](https://img.shields.io/pypi/v/microsoft-agents-storage-cosmos)](https://pypi.org/project/microsoft-agents-storage-cosmos/) + +Azure Cosmos DB storage integration for Microsoft 365 Agents SDK. This library provides enterprise-grade persistent storage for conversation state, user data, and custom agent information using Azure Cosmos DB's globally distributed, multi-model database service. + +This library implements the storage interface for the Microsoft 365 Agents SDK using Azure Cosmos DB as the backend. It provides automatic partitioning, global distribution, and low-latency access to your agent data. Perfect for production deployments requiring high availability, scalability, and multi-region support. + +# What is this? +This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehensive framework for building enterprise-grade conversational AI agents. The SDK enables developers to create intelligent agents that work across multiple platforms including Microsoft Teams, M365 Copilot, Copilot Studio, and web chat, with support for third-party integrations like Slack, Facebook Messenger, and Twilio. + +## Packages Overview + +We offer the following PyPI packages to create conversational experiences based on Agents: + +| Package Name | PyPI Version | Description | +|--------------|-------------|-------------| +| `microsoft-agents-activity` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-activity)](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. | +| `microsoft-agents-hosting-core` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-core)](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. | +| `microsoft-agents-hosting-aiohttp` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-aiohttp)](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. | +| `microsoft-agents-hosting-teams` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-teams)](https://pypi.org/project/microsoft-agents-hosting-teams/) | Provides classes to host an Agent for Teams. | +| `microsoft-agents-storage-blob` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-blob)](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. | +| `microsoft-agents-storage-cosmos` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-cosmos)](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. | +| `microsoft-agents-authentication-msal` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-authentication-msal)](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. | + +Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio: + +| Package Name | PyPI Version | Description | +|--------------|-------------|-------------| +| `microsoft-agents-copilotstudio-client` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-copilotstudio-client)](https://pypi.org/project/microsoft-agents-copilotstudio-client/) | Direct to Engine client to interact with Agents created in CopilotStudio | + +**Why Cosmos DB?** +- 🌍 Global distribution with multi-region writes +- ⚡ Single-digit millisecond latency +- 📈 Automatic and instant scalability +- 🔄 Multiple consistency models +- 💪 99.999% availability SLA + +## Installation + +```bash +pip install microsoft-agents-storage-cosmos +``` + + +## Environment Setup + +### Local Development with Cosmos DB Emulator + +Install and run the Azure Cosmos DB Emulator for local testing: + +**Download:** [Azure Cosmos DB Emulator](https://docs.microsoft.com/azure/cosmos-db/local-emulator) + + +## Best Practices + +1. **Use Managed Identity in Production** - Avoid storing auth keys in code or environment variables +2. **Initialize Once** - Call `storage.initialize()` during app startup, not per request +3. **Batch Operations** - Read/write multiple items together when possible +4. **Monitor RU Consumption** - Use Azure Monitor to track Request Units usage +5. **Set Appropriate Throughput** - Start with 400 RU/s, scale up based on metrics +6. **Use Session Consistency** - Default consistency level for most scenarios +7. **Implement Retry Logic** - Handle transient failures with exponential backoff +8. **Partition Wisely** - Current implementation uses `/id` partitioning (automatic) +9. **Enable Diagnostics** - Configure Azure diagnostic logs for troubleshooting +10. **Test with Emulator** - Use local emulator for development and testing + +## Key Classes Reference + +- **`CosmosDBStorage`** - Main storage implementation using Azure Cosmos DB +- **`CosmosDBStorageConfig`** - Configuration settings for connection and behavior +- **`StoreItem`** - Base class for data models (inherit to create custom types) + +# Quick Links + +- 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents) +- 📖 [Complete Documentation](https://aka.ms/agents) +- 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python) +- 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues) + +# Sample Applications + +|Name|Description|README| +|----|----|----| +|Quickstart|Simplest agent|[Quickstart](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/README.md)| +|Auto Sign In|Simple OAuth agent using Graph and GitHub|[auto-signin](https://github.com/microsoft/Agents/blob/main/samples/python/auto-signin/README.md)| +|OBO Authorization|OBO flow to access a Copilot Studio Agent|[obo-authorization](https://github.com/microsoft/Agents/blob/main/samples/python/obo-authorization/README.md)| +|Semantic Kernel Integration|A weather agent built with Semantic Kernel|[semantic-kernel-multiturn](https://github.com/microsoft/Agents/blob/main/samples/python/semantic-kernel-multiturn/README.md)| +|Streaming Agent|Streams OpenAI responses|[azure-ai-streaming](https://github.com/microsoft/Agents/blob/main/samples/python/azureai-streaming/README.md)| +|Copilot Studio Client|Console app to consume a Copilot Studio Agent|[copilotstudio-client](https://github.com/microsoft/Agents/blob/main/samples/python/copilotstudio-client/README.md)| +|Cards Agent|Agent that uses rich cards to enhance conversation design |[cards](https://github.com/microsoft/Agents/blob/main/samples/python/cards/README.md)| \ No newline at end of file