Skip to content
Merged
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
2 changes: 1 addition & 1 deletion azure/durable_functions/decorators/durable_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the MIT License.

from azure.durable_functions.models.RetryOptions import RetryOptions
from .metadata import OrchestrationTrigger, ActivityTrigger, EntityTrigger,\
from .metadata import OrchestrationTrigger, ActivityTrigger, EntityTrigger, \
DurableClient
from typing import Callable, Optional
from azure.durable_functions.entity import Entity
Expand Down
6 changes: 4 additions & 2 deletions azure/durable_functions/openai_agents/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""OpenAI Agents integration for Azure Durable Functions.
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
"""OpenAI Agents integration for Durable Functions.

This module provides decorators and utilities to integrate OpenAI Agents
with Azure Durable Functions orchestration patterns.
with Durable Functions orchestration patterns.
"""

from .context import DurableAIAgentContext
Expand Down
2 changes: 2 additions & 0 deletions azure/durable_functions/openai_agents/context.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import json
from typing import Any, Callable, Optional, TYPE_CHECKING, Union

Expand Down
2 changes: 2 additions & 0 deletions azure/durable_functions/openai_agents/event_loop.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import asyncio


Expand Down
2 changes: 2 additions & 0 deletions azure/durable_functions/openai_agents/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from azure.durable_functions.models.Task import TaskBase


Expand Down
67 changes: 67 additions & 0 deletions azure/durable_functions/openai_agents/handoffs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
"""Handoff conversion utilities for Azure Durable Functions OpenAI agent operations."""

from typing import Any

from agents import Handoff
from pydantic import BaseModel


class DurableHandoff(BaseModel):
"""Serializable representation of a Handoff.

Contains only the data needed by the model execution to
determine what to handoff to, not the actual handoff invocation.
"""

tool_name: str
tool_description: str
input_json_schema: dict[str, Any]
agent_name: str
strict_json_schema: bool = True

@classmethod
def from_handoff(cls, handoff: Handoff) -> "DurableHandoff":
"""Create a DurableHandoff from an OpenAI agent Handoff.

This method converts OpenAI agent Handoff instances into serializable
DurableHandoff objects for use within Azure Durable Functions.

Parameters
----------
handoff : Handoff
The OpenAI agent Handoff to convert

Returns
-------
DurableHandoff
A serializable handoff representation
"""
return cls(
tool_name=handoff.tool_name,
tool_description=handoff.tool_description,
input_json_schema=handoff.input_json_schema,
agent_name=handoff.agent_name,
strict_json_schema=handoff.strict_json_schema,
)

def to_handoff(self) -> Handoff[Any, Any]:
"""Create an OpenAI agent Handoff instance from this DurableHandoff.

This method converts the serializable DurableHandoff back into an
OpenAI agent Handoff instance for execution.

Returns
-------
Handoff
OpenAI agent Handoff instance
"""
return Handoff(
tool_name=self.tool_name,
tool_description=self.tool_description,
input_json_schema=self.input_json_schema,
agent_name=self.agent_name,
strict_json_schema=self.strict_json_schema,
on_invoke_handoff=lambda ctx, input: None,
)
Loading