Skip to content

Commit 6edbf26

Browse files
authored
General cleanup and refactoring (#19)
1 parent 7aa48a8 commit 6edbf26

27 files changed

+390
-241
lines changed

azure/durable_functions/decorators/durable_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed under the MIT License.
33

44
from azure.durable_functions.models.RetryOptions import RetryOptions
5-
from .metadata import OrchestrationTrigger, ActivityTrigger, EntityTrigger,\
5+
from .metadata import OrchestrationTrigger, ActivityTrigger, EntityTrigger, \
66
DurableClient
77
from typing import Callable, Optional
88
from azure.durable_functions.entity import Entity

azure/durable_functions/openai_agents/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
"""OpenAI Agents integration for Azure Durable Functions.
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
"""OpenAI Agents integration for Durable Functions.
24
35
This module provides decorators and utilities to integrate OpenAI Agents
4-
with Azure Durable Functions orchestration patterns.
6+
with Durable Functions orchestration patterns.
57
"""
68

79
from .context import DurableAIAgentContext

azure/durable_functions/openai_agents/context.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
13
import json
24
from typing import Any, Callable, Optional, TYPE_CHECKING, Union
35

azure/durable_functions/openai_agents/event_loop.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
13
import asyncio
24

35

azure/durable_functions/openai_agents/exceptions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
13
from azure.durable_functions.models.Task import TaskBase
24

35

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
"""Handoff conversion utilities for Azure Durable Functions OpenAI agent operations."""
4+
5+
from typing import Any
6+
7+
from agents import Handoff
8+
from pydantic import BaseModel
9+
10+
11+
class DurableHandoff(BaseModel):
12+
"""Serializable representation of a Handoff.
13+
14+
Contains only the data needed by the model execution to
15+
determine what to handoff to, not the actual handoff invocation.
16+
"""
17+
18+
tool_name: str
19+
tool_description: str
20+
input_json_schema: dict[str, Any]
21+
agent_name: str
22+
strict_json_schema: bool = True
23+
24+
@classmethod
25+
def from_handoff(cls, handoff: Handoff) -> "DurableHandoff":
26+
"""Create a DurableHandoff from an OpenAI agent Handoff.
27+
28+
This method converts OpenAI agent Handoff instances into serializable
29+
DurableHandoff objects for use within Azure Durable Functions.
30+
31+
Parameters
32+
----------
33+
handoff : Handoff
34+
The OpenAI agent Handoff to convert
35+
36+
Returns
37+
-------
38+
DurableHandoff
39+
A serializable handoff representation
40+
"""
41+
return cls(
42+
tool_name=handoff.tool_name,
43+
tool_description=handoff.tool_description,
44+
input_json_schema=handoff.input_json_schema,
45+
agent_name=handoff.agent_name,
46+
strict_json_schema=handoff.strict_json_schema,
47+
)
48+
49+
def to_handoff(self) -> Handoff[Any, Any]:
50+
"""Create an OpenAI agent Handoff instance from this DurableHandoff.
51+
52+
This method converts the serializable DurableHandoff back into an
53+
OpenAI agent Handoff instance for execution.
54+
55+
Returns
56+
-------
57+
Handoff
58+
OpenAI agent Handoff instance
59+
"""
60+
return Handoff(
61+
tool_name=self.tool_name,
62+
tool_description=self.tool_description,
63+
input_json_schema=self.input_json_schema,
64+
agent_name=self.agent_name,
65+
strict_json_schema=self.strict_json_schema,
66+
on_invoke_handoff=lambda ctx, input: None,
67+
)

0 commit comments

Comments
 (0)