Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@
#: notification: The typed notification activity with parsed entities.
#:
#: Example:
#: ```python
#: async def handle_email(
#: context: TurnContext,
#: state: TurnState,
#: notification: AgentNotificationActivity
#: ) -> None:
#: email = notification.email
#: if email:
#: print(f"Processing email: {email.id}")
#: ```
#:
#: .. code-block:: python
#:
#: async def handle_email(
#: context: TurnContext,
#: state: TurnState,
#: notification: AgentNotificationActivity,
#: ) -> None:
#: email = notification.email
#: if email:
#: print(f"Processing email: {email.id}")
AgentHandler = Callable[[TContext, TState, AgentNotificationActivity], Awaitable[None]]


Expand All @@ -57,19 +58,19 @@ class AgentNotification:
defaults to all values in the AgentLifecycleEvent enum.

Example:
```python
from microsoft_agents.hosting import Application
from microsoft_agents_a365.notifications import AgentNotification

app = Application()
notifications = AgentNotification(app)

@notifications.on_email()
async def handle_email(context, state, notification):
email = notification.email
if email:
await context.send_activity(f"Received email: {email.id}")
```
.. code-block:: python

from microsoft_agents.hosting import Application
from microsoft_agents_a365.notifications import AgentNotification

app = Application()
notifications = AgentNotification(app)

@notifications.on_email()
async def handle_email(context, state, notification):
email = notification.email
if email:
await context.send_activity(f"Received email: {email.id}")
"""

def __init__(
Expand Down Expand Up @@ -126,15 +127,15 @@ def on_agent_notification(
A decorator function that registers the handler with the application.

Example:
```python
from microsoft_agents.activity import ChannelId
.. code-block:: python

@notifications.on_agent_notification(
ChannelId(channel="agents", sub_channel="email")
)
async def handle_custom_channel(context, state, notification):
print(f"Received notification on {notification.channel}/{notification.sub_channel}")
```
from microsoft_agents.activity import ChannelId

@notifications.on_agent_notification(
ChannelId(channel="agents", sub_channel="email")
)
async def handle_custom_channel(context, state, notification):
print(f"Received notification on {notification.channel}/{notification.sub_channel}")
"""
registered_channel = channel_id.channel.lower()
registered_subchannel = (channel_id.sub_channel or "*").lower()
Expand Down Expand Up @@ -184,11 +185,11 @@ def on_agent_lifecycle_notification(
A decorator function that registers the handler with the application.

Example:
```python
@notifications.on_agent_lifecycle_notification("agenticuseridentitycreated")
async def handle_user_created(context, state, notification):
print("New user created")
```
.. code-block:: python

@notifications.on_agent_lifecycle_notification("agenticuseridentitycreated")
async def handle_user_created(context, state, notification):
print("New user created")
"""

def route_selector(context: TurnContext) -> bool:
Expand Down Expand Up @@ -234,18 +235,17 @@ def on_email(
A decorator function that registers the handler with the application.

Example:
```python
@notifications.on_email()
async def handle_email(context, state, notification):
email = notification.email
if email:
print(f"Received email: {email.id}")
# Send a response
response = EmailResponse.create_email_response_activity(
"<p>Thank you for your email.</p>"
)
await context.send_activity(response)
```
.. code-block:: python

@notifications.on_email()
async def handle_email(context, state, notification):
email = notification.email
if email:
print(f"Received email: {email.id}")
response = EmailResponse.create_email_response_activity(
"<p>Thank you for your email.</p>"
)
await context.send_activity(response)
"""
return self.on_agent_notification(
ChannelId(channel="agents", sub_channel=AgentSubChannel.EMAIL), **kwargs
Expand All @@ -266,13 +266,13 @@ def on_word(
A decorator function that registers the handler with the application.

Example:
```python
@notifications.on_word()
async def handle_word_comment(context, state, notification):
comment = notification.wpx_comment
if comment:
print(f"Received Word comment: {comment.comment_id}")
```
.. code-block:: python

@notifications.on_word()
async def handle_word_comment(context, state, notification):
comment = notification.wpx_comment
if comment:
print(f"Received Word comment: {comment.comment_id}")
"""
return self.on_agent_notification(
ChannelId(channel="agents", sub_channel=AgentSubChannel.WORD), **kwargs
Expand All @@ -293,13 +293,13 @@ def on_excel(
A decorator function that registers the handler with the application.

Example:
```python
@notifications.on_excel()
async def handle_excel_comment(context, state, notification):
comment = notification.wpx_comment
if comment:
print(f"Received Excel comment: {comment.comment_id}")
```
.. code-block:: python

@notifications.on_excel()
async def handle_excel_comment(context, state, notification):
comment = notification.wpx_comment
if comment:
print(f"Received Excel comment: {comment.comment_id}")
"""
return self.on_agent_notification(
ChannelId(channel="agents", sub_channel=AgentSubChannel.EXCEL), **kwargs
Expand All @@ -320,13 +320,13 @@ def on_powerpoint(
A decorator function that registers the handler with the application.

Example:
```python
@notifications.on_powerpoint()
async def handle_powerpoint_comment(context, state, notification):
comment = notification.wpx_comment
if comment:
print(f"Received PowerPoint comment: {comment.comment_id}")
```
.. code-block:: python

@notifications.on_powerpoint()
async def handle_powerpoint_comment(context, state, notification):
comment = notification.wpx_comment
if comment:
print(f"Received PowerPoint comment: {comment.comment_id}")
"""
return self.on_agent_notification(
ChannelId(channel="agents", sub_channel=AgentSubChannel.POWERPOINT), **kwargs
Expand All @@ -347,11 +347,11 @@ def on_lifecycle(
A decorator function that registers the handler with the application.

Example:
```python
@notifications.on_lifecycle()
async def handle_any_lifecycle_event(context, state, notification):
print(f"Lifecycle event type: {notification.notification_type}")
```
.. code-block:: python

@notifications.on_lifecycle()
async def handle_any_lifecycle_event(context, state, notification):
print(f"Lifecycle event type: {notification.notification_type}")
"""
return self.on_lifecycle_notification("*", **kwargs)

Expand All @@ -370,11 +370,11 @@ def on_user_created(
A decorator function that registers the handler with the application.

Example:
```python
@notifications.on_user_created()
async def handle_user_created(context, state, notification):
print("New agentic user identity created")
```
.. code-block:: python

@notifications.on_user_created()
async def handle_user_created(context, state, notification):
print("New agentic user identity created")
"""
return self.on_lifecycle_notification(AgentLifecycleEvent.USERCREATED, **kwargs)

Expand All @@ -393,11 +393,11 @@ def on_user_workload_onboarding(
A decorator function that registers the handler with the application.

Example:
```python
@notifications.on_user_workload_onboarding()
async def handle_onboarding_update(context, state, notification):
print("User workload onboarding status updated")
```
.. code-block:: python

@notifications.on_user_workload_onboarding()
async def handle_onboarding_update(context, state, notification):
print("User workload onboarding status updated")
"""
return self.on_lifecycle_notification(
AgentLifecycleEvent.USERWORKLOADONBOARDINGUPDATED, **kwargs
Expand All @@ -418,11 +418,11 @@ def on_user_deleted(
A decorator function that registers the handler with the application.

Example:
```python
@notifications.on_user_deleted()
async def handle_user_deleted(context, state, notification):
print("Agentic user identity deleted")
```
.. code-block:: python

@notifications.on_user_deleted()
async def handle_user_deleted(context, state, notification):
print("Agentic user identity deleted")
"""
return self.on_lifecycle_notification(AgentLifecycleEvent.USERDELETED, **kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ class AgentNotificationActivity:
activity: The underlying Activity object.

Example:
```python
async def email_handler(context: TurnContext, state: TurnState, notification: AgentNotificationActivity):
email = notification.email
if email:
print(f"Received email: {email.id}")
print(f"Body: {email.html_body}")
```
.. code-block:: python

async def email_handler(
context: TurnContext,
state: TurnState,
notification: AgentNotificationActivity,
) -> None:
email = notification.email
if email:
print(f"Received email: {email.id}")
print(f"Body: {email.html_body}")
"""

def __init__(self, activity: Activity):
Expand Down Expand Up @@ -158,17 +162,17 @@ def as_model(self, model: Type[TModel]) -> Optional[TModel]:
An instance of the specified model type if validation succeeds, otherwise None.

Example:
```python
from pydantic import BaseModel
.. code-block:: python

class CustomNotification(BaseModel):
custom_field: str
from pydantic import BaseModel

notification = AgentNotificationActivity(activity)
custom = notification.as_model(CustomNotification)
if custom:
print(custom.custom_field)
```
class CustomNotification(BaseModel):
custom_field: str

notification = AgentNotificationActivity(activity)
custom = notification.as_model(CustomNotification)
if custom:
print(custom.custom_field)
"""
try:
return model.model_validate(self.value or {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ def create_email_response_activity(email_response_html_body: str) -> Activity:
entity attached to its entities list.

Example:
```python
activity = EmailResponse.create_email_response_activity(
"<p>Thank you for your email. I'll get back to you soon.</p>"
)
await context.send_activity(activity)
```
.. code-block:: python

activity = EmailResponse.create_email_response_activity(
"<p>Thank you for your email. I'll get back to you soon.</p>"
)
await context.send_activity(activity)
"""
working_activity = Activity(type="message")
email_response = EmailResponse(html_body=email_response_html_body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@


class OpenAIAgentsTraceInstrumentor(BaseInstrumentor):
"""
Custom Trace Processor for OpenAI Agents SDK using Microsoft Agent 365.
Forwards OpenAI Agents SDK traces and spans to Microsoft Agent 365's tracing scopes.
"""Custom Trace Processor for OpenAI Agents SDK using Microsoft Agent 365.

```
Forwards OpenAI Agents SDK traces and spans to Microsoft Agent 365's tracing scopes.
"""

def __init__(self):
Expand Down