Microsoft Agents Activity Protocol Library

0.8.0 · active · verified Tue Apr 14

The `microsoft-agents-activity` library is a fundamental component of the Microsoft 365 Agents SDK for Python. It provides the core types and schemas, implementing the Activity Protocol Specification, which standardizes communication between AI agents, users, and various channels such as Microsoft Teams, M365 Copilot, Copilot Studio, and web chat. This protocol handles diverse interaction types including messages, typing indicators, conversation updates, events, invokes, and end-of-conversation signals. The SDK aims to facilitate the creation of robust, multichannel, and trusted agents for enterprise systems, allowing developers to integrate agents regardless of their underlying provider or technology stack. The current version of this specific library is 0.8.0.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create and manipulate `Activity` objects, the core data structure handled by the `microsoft-agents-activity` library. It simulates an incoming message and then shows how to generate a reply activity using built-in methods, showcasing the protocol's core functionality.

import asyncio
from microsoft_agents.activity import Activity, ActivityTypes
import os

async def main():
    # Simulate an incoming message activity (e.g., from a user in Teams)
    incoming_activity = Activity.from_object({
        "type": ActivityTypes.Message,
        "id": "msg123",
        "timestamp": "2026-04-14T18:00:00Z",
        "channelId": os.environ.get('TEST_CHANNEL_ID', 'test_channel'),
        "from": {"id": "user123", "name": "Test User"},
        "conversation": {"id": "conv123", "conversationType": "personal"},
        "recipient": {"id": "bot456", "name": "Test Bot"},
        "text": "Hello bot, how are you?",
        "locale": "en-US"
    })

    print(f"Incoming Activity Text: {incoming_activity.text}")
    print(f"Incoming Activity Sender: {incoming_activity.from_property.name}")

    # Create a reply activity using the incoming activity's context
    reply_activity = incoming_activity.create_reply("Hello there, Test User! I'm doing well, thanks for asking.")

    print(f"\nReply Activity Type: {reply_activity.type}")
    print(f"Reply Activity Text: {reply_activity.text}")
    print(f"Reply Activity Recipient: {reply_activity.recipient.name}")
    print(f"Reply Activity To ID: {reply_activity.reply_to_id}")

if __name__ == "__main__":
    # Example of setting an environment variable for demonstration
    os.environ['TEST_CHANNEL_ID'] = 'mock_channel_001'
    asyncio.run(main())

view raw JSON →