-
Notifications
You must be signed in to change notification settings - Fork 141
💥 Replayer configuration from plugins #1011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
1741a6e
3c92c40
76cacf6
f61b400
1007d02
673afbe
9812c95
2ae78b1
9c993ee
beec4bd
91c229f
cd2d12f
7671abe
8e2c7ad
602fd42
2854546
afa7768
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| """Initialize Temporal OpenAI Agents overrides.""" | ||
|
|
||
| from contextlib import contextmanager | ||
| from contextlib import asynccontextmanager, contextmanager | ||
| from datetime import timedelta | ||
| from typing import AsyncIterator, Callable, Optional, Union | ||
|
|
||
|
|
@@ -24,7 +24,7 @@ | |
|
|
||
| import temporalio.client | ||
| import temporalio.worker | ||
| from temporalio.client import ClientConfig | ||
| from temporalio.client import ClientConfig, Plugin | ||
| from temporalio.contrib.openai_agents._invoke_model_activity import ModelActivity | ||
| from temporalio.contrib.openai_agents._model_parameters import ModelActivityParameters | ||
| from temporalio.contrib.openai_agents._openai_runner import TemporalOpenAIRunner | ||
|
|
@@ -41,7 +41,13 @@ | |
| from temporalio.converter import ( | ||
| DataConverter, | ||
| ) | ||
| from temporalio.worker import Worker, WorkerConfig | ||
| from temporalio.worker import ( | ||
| Replayer, | ||
| ReplayerConfig, | ||
| Worker, | ||
| WorkerConfig, | ||
| WorkflowReplayResult, | ||
| ) | ||
|
|
||
|
|
||
| @contextmanager | ||
|
|
@@ -231,6 +237,26 @@ def __init__( | |
| self._model_params = model_params | ||
| self._model_provider = model_provider | ||
|
|
||
| def init_client_plugin( | ||
| self, next: temporalio.client.Plugin | ||
| ) -> temporalio.client.Plugin: | ||
| """Set the next client plugin""" | ||
| self.next_client_plugin = next | ||
| return self | ||
|
|
||
| async def connect_service_client( | ||
| self, config: temporalio.service.ConnectConfig | ||
| ) -> temporalio.service.ServiceClient: | ||
| """No modifications to service client""" | ||
| return await self.next_client_plugin.connect_service_client(config) | ||
|
|
||
| def init_worker_plugin( | ||
| self, next: temporalio.worker.Plugin | ||
| ) -> temporalio.worker.Plugin: | ||
| """Set the next worker plugin""" | ||
| self.next_worker_plugin = next | ||
| return self | ||
|
|
||
| def configure_client(self, config: ClientConfig) -> ClientConfig: | ||
| """Configure the Temporal client for OpenAI agents integration. | ||
|
|
||
|
|
@@ -246,7 +272,7 @@ def configure_client(self, config: ClientConfig) -> ClientConfig: | |
| config["data_converter"] = DataConverter( | ||
| payload_converter_class=_OpenAIPayloadConverter | ||
| ) | ||
| return super().configure_client(config) | ||
| return self.next_client_plugin.configure_client(config) | ||
|
|
||
| def configure_worker(self, config: WorkerConfig) -> WorkerConfig: | ||
| """Configure the Temporal worker for OpenAI agents integration. | ||
|
|
@@ -268,7 +294,7 @@ def configure_worker(self, config: WorkerConfig) -> WorkerConfig: | |
| config["activities"] = list(config.get("activities") or []) + [ | ||
| ModelActivity(self._model_provider).invoke_model_activity | ||
| ] | ||
| return super().configure_worker(config) | ||
| return self.next_worker_plugin.configure_worker(config) | ||
|
|
||
| async def run_worker(self, worker: Worker) -> None: | ||
| """Run the worker with OpenAI agents temporal overrides. | ||
|
|
@@ -281,4 +307,27 @@ async def run_worker(self, worker: Worker) -> None: | |
| worker: The worker instance to run. | ||
| """ | ||
| with set_open_ai_agent_temporal_overrides(self._model_params): | ||
| await super().run_worker(worker) | ||
| await self.next_worker_plugin.run_worker(worker) | ||
|
|
||
| def configure_replayer(self, config: ReplayerConfig) -> ReplayerConfig: | ||
| """Configure the replayer for OpenAI Agents.""" | ||
| config["interceptors"] = list(config.get("interceptors") or []) + [ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a very surprising footgun and introduces coupling, and requires that users understand a concept (Replayer) that few are familiar with. It feels like a very large chance that users will mess this up.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is why we chose to require that plugin authors configure replayers and therefore become familiar with them. Regular users don't need to become familiar with replayers, but plugin authors do to ensure their plugin works right in replayer scenarios and not just client and worker scenarios. |
||
| OpenAIAgentsTracingInterceptor() | ||
| ] | ||
| config["data_converter"] = DataConverter( | ||
| payload_converter_class=_OpenAIPayloadConverter | ||
| ) | ||
| return config | ||
|
|
||
| @asynccontextmanager | ||
| async def workflow_replay( | ||
| self, | ||
| replayer: Replayer, | ||
| histories: AsyncIterator[temporalio.client.WorkflowHistory], | ||
| ) -> AsyncIterator[AsyncIterator[WorkflowReplayResult]]: | ||
| """Set the OpenAI Overrides during replay""" | ||
| with set_open_ai_agent_temporal_overrides(self._model_params): | ||
| async with self.next_worker_plugin.workflow_replay( | ||
| replayer, histories | ||
| ) as results: | ||
| yield results | ||
Uh oh!
There was an error while loading. Please reload this page.