Skip to content

Commit 14c818b

Browse files
committed
Linting
1 parent 974d132 commit 14c818b

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

temporalio/contrib/openai_agents/_model_parameters.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from dataclasses import dataclass
44
from datetime import timedelta
5-
from typing import Optional, Union, Callable, Any
5+
from typing import Any, Callable, Optional, Union
66

77
from agents import Agent, TResponseInputItem
88

@@ -43,7 +43,14 @@ class ModelActivityParameters:
4343
versioning_intent: Optional[VersioningIntent] = None
4444
"""Versioning intent for the activity."""
4545

46-
summary_override: Optional[Union[str, Callable[[Agent[Any], Optional[str], Union[str, list[TResponseInputItem]]], str]]] = None
46+
summary_override: Optional[
47+
Union[
48+
str,
49+
Callable[
50+
[Agent[Any], Optional[str], Union[str, list[TResponseInputItem]]], str
51+
],
52+
]
53+
] = None
4754
"""Summary for the activity execution."""
4855

4956
priority: Priority = Priority.default

temporalio/contrib/openai_agents/_openai_runner.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import json
22
import typing
3-
from dataclasses import replace
4-
from typing import Any, Union
3+
from typing import Any, Optional, Union
54

65
from agents import (
76
Agent,
7+
Handoff,
88
RunConfig,
9+
RunContextWrapper,
910
RunResult,
1011
RunResultStreaming,
1112
SQLiteSession,
1213
TContext,
1314
Tool,
14-
TResponseInputItem, Handoff, RunContextWrapper,
15+
TResponseInputItem,
1516
)
1617
from agents.run import DEFAULT_AGENT_RUNNER, DEFAULT_MAX_TURNS, AgentRunner
1718
from pydantic_core import to_json
@@ -77,7 +78,7 @@ async def run(
7778
if run_config is None:
7879
run_config = RunConfig()
7980

80-
def model_name(agent: Agent[Any]) -> str:
81+
def model_name(agent: Agent[Any]) -> Optional[str]:
8182
name = run_config.model or agent.model
8283
if name is not None and not isinstance(name, str):
8384
print("Name: ", name, " Agent: ", agent)
@@ -106,10 +107,14 @@ def convert_agent(agent: Agent[Any]) -> None:
106107
convert_agent(handoff)
107108
elif isinstance(handoff, Handoff):
108109
original_invoke = handoff.on_invoke_handoff
109-
async def on_invoke(context: RunContextWrapper[Any], args: str) -> Agent[Any]:
110+
111+
async def on_invoke(
112+
context: RunContextWrapper[Any], args: str
113+
) -> Agent[Any]:
110114
handoff_agent = await original_invoke(context, args)
111115
convert_agent(handoff_agent)
112116
return handoff_agent
117+
113118
handoff.on_invoke_handoff = on_invoke
114119

115120
convert_agent(starting_agent)

temporalio/contrib/openai_agents/_temporal_model_stub.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing import Any, AsyncIterator, Union, cast
1212

1313
from agents import (
14+
Agent,
1415
AgentOutputSchema,
1516
AgentOutputSchemaBase,
1617
CodeInterpreterTool,
@@ -25,7 +26,7 @@
2526
ModelTracing,
2627
Tool,
2728
TResponseInputItem,
28-
WebSearchTool, Agent,
29+
WebSearchTool,
2930
)
3031
from agents.items import TResponseStreamEvent
3132
from openai.types.responses.response_prompt_param import ResponsePromptParam
@@ -70,6 +71,7 @@ async def get_response(
7071
prompt: Optional[ResponsePromptParam],
7172
) -> ModelResponse:
7273
print("Model stub invocation:", self.model_name)
74+
7375
def make_tool_info(tool: Tool) -> ToolInput:
7476
if isinstance(
7577
tool,
@@ -138,8 +140,15 @@ def make_tool_info(tool: Tool) -> ToolInput:
138140
)
139141

140142
if self.model_params.summary_override:
141-
summary = self.model_params.summary_override if isinstance(self.model_params.summary_override, str) else (
142-
self.model_params.summary_override(self.agent, system_instructions, input))
143+
summary = (
144+
self.model_params.summary_override
145+
if isinstance(self.model_params.summary_override, str)
146+
else (
147+
self.model_params.summary_override(
148+
self.agent, system_instructions, input
149+
)
150+
)
151+
)
143152
else:
144153
summary = self.agent.name
145154

tests/contrib/openai_agents/test_openai.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,6 @@ class CustomerServiceModel(StaticTestModel):
916916
]
917917

918918

919-
920919
@workflow.defn
921920
class CustomerServiceWorkflow:
922921
def __init__(self, input_items: list[TResponseInputItem] = []):
@@ -995,9 +994,7 @@ async def test_customer_service_workflow(client: Client, use_local_model: bool):
995994
model_params=ModelActivityParameters(
996995
start_to_close_timeout=timedelta(seconds=30)
997996
),
998-
model_provider= provider
999-
if use_local_model
1000-
else None,
997+
model_provider=provider if use_local_model else None,
1001998
)
1002999
]
10031000
client = Client(**new_config)
@@ -2047,7 +2044,7 @@ async def test_hosted_mcp_tool(client: Client, use_local_model):
20472044

20482045

20492046
class AssertDifferentModelProvider(ModelProvider):
2050-
model_names = set()
2047+
model_names: set[Optional[str]] = set()
20512048

20522049
def __init__(self, model: Model):
20532050
self._model = model
@@ -2065,6 +2062,7 @@ class MultipleModelsModel(StaticTestModel):
20652062
),
20662063
]
20672064

2065+
20682066
@workflow.defn
20692067
class MultipleModelWorkflow:
20702068
@workflow.run
@@ -2078,7 +2076,7 @@ async def run(self):
20782076
name="Lazy Assistant",
20792077
model="gpt-4o-mini",
20802078
instructions="You delegate all your work to another agent.",
2081-
handoffs=[underling]
2079+
handoffs=[underling],
20822080
)
20832081
result = await Runner.run(
20842082
starting_agent=starting_agent,
@@ -2095,7 +2093,7 @@ async def test_multiple_models(client: Client):
20952093
model_params=ModelActivityParameters(
20962094
start_to_close_timeout=timedelta(seconds=120)
20972095
),
2098-
model_provider=provider
2096+
model_provider=provider,
20992097
)
21002098
]
21012099
client = Client(**new_config)

0 commit comments

Comments
 (0)